fake_fb_marketing_api 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/fake_fb_marketing_api.gemspec +1 -1
- data/lib/fake_fb_marketing_api/application.rb +2 -0
- data/lib/fake_fb_marketing_api/fake_facebook.rb +1 -0
- data/lib/fake_fb_marketing_api/version.rb +1 -1
- data/lib/fake_fb_marketing_api/versions/v3_3.rb +104 -0
- data/spec/{fake_fb_marketing_api_spec.rb → fake_fb_marketing_api_V3_2_spec.rb} +1 -0
- data/spec/fake_fb_marketing_api_v3_3_spec.rb +351 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 902b82f2118934fcc72d5f5f13eff04ecf047e2b
|
4
|
+
data.tar.gz: 9810c731ff7749c5c5217ad5e770ab0cd9667567
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 796be2231683d601691c4660233945e8e295092ba61c07003a4c6312937b396b4b320d9687f63fd3c85f15eee50a8172120ffab8e0d3e6b13850f8bf7b89704f
|
7
|
+
data.tar.gz: 97cffc4336e934983a1620a7b1431a1a061185a25e366a4a9404f7eb91d7fd28b0bdb240d0d53a5818fe72ee002f16b2e87cecc844101eb0dc8cf69ac2b74a10
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fake_fb_marketing_api (0.0.
|
4
|
+
fake_fb_marketing_api (0.0.6)
|
5
5
|
sinatra (~> 2.0)
|
6
6
|
we-call (~> 0.9)
|
7
7
|
|
@@ -39,7 +39,7 @@ GEM
|
|
39
39
|
faraday (>= 0.9.0, < 1)
|
40
40
|
faraday_middleware (0.13.1)
|
41
41
|
faraday (>= 0.7.4, < 1.0)
|
42
|
-
ffi (1.
|
42
|
+
ffi (1.11.1)
|
43
43
|
hashdiff (0.3.8)
|
44
44
|
i18n (1.5.3)
|
45
45
|
concurrent-ruby (~> 1.0)
|
@@ -110,7 +110,7 @@ PLATFORMS
|
|
110
110
|
ruby
|
111
111
|
|
112
112
|
DEPENDENCIES
|
113
|
-
bundler
|
113
|
+
bundler
|
114
114
|
capybara_discoball
|
115
115
|
fake_fb_marketing_api!
|
116
116
|
faker (~> 1.9)
|
@@ -125,4 +125,4 @@ DEPENDENCIES
|
|
125
125
|
webmock
|
126
126
|
|
127
127
|
BUNDLED WITH
|
128
|
-
|
128
|
+
2.0.2
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |gem|
|
|
35
35
|
end
|
36
36
|
gem.required_ruby_version = '>= 2.4.3'
|
37
37
|
|
38
|
-
gem.add_development_dependency 'bundler'
|
38
|
+
gem.add_development_dependency 'bundler'
|
39
39
|
gem.add_development_dependency 'capybara_discoball'
|
40
40
|
gem.add_development_dependency 'faker', '~> 1.9'
|
41
41
|
gem.add_development_dependency 'faraday'
|
@@ -2,12 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'rack/builder'
|
4
4
|
|
5
|
+
require_relative './versions/v3_3'
|
5
6
|
require_relative './versions/v3_2'
|
6
7
|
require_relative './versions/v3_0'
|
7
8
|
|
8
9
|
module FakeFbMarketingApi
|
9
10
|
class Application
|
10
11
|
VERSIONS = [
|
12
|
+
FakeFbMarketingApi::Versions::V33,
|
11
13
|
FakeFbMarketingApi::Versions::V32,
|
12
14
|
FakeFbMarketingApi::Versions::V30
|
13
15
|
].freeze
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../base'
|
4
|
+
require_relative '../fake_facebook'
|
5
|
+
|
6
|
+
module FakeFbMarketingApi
|
7
|
+
module Versions
|
8
|
+
class V33 < Base
|
9
|
+
set_namespace 'v3.3'
|
10
|
+
|
11
|
+
get '/:business_id/owned_ad_accounts' do
|
12
|
+
content_type :json
|
13
|
+
FakeFacebook.owned_ad_accounts.to_json
|
14
|
+
end
|
15
|
+
|
16
|
+
post '/:business_id/adaccount' do
|
17
|
+
content_type :json
|
18
|
+
FakeFacebook.add_owned_ad_account(
|
19
|
+
{
|
20
|
+
'name' => params[:name],
|
21
|
+
'id' => ENV.fetch('FACEBOOK_AD_ACCOUNT_ID')
|
22
|
+
}
|
23
|
+
)
|
24
|
+
{
|
25
|
+
end_advertiser_id: params[:end_advertiser_id],
|
26
|
+
media_agency_id: params[:media_agency_id],
|
27
|
+
business_id: params[:business_id],
|
28
|
+
account_id: ENV['FACEBOOK_AD_ACCOUNT_ID'].sub(/^act_/, ''),
|
29
|
+
id: ENV['FACEBOOK_AD_ACCOUNT_ID'],
|
30
|
+
partner_id: 'NONE'
|
31
|
+
}.to_json
|
32
|
+
end
|
33
|
+
|
34
|
+
post '/:project_id/adaccounts' do
|
35
|
+
content_type :json
|
36
|
+
proxy_post_to_fb(request, response)
|
37
|
+
end
|
38
|
+
|
39
|
+
post '/:ad_account_id/assigned_users' do
|
40
|
+
proxy_post_to_fb(request, response)
|
41
|
+
end
|
42
|
+
|
43
|
+
post '/:business_id/businessprojects' do
|
44
|
+
proxy_post_to_fb(request, response)
|
45
|
+
end
|
46
|
+
|
47
|
+
post '/:ad_account_id/campaigns' do
|
48
|
+
content_type :json
|
49
|
+
case params[:objective]
|
50
|
+
when 'BRAND_AWARENESS'
|
51
|
+
{
|
52
|
+
id: ENV['BRAND_AWARENESS_CAMPAIGN_ID']
|
53
|
+
}.to_json
|
54
|
+
when 'LINK_CLICKS'
|
55
|
+
{
|
56
|
+
id: ENV['LINK_CLICKS_CAMPAIGN_ID']
|
57
|
+
}.to_json
|
58
|
+
when 'VIDEO_VIEWS'
|
59
|
+
{
|
60
|
+
id: ENV['VIDEO_VIEWS_CAMPAIGN_ID']
|
61
|
+
}.to_json
|
62
|
+
when 'REACH'
|
63
|
+
{
|
64
|
+
id: ENV['REACH_CAMPAIGN_ID']
|
65
|
+
}.to_json
|
66
|
+
when 'POST_ENGAGEMENT'
|
67
|
+
{
|
68
|
+
id: ENV['POST_ENGAGEMENT_CAMPAIGN_ID']
|
69
|
+
}.to_json
|
70
|
+
when 'PAGE_LIKES'
|
71
|
+
{
|
72
|
+
id: ENV['PAGE_LIKES_CAMPAIGN_ID']
|
73
|
+
}.to_json
|
74
|
+
when 'CONVERSIONS_COUNT'
|
75
|
+
{
|
76
|
+
id: ENV['CONVERSIONS_COUNT_CAMPAIGN_ID']
|
77
|
+
}.to_json
|
78
|
+
when 'CONVERSIONS_FUNDRAISE'
|
79
|
+
{
|
80
|
+
id: ENV['CONVERSIONS_FUNDRAISE_CAMPAIGN_ID']
|
81
|
+
}.to_json
|
82
|
+
when 'CONVERSIONS'
|
83
|
+
{
|
84
|
+
id: ENV['CONVERSIONS_CAMPAIGN_ID']
|
85
|
+
}.to_json
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
get '/:graph_id/*' do
|
90
|
+
content_type :json
|
91
|
+
proxy_get_to_fb(request, response)
|
92
|
+
end
|
93
|
+
|
94
|
+
post '/*' do
|
95
|
+
content_type :json
|
96
|
+
return proxy_post_to_fb(request, response)
|
97
|
+
end
|
98
|
+
|
99
|
+
get '/*' do
|
100
|
+
proxy_get_to_fb(request, response)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -16,6 +16,7 @@ RSpec.describe FakeFbMarketingApi::Application do
|
|
16
16
|
before { ENV['POST_ENGAGEMENT_CAMPAIGN_ID'] = Faker::Number.number(10) }
|
17
17
|
before { ENV['PAGE_LIKES_CAMPAIGN_ID'] = Faker::Number.number(10) }
|
18
18
|
before do
|
19
|
+
FakeFbMarketingApi::FakeFacebook.setup
|
19
20
|
WebMock.disable_net_connect!(allow: /127.0.0.1/)
|
20
21
|
Capybara::Discoball.spin(FakeFbMarketingApi::Application) do |server|
|
21
22
|
Koala.http_service.http_options = {
|
@@ -0,0 +1,351 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'koala'
|
4
|
+
require 'capybara_discoball'
|
5
|
+
|
6
|
+
RSpec.describe FakeFbMarketingApi::Application do
|
7
|
+
before { ENV['PROJECT_ID'] = Faker::Number.number(10) }
|
8
|
+
before { ENV['BUSINESS_ID'] = Faker::Number.number(10) }
|
9
|
+
before { ENV['FACEBOOK_AD_ACCOUNT_ID'] = Faker::Number.number(10) }
|
10
|
+
before { ENV['FACEBOOK_AD_ACCOUNT_NAME'] = Faker::Seinfeld.character }
|
11
|
+
before { ENV['BRAND_AWARENESS_CAMPAIGN_ID'] = Faker::Number.number(10) }
|
12
|
+
before { ENV['LINK_CLICKS_CAMPAIGN_ID'] = Faker::Number.number(10) }
|
13
|
+
before { ENV['VIDEO_VIEWS_CAMPAIGN_ID'] = Faker::Number.number(10) }
|
14
|
+
before { ENV['CONVERSIONS_CAMPAIGN_ID'] = Faker::Number.number(10) }
|
15
|
+
before { ENV['REACH_CAMPAIGN_ID'] = Faker::Number.number(10) }
|
16
|
+
before { ENV['POST_ENGAGEMENT_CAMPAIGN_ID'] = Faker::Number.number(10) }
|
17
|
+
before { ENV['PAGE_LIKES_CAMPAIGN_ID'] = Faker::Number.number(10) }
|
18
|
+
before do
|
19
|
+
FakeFbMarketingApi::FakeFacebook.setup
|
20
|
+
WebMock.disable_net_connect!(allow: /127.0.0.1/)
|
21
|
+
Capybara::Discoball.spin(FakeFbMarketingApi::Application) do |server|
|
22
|
+
Koala.http_service.http_options = {
|
23
|
+
use_ssl: false
|
24
|
+
}
|
25
|
+
Koala.configure do |config|
|
26
|
+
config.api_version = 'v3.3'
|
27
|
+
config.graph_server = server.url.gsub 'http://', ''
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:access_token) { Faker::Number.number(20) }
|
33
|
+
let(:graph) { Koala::Facebook::API.new(access_token) }
|
34
|
+
|
35
|
+
it 'has a version number' do
|
36
|
+
expect(FakeFbMarketingApi::VERSION).not_to be nil
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'GET /:business_id/owned_ad_acocunts' do
|
40
|
+
it 'does not show any ad accounts until one is created' do
|
41
|
+
response = graph.get_object("#{ENV['BUSINESS_ID']}/owned_ad_accounts", fields: 'id,name')
|
42
|
+
|
43
|
+
expect(response).to eq([])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns a single ad account after one has been created' do
|
47
|
+
end_advertiser_id = Faker::Number.number(10)
|
48
|
+
media_agency_id = Faker::Number.number(10)
|
49
|
+
name = Faker::Seinfeld.character
|
50
|
+
response = graph.put_connections "#{ENV['BUSINESS_ID']}", 'adaccount',
|
51
|
+
name: name,
|
52
|
+
currency: 'USD', timezone_id: 6, end_advertiser_id: end_advertiser_id,
|
53
|
+
media_agency_id: media_agency_id, partner: 'NONE'
|
54
|
+
response = graph.get_object("#{ENV['BUSINESS_ID']}/owned_ad_accounts", fields: 'id,name')
|
55
|
+
|
56
|
+
expect(response).to eq(
|
57
|
+
[
|
58
|
+
{
|
59
|
+
'id' => ENV.fetch('FACEBOOK_AD_ACCOUNT_ID'),
|
60
|
+
'name' => name
|
61
|
+
}
|
62
|
+
]
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'POST /:business_id/adaccount' do
|
68
|
+
context 'when creating an ad account' do
|
69
|
+
it 'works' do
|
70
|
+
end_advertiser_id = Faker::Number.number(10)
|
71
|
+
media_agency_id = Faker::Number.number(10)
|
72
|
+
response = graph.put_connections (ENV['BUSINESS_ID']).to_s, 'adaccount',
|
73
|
+
name: 'Test Ad Account',
|
74
|
+
currency: 'USD', timezone_id: 6, end_advertiser_id: end_advertiser_id,
|
75
|
+
media_agency_id: media_agency_id, partner: 'NONE'
|
76
|
+
|
77
|
+
expect(response).to include
|
78
|
+
{
|
79
|
+
'business_id' => ENV['BUSINESS_ID'],
|
80
|
+
'account_id' => ENV['FACEBOOK_AD_ACCOUNT_ID'],
|
81
|
+
'id' => "act_#{ENV['FACEBOOK_AD_ACCOUNT_ID']}",
|
82
|
+
'end_advertiser_id' => end_advertiser_id,
|
83
|
+
'media_agency_id' => media_agency_id,
|
84
|
+
'partner_id' => 'NONE'
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'POST /:project_id/adaccounts' do
|
91
|
+
context 'when adding a user to an ad account' do
|
92
|
+
it 'calls out to facebook' do
|
93
|
+
project_id = Faker::Number.number(15).to_s
|
94
|
+
fb_ad_account = ENV['FACEBOOK_AD_ACCOUNT_ID']
|
95
|
+
stub_request(:post, "https://graph.facebook.com/v3.3/#{project_id}/adaccounts?access_token=#{access_token}&adaccount_id=#{fb_ad_account}")
|
96
|
+
.with(
|
97
|
+
headers: {
|
98
|
+
'Expect' => '',
|
99
|
+
'User-Agent' => 'fb-graph-proxy',
|
100
|
+
'X-App-Env' => 'staging',
|
101
|
+
'X-App-Name' => 'fb-graph-proxy'
|
102
|
+
}
|
103
|
+
).to_return(status: 200, body: { 'success' => true }.to_json, headers: {})
|
104
|
+
|
105
|
+
response = graph.put_connections(project_id, 'adaccounts', adaccount_id: fb_ad_account)
|
106
|
+
|
107
|
+
expect(response).to eq('success' => true)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'POST /:ad_account_id/assigned_users' do
|
113
|
+
it 'passes makes a post to fb' do
|
114
|
+
user_id = Faker::Number.number(14).to_s
|
115
|
+
ad_account_id = Faker::Number.number(15).to_s
|
116
|
+
stub_request(:post, "https://graph.facebook.com/v3.3/#{ad_account_id}/assigned_users?access_token=#{access_token}&tasks=ANALYZE,MANAGE,ADVERTISE&user=#{user_id}")
|
117
|
+
.with(
|
118
|
+
headers: {
|
119
|
+
'Content-Length' => '0',
|
120
|
+
'Expect' => '',
|
121
|
+
'User-Agent' => 'fb-graph-proxy',
|
122
|
+
'X-App-Env' => 'staging',
|
123
|
+
'X-App-Name' => 'fb-graph-proxy'
|
124
|
+
}
|
125
|
+
)
|
126
|
+
.to_return(status: 200, body: { 'success' => true }.to_json, headers: {})
|
127
|
+
|
128
|
+
response = graph.put_connections(ad_account_id, 'assigned_users', user: user_id, tasks: %w[ANALYZE MANAGE ADVERTISE])
|
129
|
+
|
130
|
+
expect(response).to eq 'success' => true
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'POST /:business_id/businessprojects' do
|
135
|
+
it 'passes a static project_id' do
|
136
|
+
stub_request(:post, "https://graph.facebook.com/v3.3/#{ENV['BUSINESS_ID']}/businessprojects?access_token=#{access_token}&name=test_project")
|
137
|
+
.to_return(status: 200, body: { 'id' => ENV['PROJECT_ID'] }.to_json, headers: {})
|
138
|
+
|
139
|
+
result = graph.put_connections(ENV['BUSINESS_ID'], 'businessprojects', name: 'test_project')
|
140
|
+
|
141
|
+
expect(result).to include 'id' => ENV['PROJECT_ID']
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe 'POST /:ad_account_id/campaigns' do
|
146
|
+
it 'works for brand awareness' do
|
147
|
+
objective = 'BRAND_AWARENESS'
|
148
|
+
|
149
|
+
campaign = graph.put_connections("act_#{ENV['FACEBOOK_AD_ACCOUNT_ID']}", 'campaigns', budget_rebalance_flag: false, name: "#{objective} Test Campaign", objective: objective, status: 'ACTIVE')
|
150
|
+
|
151
|
+
expect(campaign).to eq 'id' => ENV['BRAND_AWARENESS_CAMPAIGN_ID']
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'works for link clicks' do
|
155
|
+
objective = 'LINK_CLICKS'
|
156
|
+
|
157
|
+
campaign = graph.put_connections("act_#{ENV['FACEBOOK_AD_ACCOUNT_ID']}", 'campaigns', budget_rebalance_flag: false, name: "#{objective} Test Campaign", objective: objective, status: 'ACTIVE')
|
158
|
+
|
159
|
+
expect(campaign).to eq 'id' => ENV['LINK_CLICKS_CAMPAIGN_ID']
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'works for video views' do
|
163
|
+
objective = 'VIDEO_VIEWS'
|
164
|
+
|
165
|
+
campaign = graph.put_connections("act_#{ENV['FACEBOOK_AD_ACCOUNT_ID']}", 'campaigns', budget_rebalance_flag: false, name: "#{objective} Test Campaign", objective: objective, status: 'ACTIVE')
|
166
|
+
|
167
|
+
expect(campaign).to eq 'id' => ENV['VIDEO_VIEWS_CAMPAIGN_ID']
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'works for reach' do
|
171
|
+
objective = 'REACH'
|
172
|
+
|
173
|
+
campaign = graph.put_connections("act_#{ENV['FACEBOOK_AD_ACCOUNT_ID']}", 'campaigns', budget_rebalance_flag: false, name: "#{objective} Test Campaign", objective: objective, status: 'ACTIVE')
|
174
|
+
|
175
|
+
expect(campaign).to eq 'id' => ENV['REACH_CAMPAIGN_ID']
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'works for post engagement' do
|
179
|
+
objective = 'POST_ENGAGEMENT'
|
180
|
+
|
181
|
+
campaign = graph.put_connections("act_#{ENV['FACEBOOK_AD_ACCOUNT_ID']}", 'campaigns', budget_rebalance_flag: false, name: "#{objective} Test Campaign", objective: objective, status: 'ACTIVE')
|
182
|
+
|
183
|
+
expect(campaign).to eq 'id' => ENV['POST_ENGAGEMENT_CAMPAIGN_ID']
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'works for page likes' do
|
187
|
+
objective = 'PAGE_LIKES'
|
188
|
+
|
189
|
+
campaign = graph.put_connections("act_#{ENV['FACEBOOK_AD_ACCOUNT_ID']}", 'campaigns', budget_rebalance_flag: false, name: "#{objective} Test Campaign", objective: objective, status: 'ACTIVE')
|
190
|
+
|
191
|
+
expect(campaign).to eq 'id' => ENV['PAGE_LIKES_CAMPAIGN_ID']
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'works for conversions' do
|
195
|
+
objective = 'CONVERSIONS'
|
196
|
+
|
197
|
+
campaign = graph.put_connections("act_#{ENV['FACEBOOK_AD_ACCOUNT_ID']}", 'campaigns', budget_rebalance_flag: false, name: "#{objective} Test Campaign", objective: objective, status: 'ACTIVE')
|
198
|
+
|
199
|
+
expect(campaign).to eq 'id' => ENV['CONVERSIONS_CAMPAIGN_ID']
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe 'GET /:ad_account_id/campaigns' do
|
204
|
+
context 'when no campaigns have been created' do
|
205
|
+
it 'returns nothing' do
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe 'GET /:graph_id/insights' do
|
211
|
+
it 'passes through insight requests' do
|
212
|
+
graph_id = Faker::Number.number(10)
|
213
|
+
stub_request(:get, "https://graph.facebook.com/v3.3/#{graph_id}/insights?access_token=#{access_token}&date_preset=lifetime&fields=ad_id")
|
214
|
+
.to_return(status: 200, body: "{\"data\":[{\"ad_id\":\"#{graph_id}\",\"date_start\":\"2018-05-30\",\"date_stop\":\"2019-01-05\"}],\"paging\":{\"cursors\":{\"before\":\"MAZDZD\",\"after\":\"MAZDZD\"}}}", headers: {})
|
215
|
+
|
216
|
+
ad_insights = graph.get_object("#{graph_id}/insights", fields: 'ad_id', date_preset: 'lifetime')
|
217
|
+
|
218
|
+
expect(ad_insights.count).to eq 1
|
219
|
+
expect(ad_insights.first['ad_id']).to eq graph_id
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'returns headers of the api call' do
|
223
|
+
graph_id = Faker::Number.number(10)
|
224
|
+
headers = { 'etag' => '423144fb7fd642308ea9666e20cceb65ee4f6650' }
|
225
|
+
stub_request(:get, "https://graph.facebook.com/v3.3/#{graph_id}/insights?access_token=#{access_token}&date_preset=lifetime&fields=ad_id")
|
226
|
+
.to_return(status: 200, body: "{\"data\":[{\"ad_id\":\"#{graph_id}\",\"date_start\":\"2018-05-30\",\"date_stop\":\"2019-01-05\"}],\"paging\":{\"cursors\":{\"before\":\"MAZDZD\",\"after\":\"MAZDZD\"}}}", headers: headers)
|
227
|
+
|
228
|
+
ad_insights = graph.get_object("#{graph_id}/insights", fields: 'ad_id', date_preset: 'lifetime')
|
229
|
+
|
230
|
+
expect(ad_insights.headers).to include 'etag'
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'returns the status of the api call' do
|
234
|
+
graph_id = Faker::Number.number(10)
|
235
|
+
headers = { 'etag' => '423144fb7fd642308ea9666e20cceb65ee4f6650' }
|
236
|
+
stub_request(:get, "https://graph.facebook.com/v3.3/#{graph_id}/insights?access_token=#{access_token}&date_preset=lifetime&fields=ad_id")
|
237
|
+
.to_return(status: 400, body: "{\"error\":{\"message\":\"(#100) date_preset must be \",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"GB8SawFk\/47\"}}", headers: headers)
|
238
|
+
|
239
|
+
expect do
|
240
|
+
graph.get_object("#{graph_id}/insights", fields: 'ad_id', date_preset: 'lifetime')
|
241
|
+
end.to raise_error Koala::KoalaError
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe 'POST / batch requests' do
|
246
|
+
it 'passes through insight requests' do
|
247
|
+
graph_id = Faker::Number.number(10)
|
248
|
+
json = File.open("#{Dir.pwd}/spec/fb_batch_response.json").read
|
249
|
+
json.gsub!('replace_ad_id', graph_id)
|
250
|
+
stub_request(:post, "https://graph.facebook.com/v3.3/?access_token=#{access_token}&batch=%5B%7B%22method%22:%22get%22,%22relative_url%22:%22#{graph_id}/insights?date_preset=lifetime%26fields=ad_id%22%7D,%7B%22method%22:%22get%22,%22relative_url%22:%22#{graph_id}/insights?date_preset=lifetime%26fields=ad_id%22%7D%5D")
|
251
|
+
.to_return(status: 200, body: json, headers: {})
|
252
|
+
|
253
|
+
result = graph.batch do |batch|
|
254
|
+
batch.get_object("#{graph_id}/insights", fields: 'ad_id', date_preset: 'lifetime')
|
255
|
+
batch.get_object("#{graph_id}/insights", fields: 'ad_id', date_preset: 'lifetime')
|
256
|
+
end
|
257
|
+
|
258
|
+
expect(result.first.first).to include 'ad_id' => graph_id
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'returns errror when they happen' do
|
262
|
+
graph_id = Faker::Number.number(10)
|
263
|
+
json = File.open("#{Dir.pwd}/spec/fb_batch_error_response.json").read
|
264
|
+
json.gsub!('replace_ad_id', graph_id)
|
265
|
+
stub_request(:post, "https://graph.facebook.com/v3.3/?access_token=#{access_token}&batch=%5B%7B%22method%22:%22get%22,%22relative_url%22:%22doesnotexist/insights?date_preset=lifetime%26fields=ad_id%22%7D,%7B%22method%22:%22get%22,%22relative_url%22:%22doesnotexist/insights?date_preset=lifetime%26fields=ad_id%22%7D%5D").
|
266
|
+
# stub_request(:get, "https://graph.facebook.com/v3.0/?access_token=#{access_token}&batch=%5B%7B%22method%22:%22get%22,%22relative_url%22:%22#{graph_id}/insights?date_preset=lifetime%26fields=ad_id%22%7D%5D").
|
267
|
+
to_return(status: 200, body: json)
|
268
|
+
|
269
|
+
result = graph.batch do |batch|
|
270
|
+
batch.get_object('doesnotexist/insights', fields: 'ad_id', date_preset: 'lifetime')
|
271
|
+
batch.get_object('doesnotexist/insights', fields: 'ad_id', date_preset: 'lifetime')
|
272
|
+
end
|
273
|
+
|
274
|
+
expect(result[0].fb_error_code).to eq 803
|
275
|
+
expect(result[1].fb_error_code).to eq 803
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'passes headers through' do
|
279
|
+
graph_id = Faker::Number.number(10)
|
280
|
+
json = File.open("#{Dir.pwd}/spec/fb_batch_error_response.json").read
|
281
|
+
json.gsub!('replace_ad_id', graph_id)
|
282
|
+
stub_request(:post, "https://graph.facebook.com/v3.3/?access_token=#{access_token}&batch=%5B%7B%22method%22:%22get%22,%22relative_url%22:%22doesnotexist/insights?date_preset=lifetime%26fields=ad_id%22%7D,%7B%22method%22:%22get%22,%22relative_url%22:%22doesnotexist/insights?date_preset=lifetime%26fields=ad_id%22%7D%5D")
|
283
|
+
.to_return(status: 200,
|
284
|
+
body: json,
|
285
|
+
headers: { 'Content-Type' => 'text/javascript; charset=UTF-8',
|
286
|
+
'Facebook-API-Version' => 'v3.3',
|
287
|
+
'X-App-Usage' => '{"call_count":0,"total_cputime":0,"total_time":0}',
|
288
|
+
'ETag' => '9d4067db4e21a79fc53d45e0f487e67c5c0b50a1',
|
289
|
+
'Access-Control-Allow-Origin' => '*',
|
290
|
+
'Cache-Control' => 'private, no-cache, no-store, must-revalidate',
|
291
|
+
'Vary' => 'Accept-Encoding',
|
292
|
+
'Expires' => 'Sat, 01 Jan 2000 00:00:00 GMT',
|
293
|
+
'X-Ad-Account-Usage' => '{"acc_id_util_pct":0}',
|
294
|
+
'Strict-Transport-Security' => 'max-age=15552000; preload',
|
295
|
+
'Transfer-Encoding' => 'chunked',
|
296
|
+
'Connection' => 'keep-alive',
|
297
|
+
'Pragma' => 'no-cache' })
|
298
|
+
|
299
|
+
result = graph.batch do |batch|
|
300
|
+
batch.get_object('doesnotexist/insights', fields: 'ad_id', date_preset: 'lifetime')
|
301
|
+
batch.get_object('doesnotexist/insights', fields: 'ad_id', date_preset: 'lifetime')
|
302
|
+
end
|
303
|
+
|
304
|
+
expect(result).not_to be_nil
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
describe 'POST /:ad_set_id' do
|
309
|
+
it 'passes through requests to pause an ad' do
|
310
|
+
graph_id = Faker::Number.number(10)
|
311
|
+
stub_request(:post, "https://graph.facebook.com/v3.3/#{graph_id}/?access_token=#{access_token}&status=PAUSED")
|
312
|
+
.to_return(status: 200, body: { success: true }.to_json, headers: {})
|
313
|
+
|
314
|
+
result = graph.put_connections(graph_id, '', status: 'PAUSED')
|
315
|
+
|
316
|
+
expect(result).to include 'success' => true
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
describe 'GET /' do
|
321
|
+
it 'gets graph objects' do
|
322
|
+
graph_id = Faker::Number.number(10)
|
323
|
+
json = File.open("#{Dir.pwd}/spec/fb_graph_object_response.json").read
|
324
|
+
stub_request(:get, "https://graph.facebook.com/v3.3/?access_token=#{access_token}&fields=og_object%7Btitle,description,image%7D&id=https://fox2now.com/2018/04/02/5-myths-about-organ-donation/")
|
325
|
+
.to_return(
|
326
|
+
status: 200,
|
327
|
+
body: json,
|
328
|
+
headers: { 'Vary' => 'Accept-Encoding',
|
329
|
+
'ETag' => '"90f0a9d85d04bf2760528d1f834dfa8444145dfb"',
|
330
|
+
'x-app-usage' => '{"call_count":0,"total_cputime":0,"total_time":0}',
|
331
|
+
'Content-Type' => 'application/json; charset=UTF-8',
|
332
|
+
'facebook-api-version' => 'v3.0',
|
333
|
+
'x-fb-rev' => '4669664',
|
334
|
+
'Access-Control-Allow-Origin' => '*',
|
335
|
+
'Cache-Control' => 'private, no-cache, no-store, must-revalidate',
|
336
|
+
'x-fb-trace-id' => 'HwmUZwadEmw',
|
337
|
+
'Expires' => 'Sat, 01 Jan 2000 00:00:00 GMT',
|
338
|
+
'Strict-Transport-Security' => 'max-age=15552000; preload',
|
339
|
+
'Pragma' => 'no-cache',
|
340
|
+
'X-FB-Debug' => 'ykeEji7+g4+BKuq0fR8pJC2k3egR1GLILfEN7eL2VcGOBqKa7u2nLHGrLOE5DfB6A7YlPTalEVgbAx8oDyIDnQ==',
|
341
|
+
'Date' => 'Tue, 08 Jan 2019 20:17:41 GMT',
|
342
|
+
'Transfer-Encoding' => 'chunked',
|
343
|
+
'Connection' => 'keep-alive' }
|
344
|
+
)
|
345
|
+
|
346
|
+
result = graph.get_object('', fields: 'og_object{title,description,image}', id: 'https://fox2now.com/2018/04/02/5-myths-about-organ-donation/')
|
347
|
+
|
348
|
+
expect(result.dig('og_object')['title']).to eq '5 myths about organ donation'
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_fb_marketing_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Menne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: capybara_discoball
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -237,9 +237,11 @@ files:
|
|
237
237
|
- lib/fake_fb_marketing_api/version.rb
|
238
238
|
- lib/fake_fb_marketing_api/versions/v3_0.rb
|
239
239
|
- lib/fake_fb_marketing_api/versions/v3_2.rb
|
240
|
+
- lib/fake_fb_marketing_api/versions/v3_3.rb
|
240
241
|
- spec/.fake_fb_marketing_api_spec.rb.swo
|
241
242
|
- spec/.fake_fb_marketing_api_spec.rb.swp
|
242
|
-
- spec/
|
243
|
+
- spec/fake_fb_marketing_api_V3_2_spec.rb
|
244
|
+
- spec/fake_fb_marketing_api_v3_3_spec.rb
|
243
245
|
- spec/fb_batch_error_response.json
|
244
246
|
- spec/fb_batch_response.json
|
245
247
|
- spec/fb_graph_object_response.json
|