spec/omnicontacts/importer/yahoo_spec.rb in omnicontacts-0.2.5 vs spec/omnicontacts/importer/yahoo_spec.rb in omnicontacts-0.3.0

- old
+ new

@@ -3,15 +3,27 @@ describe OmniContacts::Importer::Yahoo do describe "fetch_contacts_from_token_and_verifier" do let(:contacts_as_json) { - '{"contacts": - {"start":1, "count":1, - "contact":[{"id":10, "fields":[{"id":819, "type":"email", "value":"john@yahoo.com"}, - {"type":"name", "value": { "givenName":"John", "familyName":"Doe"} }] }] - } }' } + '{ + "contacts": { + "start":1, + "count":1, + "contact":[ + { + "id":10, + "fields":[ + {"id":819, "type":"email", "value":"johnny@yahoo.com"}, + {"id":806,"type":"name","value":{"givenName":"John","middleName":"","familyName":"Smith"},"editedBy":"OWNER","categories":[]}, + {"id":33555343,"type":"guid","value":"7ET6MYV2UQ6VR6CBSNMCLFJIVI"}, + {"id":946,"type":"birthday","value":{"day":"22","month":"2","year":"1952"},"editedBy":"OWNER","categories":[]} + ] + } + ] + } + }' } let(:yahoo) { OmniContacts::Importer::Yahoo.new({}, "consumer_key", "consumer_secret") } it "should request the contacts by specifying all required parameters" do yahoo.should_receive(:fetch_access_token).and_return(["access_token", "access_token_secret", "guid"]) @@ -27,25 +39,30 @@ contacts_as_json end yahoo.fetch_contacts_from_token_and_verifier "auth_token", "auth_token_secret", "oauth_verifier" end - it "should parse the contacts correctly" do + it "should correctly parse id, name,email,gender, birthday, image source and relation" do yahoo.should_receive(:fetch_access_token).and_return(["access_token", "access_token_secret", "guid"]) yahoo.should_receive(:http_get).and_return(contacts_as_json) result = yahoo.fetch_contacts_from_token_and_verifier "auth_token", "auth_token_secret", "oauth_verifier" result.size.should be(1) - result.first[:name].should eq("John Doe") - result.first[:email].should eq("john@yahoo.com") + result.first[:id].should eq('10') + result.first[:first_name].should eq('John') + result.first[:last_name].should eq('Smith') + result.first[:name].should eq("John Smith") + result.first[:email].should eq("johnny@yahoo.com") + result.first[:gender].should be_nil + result.first[:birthday].should eq({:day=>22, :month=>2, :year=>1952}) + result.first[:relation].should be_nil end it "should return an empty list of contacts" do empty_contacts_list = '{"contacts": {"start":0, "count":0}}' yahoo.should_receive(:fetch_access_token).and_return(["access_token", "access_token_secret", "guid"]) yahoo.should_receive(:http_get).and_return(empty_contacts_list) result = yahoo.fetch_contacts_from_token_and_verifier "auth_token", "auth_token_secret", "oauth_verifier" result.should be_empty - end end end