require File.dirname(__FILE__) + '/../test_helper' class BaseTest < Test::Unit::TestCase context "when connected thru HTTP" do setup do @mambanation = MambaNation::Base.new(MambaNation::HTTPAuth.new("username", "password", :api_endpoint => "api.mambanation.com")) end should "have user method for base authenticated calls to get a user's information" do stub_get("http://username:password@api.mambanation.com/v2/users/4.json", 'user.json') user = @mambanation.user(4) user.mamba_level.should == 1 user.email.should == "tian.jiang01@gmail.com" end should "have facet method for base authenticated calls to get a facet's information" do stub_get("http://username:password@api.mambanation.com/v2/facets/1.json", 'facet.json') facet = @mambanation.facet 1 facet.user_id.should == 1 end should "have user_facets method with given user for base authenticated calls to get a user's facet's information" do stub_get("http://username:password@api.mambanation.com/v2/users/4/facets.json", 'facets.json') facets = @mambanation.user_facets(4) facets.facets.count.should == 1 facets.facebook_id == nil end should "have user_friends method with given user for base authenticated calls to get a user's facet's information" do stub_get("http://username:password@api.mambanation.com/v2/users/4/friends.json", 'friends.json') friends = @mambanation.user_friends(4) friends.count.should == 2 end #media api for user in sdk is not rest # should "have user_media method with given user for base authenticated calls to get a user's media's information" do # stub_get("http://username:password@api.mambanation.com/v2/users/5/medias.json", '') # media # end # user_set_websession no more in sdk # should "be able to update websession for a user" # stub_post("http://username:password@api.mambanation.com/v2/facets/1.json", '') # end should "be able to create a user" do stub_post("http://username:password@api.mambanation.com/v2/users", 'new_user_status.json') response = @mambanation.create_user({"email" => "foofoo@gmail.com", "password" => "foofoo", "password_confirmation" => "foofoo"}) response.status.should == "ok" end should "be able to create a user with a facebook_id" do stub_post("http://username:password@api.mambanation.com/v2/users", 'new_user_status.json') response = @mambanation.create_user({"facebook_id" => "1474761574"}) response.status.should == "ok" end should "have user find by existing facebook_id" do stub_get("http://username:password@api.mambanation.com/v2/users/find_by?facebook_id=1474761574", 'user.json') user = @mambanation.user_by_facebook_id 1474761574 user.mamba_level.should == 1 user.email.should == "tian.jiang01@gmail.com" user.facebook_id.should == 1474761574 end should "have not found user message when no existing facebook_id" do stub_get("http://username:password@api.mambanation.com/v2/users/find_by?facebook_id=12345", 'not_found_user.json') user = @mambanation.user_by_facebook_id 12345 user.message.should == "I can't find this user !" end should "have user find by existing email" do stub_get("http://username:password@api.mambanation.com/v2/users/find_by?email=tian.jiang01@gmail.com", 'user.json') user = @mambanation.user_by_email 'tian.jiang01@gmail.com' user.mamba_level.should == 1 user.email.should == "tian.jiang01@gmail.com" user.facebook_id.should == 1474761574 end should "have not found user message when no existing email" do stub_get("http://username:password@api.mambanation.com/v2/users/find_by?email=zahia@gmail.com", 'not_found_user.json') user = @mambanation.user_by_email 'zahia@gmail.com' user.message.should == "I can't find this user !" end should "have last login" do stub_get("http://username:password@api.mambanation.com/v2/users/4/last_login.json", 'last_login.json') user = @mambanation.user_last_login(4) user.last_login.should == 1234567890 end should "have user chat" do stub_get("http://username:password@api.mambanation.com/v2/users/4/chats.json", 'chats.json') chats = @mambanation.user_chats(4) puts chats.class chats.total_messages.should == 1 chats.total_pages.should == 1 chats.current_page.should == 1 chats.messages.size.should == 2 chats.messages_per_page.should == 50 end should "have user coms" do stub_get("http://username:password@api.mambanation.com/v2/users/4/coms.json", 'coms.json') coms = @mambanation.user_coms(4) coms.count.should == 4 end end end