spec/people/vkontakte_spec.rb in social_profile-0.2.1 vs spec/people/vkontakte_spec.rb in social_profile-0.2.2
- old
+ new
@@ -1,23 +1,115 @@
+# encoding: utf-8
+
require 'spec_helper'
describe SocialProfile::People::Vkontakte do
it "should be a Module" do
SocialProfile::People.should be_a(Module)
end
context "vkontakte" do
before(:each) do
- @user = SocialProfile::Person.get(:vkontakte, "123456789", "abc")
- stub_request(:get, "https://api.vk.com/method/users.get?access_token=abc&fields=counters&uids=123456789").
- to_return(:status => 200, :body => File.read(SocialProfile.root_path.join('spec/mock_json/vkontakte/friends_count.json')))
+ @user = SocialProfile::Person.get(:vkontakte, "2592709", "abc")
+
+ stub_request(:get, "https://api.vk.com/method/users.get?access_token=abc&fields=counters&uids=2592709").
+ to_return(:status => 200, :body => fixture('vkontakte/friends_count.json'))
+ stub_request(:get, "https://api.vk.com/method/wall.get?access_token=abc&count=100&filter=owner&offset=0&owner_id=2592709").
+ to_return(:status => 200, :body => fixture("vkontakte/last_posts.json"))
+ stub_request(:get, "https://api.vk.com/method/likes.getList?access_token=abc&count=1000&item_id=655&offset=0&owner_id=2592709&type=post").
+ to_return(:status => 200, :body => fixture("vkontakte/likes_post_655.json"))
+ stub_request(:get, "https://api.vk.com/method/likes.getList?access_token=abc&count=1000&item_id=290498375&offset=0&owner_id=2592709&type=photo").
+ to_return(:status => 200, :body => fixture("vkontakte/likes_photo_290498375.json"))
+ stub_request(:get, "https://api.vk.com/method/wall.getComments?access_token=abc&count=100&need_likes=1&offset=0&owner_id=2592709&post_id=655&preview_length=0").
+ to_return(:status => 200, :body => fixture("vkontakte/comments_post_655.json"))
+ stub_request(:get, "https://api.vk.com/method/photos.getAllComments?access_token=abc&count=100&need_likes=1&offset=0&owner_id=2592709&uid=2592709").
+ to_return(:status => 200, :body => fixture("vkontakte/comments_photos.json"))
+ stub_request(:get, "https://api.vk.com/method/friends.get?access_token=abc&count=5000&fields=domain&offset=0&user_id=2592709").
+ to_return(:status => 200, :body => fixture("vkontakte/friends.json"))
+ stub_request(:get, "https://api.vk.com/method/users.getFollowers?access_token=abc&count=1000&fields=screen_name&offset=0&user_id=2592709").
+ to_return(:status => 200, :body => fixture("vkontakte/followers.json"))
+ stub_request(:get, "https://api.vk.com/method/wall.getReposts?access_token=abc&count=1000&offset=0&owner_id=2592709&post_id=3675").
+ to_return(:status => 200, :body => fixture("vkontakte/shares_post_3675.json"))
end
it "should be a vkontakte profile" do
@user.should be_a(SocialProfile::People::Vkontakte)
end
it "should response to friends_count" do
@user.friends_count.should > 0
+ end
+
+ it "should response to last_posts" do
+ @user.last_posts.size.should == 100
+ end
+
+ it "should response to last_post_by_days by 30 days" do
+ @user.last_post_by_days(30).size.should == 0
+ end
+
+ it "should response to last_post_by_days by 30 days with date_end options" do
+ @user.last_post_by_days(30, :date_end => DateTime.new(2014, 5, 17)).size.should == 1
+ end
+
+ it "should response to last_post_by_days by 2119 days" do
+ stub_request(:get, "https://api.vk.com/method/wall.get?access_token=abc&count=100&filter=owner&offset=100&owner_id=2592709").
+ to_return(:status => 200, :body => fixture("vkontakte/last_posts_2.json"))
+
+ posts = @user.last_post_by_days(2119, :date_end => DateTime.new(2014, 8, 19))
+
+ posts.size.should == 175
+ posts.last["text"].should == "хочеш узнать про меня побольше? введи в google ник super_p."
+ end
+
+ it "should response to object_likes" do
+ @user.object_likes("655")["items"].size.should == 7
+ @user.object_likes("290498375", :type => "photo")["items"].size.should == 17
+ end
+
+ it "should response to object_likes with fetch_all" do
+ @user.object_likes("655", :fetch_all => true).size.should == 7
+ @user.object_likes("290498375", :type => "photo", :fetch_all => true).size.should == 17
+ end
+
+ it "should response to post_comments" do
+ @user.post_comments("655")["items"].size.should == 3
+ end
+
+ it "should response to post_comments with fetch_all" do
+ @user.post_comments("655", :fetch_all => true).size.should == 3
+ end
+
+ it "should response to post_shares" do
+ @user.post_shares("3675")["items"].size.should == 21
+ end
+
+ it "should response to post_shares with fetch_all" do
+ @user.post_shares("3675", :fetch_all => true).size.should == 21
+ end
+
+ it "should response to photos_comments" do
+ @user.photos_comments.size.should == 100
+ end
+
+ it "should response to photos_comments with days" do
+ @user.photos_comments(:days => 30).size.should == 0
+ end
+
+ it "should fetch all friends" do
+ @user.friends.size.should == 208
+ end
+
+ it "should fetch all followers" do
+ @user.followers.size.should == 30
+ end
+
+ it "should fetch all followers with iteration by 20 items in step" do
+ stub_request(:get, "https://api.vk.com/method/users.getFollowers?access_token=abc&count=20&fields=screen_name&offset=0&user_id=2592709").
+ to_return(:status => 200, :body => fixture("vkontakte/followers_20.json"))
+ stub_request(:get, "https://api.vk.com/method/users.getFollowers?access_token=abc&count=20&fields=screen_name&offset=20&user_id=2592709").
+ to_return(:status => 200, :body => fixture("vkontakte/followers_20_2.json"))
+
+ @user.followers(:count => 20).size.should == 30
end
end
end