/
graph_api_spec.rb
68 lines (61 loc) · 2.28 KB
/
graph_api_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'spec_helper'
describe 'Koala::Facebook::GraphAPIMethods' do
before do
@api = Koala::Facebook::API.new(@token)
# app API
@app_id = KoalaTest.app_id
@app_access_token = KoalaTest.app_access_token
@app_api = Koala::Facebook::API.new(@app_access_token)
end
describe 'post-processing for' do
let(:post_processing) { lambda {} }
# Most API methods have the same signature, we test get_object representatively
# and the other methods which do some post-processing locally
context '#get_object' do
it 'returns result of block' do
result = {"id" => 1, "name" => 1, "updated_time" => 1}
@api.stub(:api).and_return(result)
post_processing.should_receive(:call).
with(result).and_return('new result')
@api.get_object('koppel', &post_processing).should == 'new result'
end
end
context '#get_picture' do
it 'returns result of block' do
result = "http://facebook.com/"
@api.stub(:api).and_return("Location" => result)
post_processing.should_receive(:call).
with(result).and_return('new result')
@api.get_picture('lukeshepard', &post_processing).should == 'new result'
end
end
context '#fql_multiquery' do
before do
@api.should_receive(:get_object).and_return([
{"name" => "query1", "fql_result_set" => [{"id" => 123}]},
{"name" => "query2", "fql_result_set" => ["id" => 456]}
])
end
it 'is called with resolved response' do
resolved_result = {
'query1' => [{'id' => 123}],
'query2' => [{'id'=>456}]
}
post_processing.should_receive(:call).
with(resolved_result).and_return('id'=>'123', 'id'=>'456')
@api.fql_multiquery({}, &post_processing).should ==
{'id'=>'123', 'id'=>'456'}
end
end
context '#get_page_access_token' do
it 'returns result of block' do
token = Koala::MockHTTPService::APP_ACCESS_TOKEN
@api.stub(:api).and_return("access_token" => token)
post_processing.should_receive(:call).
with(token).and_return('base64-encoded access token')
@api.get_page_access_token('facebook', &post_processing).should ==
'base64-encoded access token'
end
end
end
end