fcm 0.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/fcm_spec.rb CHANGED
@@ -1,12 +1,12 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe FCM do
4
4
  let(:send_url) { "#{FCM::BASE_URI}/fcm/send" }
5
5
  let(:group_notification_base_uri) { "#{FCM::GROUP_NOTIFICATION_BASE_URI}/gcm/notification" }
6
- let(:api_key) { 'AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA' }
7
- let(:registration_id) { '42' }
8
- let(:registration_ids) { ['42'] }
9
- let(:key_name) { 'appUser-Chris' }
6
+ let(:api_key) { "AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA" }
7
+ let(:registration_id) { "42" }
8
+ let(:registration_ids) { ["42"] }
9
+ let(:key_name) { "appUser-Chris" }
10
10
  let(:project_id) { "123456789" } # https://developers.google.com/cloud-messaging/gcm#senderid
11
11
  let(:notification_key) { "APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ" }
12
12
  let(:valid_topic) { "TopicA" }
@@ -15,15 +15,19 @@ describe FCM do
15
15
  let(:invalid_condition) { "'TopicA' in topics and some other text ('TopicB' in topics || 'TopicC' in topics)" }
16
16
  let(:invalid_condition_topic) { "'TopicA$' in topics" }
17
17
 
18
- it 'should raise an error if the api key is not provided' do
18
+ it "should raise an error if the api key is not provided" do
19
19
  expect { FCM.new }.to raise_error(ArgumentError)
20
20
  end
21
21
 
22
- it 'should raise error if time_to_live is given' do
22
+ it "should raise error if time_to_live is given" do
23
23
  # ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#ttl
24
24
  end
25
25
 
26
- describe 'sending notification' do
26
+ describe "#send_v1" do
27
+ pending "should send message"
28
+ end
29
+
30
+ describe "sending notification" do
27
31
  let(:valid_request_body) do
28
32
  { registration_ids: registration_ids }
29
33
  end
@@ -32,39 +36,39 @@ describe FCM do
32
36
  end
33
37
  let(:valid_request_headers) do
34
38
  {
35
- 'Content-Type' => 'application/json',
36
- 'Authorization' => "key=#{api_key}"
39
+ "Content-Type" => "application/json",
40
+ "Authorization" => "key=#{api_key}",
37
41
  }
38
42
  end
39
43
 
40
44
  let(:stub_fcm_send_request) do
41
45
  stub_request(:post, send_url).with(
42
46
  body: valid_request_body.to_json,
43
- headers: valid_request_headers
47
+ headers: valid_request_headers,
44
48
  ).to_return(
45
49
  # ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream
46
- body: '{}',
50
+ body: "{}",
47
51
  headers: {},
48
- status: 200
52
+ status: 200,
49
53
  )
50
54
  end
51
55
 
52
56
  let(:stub_fcm_send_request_with_string) do
53
57
  stub_request(:post, send_url).with(
54
58
  body: valid_request_body_with_string.to_json,
55
- headers: valid_request_headers
59
+ headers: valid_request_headers,
56
60
  ).to_return(
57
- body: '{}',
61
+ body: "{}",
58
62
  headers: {},
59
- status: 200
63
+ status: 200,
60
64
  )
61
65
  end
62
66
 
63
67
  let(:stub_fcm_send_request_with_basic_auth) do
64
68
  uri = URI.parse(send_url)
65
- uri.user = 'a'
66
- uri.password = 'b'
67
- stub_request(:post, uri.to_s).to_return(body: '{}', headers: {}, status: 200)
69
+ uri.user = "a"
70
+ uri.password = "b"
71
+ stub_request(:post, uri.to_s).to_return(body: "{}", headers: {}, status: 200)
68
72
  end
69
73
 
70
74
  before(:each) do
@@ -73,30 +77,30 @@ describe FCM do
73
77
  stub_fcm_send_request_with_basic_auth
74
78
  end
75
79
 
76
- it 'should send notification using POST to FCM server' do
80
+ it "should send notification using POST to FCM server" do
77
81
  fcm = FCM.new(api_key)
78
- fcm.send(registration_ids).should eq(response: 'success', body: '{}', headers: {}, status_code: 200, canonical_ids: [], not_registered_ids: [])
82
+ fcm.send(registration_ids).should eq(response: "success", body: "{}", headers: {}, status_code: 200, canonical_ids: [], not_registered_ids: [])
79
83
  stub_fcm_send_request.should have_been_made.times(1)
80
84
  end
81
85
 
82
- it 'should send notification using POST to FCM if id provided as string' do
86
+ it "should send notification using POST to FCM if id provided as string" do
83
87
  fcm = FCM.new(api_key)
84
- fcm.send(registration_id).should eq(response: 'success', body: '{}', headers: {}, status_code: 200, canonical_ids: [], not_registered_ids: [])
88
+ fcm.send(registration_id).should eq(response: "success", body: "{}", headers: {}, status_code: 200, canonical_ids: [], not_registered_ids: [])
85
89
  stub_fcm_send_request.should have_been_made.times(1)
86
90
  end
87
91
 
88
- context 'send notification with data' do
92
+ context "send notification with data" do
89
93
  let!(:stub_with_data) do
90
94
  stub_request(:post, send_url)
91
95
  .with(body: '{"registration_ids":["42"],"data":{"score":"5x1","time":"15:10"}}',
92
96
  headers: valid_request_headers)
93
- .to_return(status: 200, body: '', headers: {})
97
+ .to_return(status: 200, body: "", headers: {})
94
98
  end
95
99
  before do
96
100
  end
97
- it 'should send the data in a post request to fcm' do
101
+ it "should send the data in a post request to fcm" do
98
102
  fcm = FCM.new(api_key)
99
- fcm.send(registration_ids, data: { score: '5x1', time: '15:10' })
103
+ fcm.send(registration_ids, data: { score: "5x1", time: "15:10" })
100
104
  stub_with_data.should have_been_requested
101
105
  end
102
106
  end
@@ -106,25 +110,25 @@ describe FCM do
106
110
  stub_request(:post, send_url)
107
111
  .with(body: '{"to":"/topics/TopicA","data":{"score":"5x1","time":"15:10"}}',
108
112
  headers: valid_request_headers)
109
- .to_return(status: 200, body: '', headers: {})
113
+ .to_return(status: 200, body: "", headers: {})
110
114
  end
111
115
  let!(:stub_with_invalid_topic) do
112
116
  stub_request(:post, send_url)
113
117
  .with(body: '{"condition":"/topics/TopicA$","data":{"score":"5x1","time":"15:10"}}',
114
118
  headers: valid_request_headers)
115
- .to_return(status: 200, body: '', headers: {})
119
+ .to_return(status: 200, body: "", headers: {})
116
120
  end
117
121
 
118
122
  describe "#send_to_topic" do
119
- it 'should send the data in a post request to fcm' do
123
+ it "should send the data in a post request to fcm" do
120
124
  fcm = FCM.new(api_key)
121
- fcm.send_to_topic(valid_topic, data: { score: '5x1', time: '15:10' })
125
+ fcm.send_to_topic(valid_topic, data: { score: "5x1", time: "15:10" })
122
126
  stub_with_valid_topic.should have_been_requested
123
127
  end
124
128
 
125
- it 'should not send to invalid topics' do
129
+ it "should not send to invalid topics" do
126
130
  fcm = FCM.new(api_key)
127
- fcm.send_to_topic(invalid_topic, data: { score: '5x1', time: '15:10' })
131
+ fcm.send_to_topic(invalid_topic, data: { score: "5x1", time: "15:10" })
128
132
  stub_with_invalid_topic.should_not have_been_requested
129
133
  end
130
134
  end
@@ -135,143 +139,143 @@ describe FCM do
135
139
  stub_request(:post, send_url)
136
140
  .with(body: '{"condition":"\'TopicA\' in topics && (\'TopicB\' in topics || \'TopicC\' in topics)","data":{"score":"5x1","time":"15:10"}}',
137
141
  headers: valid_request_headers)
138
- .to_return(status: 200, body: '', headers: {})
142
+ .to_return(status: 200, body: "", headers: {})
139
143
  end
140
144
  let!(:stub_with_invalid_condition) do
141
145
  stub_request(:post, send_url)
142
146
  .with(body: '{"condition":"\'TopicA\' in topics and some other text (\'TopicB\' in topics || \'TopicC\' in topics)","data":{"score":"5x1","time":"15:10"}}',
143
147
  headers: valid_request_headers)
144
- .to_return(status: 200, body: '', headers: {})
148
+ .to_return(status: 200, body: "", headers: {})
145
149
  end
146
150
  let!(:stub_with_invalid_condition_topic) do
147
151
  stub_request(:post, send_url)
148
152
  .with(body: '{"condition":"\'TopicA$\' in topics","data":{"score":"5x1","time":"15:10"}}',
149
153
  headers: valid_request_headers)
150
- .to_return(status: 200, body: '', headers: {})
154
+ .to_return(status: 200, body: "", headers: {})
151
155
  end
152
156
 
153
157
  describe "#send_to_topic_condition" do
154
- it 'should send the data in a post request to fcm' do
158
+ it "should send the data in a post request to fcm" do
155
159
  fcm = FCM.new(api_key)
156
- fcm.send_to_topic_condition(valid_condition, data: { score: '5x1', time: '15:10' })
160
+ fcm.send_to_topic_condition(valid_condition, data: { score: "5x1", time: "15:10" })
157
161
  stub_with_valid_condition.should have_been_requested
158
162
  end
159
163
 
160
- it 'should not send to invalid conditions' do
164
+ it "should not send to invalid conditions" do
161
165
  fcm = FCM.new(api_key)
162
- fcm.send_to_topic_condition(invalid_condition, data: { score: '5x1', time: '15:10' })
166
+ fcm.send_to_topic_condition(invalid_condition, data: { score: "5x1", time: "15:10" })
163
167
  stub_with_invalid_condition.should_not have_been_requested
164
168
  end
165
169
 
166
- it 'should not send to invalid topics in a condition' do
170
+ it "should not send to invalid topics in a condition" do
167
171
  fcm = FCM.new(api_key)
168
- fcm.send_to_topic_condition(invalid_condition_topic, data: { score: '5x1', time: '15:10' })
172
+ fcm.send_to_topic_condition(invalid_condition_topic, data: { score: "5x1", time: "15:10" })
169
173
  stub_with_invalid_condition_topic.should_not have_been_requested
170
174
  end
171
175
  end
172
176
  end
173
177
 
174
- context 'when send_notification responds with failure' do
178
+ context "when send_notification responds with failure" do
175
179
  let(:mock_request_attributes) do
176
180
  {
177
181
  body: valid_request_body.to_json,
178
- headers: valid_request_headers
182
+ headers: valid_request_headers,
179
183
  }
180
184
  end
181
185
 
182
186
  subject { FCM.new(api_key) }
183
187
 
184
- context 'on failure code 400' do
188
+ context "on failure code 400" do
185
189
  before do
186
190
  stub_request(:post, send_url).with(
187
191
  mock_request_attributes
188
192
  ).to_return(
189
193
  # ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream
190
- body: '{}',
194
+ body: "{}",
191
195
  headers: {},
192
- status: 400
196
+ status: 400,
193
197
  )
194
198
  end
195
- it 'should not send notification due to 400' do
196
- subject.send(registration_ids).should eq(body: '{}',
199
+ it "should not send notification due to 400" do
200
+ subject.send(registration_ids).should eq(body: "{}",
197
201
  headers: {},
198
- response: 'Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields.',
202
+ response: "Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields.",
199
203
  status_code: 400)
200
204
  end
201
205
  end
202
206
 
203
- context 'on failure code 401' do
207
+ context "on failure code 401" do
204
208
  before do
205
209
  stub_request(:post, send_url).with(
206
210
  mock_request_attributes
207
211
  ).to_return(
208
212
  # ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream
209
- body: '{}',
213
+ body: "{}",
210
214
  headers: {},
211
- status: 401
215
+ status: 401,
212
216
  )
213
217
  end
214
218
 
215
- it 'should not send notification due to 401' do
216
- subject.send(registration_ids).should eq(body: '{}',
219
+ it "should not send notification due to 401" do
220
+ subject.send(registration_ids).should eq(body: "{}",
217
221
  headers: {},
218
- response: 'There was an error authenticating the sender account.',
222
+ response: "There was an error authenticating the sender account.",
219
223
  status_code: 401)
220
224
  end
221
225
  end
222
226
 
223
- context 'on failure code 503' do
227
+ context "on failure code 503" do
224
228
  before do
225
229
  stub_request(:post, send_url).with(
226
230
  mock_request_attributes
227
231
  ).to_return(
228
232
  # ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream
229
- body: '{}',
233
+ body: "{}",
230
234
  headers: {},
231
- status: 503
235
+ status: 503,
232
236
  )
233
237
  end
234
238
 
235
- it 'should not send notification due to 503' do
236
- subject.send(registration_ids).should eq(body: '{}',
239
+ it "should not send notification due to 503" do
240
+ subject.send(registration_ids).should eq(body: "{}",
237
241
  headers: {},
238
- response: 'Server is temporarily unavailable.',
242
+ response: "Server is temporarily unavailable.",
239
243
  status_code: 503)
240
244
  end
241
245
  end
242
246
 
243
- context 'on failure code 5xx' do
247
+ context "on failure code 5xx" do
244
248
  before do
245
249
  stub_request(:post, send_url).with(
246
250
  mock_request_attributes
247
251
  ).to_return(
248
252
  # ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream
249
253
  body: '{"body-key" => "Body value"}',
250
- headers: { 'header-key' => 'Header value' },
251
- status: 599
254
+ headers: { "header-key" => "Header value" },
255
+ status: 599,
252
256
  )
253
257
  end
254
258
 
255
- it 'should not send notification due to 599' do
259
+ it "should not send notification due to 599" do
256
260
  subject.send(registration_ids).should eq(body: '{"body-key" => "Body value"}',
257
- headers: { 'header-key' => 'Header value' },
258
- response: 'There was an internal error in the FCM server while trying to process the request.',
261
+ headers: { "header-key" => "Header value" },
262
+ response: "There was an internal error in the FCM server while trying to process the request.",
259
263
  status_code: 599)
260
264
  end
261
265
  end
262
266
  end
263
267
 
264
- context 'when send_notification responds canonical_ids' do
268
+ context "when send_notification responds canonical_ids" do
265
269
  let(:mock_request_attributes) do
266
270
  {
267
271
  body: valid_request_body.to_json,
268
- headers: valid_request_headers
272
+ headers: valid_request_headers,
269
273
  }
270
274
  end
271
275
 
272
276
  let(:valid_response_body_with_canonical_ids) do
273
277
  {
274
- failure: 0, canonical_ids: 1, results: [{ registration_id: '43', message_id: '0:1385025861956342%572c22801bb3' }]
278
+ failure: 0, canonical_ids: 1, results: [{ registration_id: "43", message_id: "0:1385025861956342%572c22801bb3" }],
275
279
  }
276
280
  end
277
281
 
@@ -284,35 +288,35 @@ describe FCM do
284
288
  # ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream
285
289
  body: valid_response_body_with_canonical_ids.to_json,
286
290
  headers: {},
287
- status: 200
291
+ status: 200,
288
292
  )
289
293
  end
290
294
 
291
- it 'should contain canonical_ids' do
295
+ it "should contain canonical_ids" do
292
296
  response = subject.send(registration_ids)
293
297
 
294
298
  response.should eq(headers: {},
295
- canonical_ids: [{ old: '42', new: '43' }],
299
+ canonical_ids: [{ old: "42", new: "43" }],
296
300
  not_registered_ids: [],
297
301
  status_code: 200,
298
- response: 'success',
302
+ response: "success",
299
303
  body: '{"failure":0,"canonical_ids":1,"results":[{"registration_id":"43","message_id":"0:1385025861956342%572c22801bb3"}]}')
300
304
  end
301
305
  end
302
306
 
303
- context 'when send_notification responds with NotRegistered' do
307
+ context "when send_notification responds with NotRegistered" do
304
308
  subject { FCM.new(api_key) }
305
309
 
306
310
  let(:mock_request_attributes) do
307
311
  {
308
312
  body: valid_request_body.to_json,
309
- headers: valid_request_headers
313
+ headers: valid_request_headers,
310
314
  }
311
315
  end
312
316
 
313
317
  let(:valid_response_body_with_not_registered_ids) do
314
318
  {
315
- canonical_ids: 0, failure: 1, results: [{ error: 'NotRegistered' }]
319
+ canonical_ids: 0, failure: 1, results: [{ error: "NotRegistered" }],
316
320
  }
317
321
  end
318
322
 
@@ -322,31 +326,31 @@ describe FCM do
322
326
  ).to_return(
323
327
  body: valid_response_body_with_not_registered_ids.to_json,
324
328
  headers: {},
325
- status: 200
329
+ status: 200,
326
330
  )
327
331
  end
328
332
 
329
- it 'should contain not_registered_ids' do
333
+ it "should contain not_registered_ids" do
330
334
  response = subject.send(registration_ids)
331
335
  response.should eq(
332
336
  headers: {},
333
337
  canonical_ids: [],
334
338
  not_registered_ids: registration_ids,
335
339
  status_code: 200,
336
- response: 'success',
337
- body: '{"canonical_ids":0,"failure":1,"results":[{"error":"NotRegistered"}]}'
340
+ response: "success",
341
+ body: '{"canonical_ids":0,"failure":1,"results":[{"error":"NotRegistered"}]}',
338
342
  )
339
343
  end
340
344
  end
341
345
  end
342
346
 
343
- describe 'sending group notifications' do
347
+ describe "sending group notifications" do
344
348
  # TODO: refactor to should_behave_like
345
349
  let(:valid_request_headers) do
346
350
  {
347
351
  "Authorization" => "key=#{api_key}",
348
- "Content-Type" => 'application/json',
349
- "Project-Id" => project_id
352
+ "Content-Type" => "application/json",
353
+ "Project-Id" => project_id,
350
354
  }
351
355
  end
352
356
  let(:valid_response_body) do
@@ -357,24 +361,24 @@ describe FCM do
357
361
  {
358
362
  registration_ids: registration_ids,
359
363
  operation: "create",
360
- notification_key_name: key_name
364
+ notification_key_name: key_name,
361
365
  }
362
366
  end
363
367
 
364
368
  subject { FCM.new(api_key) }
365
369
 
366
370
  # ref: https://firebase.google.com/docs/cloud-messaging/notifications#managing-device-groups-on-the-app-server
367
- context 'create' do
371
+ context "create" do
368
372
  let(:valid_request_body) do
369
373
  default_valid_request_body.merge({
370
- operation: "create"
374
+ operation: "create",
371
375
  })
372
376
  end
373
377
 
374
378
  let(:mock_request_attributes) do
375
379
  {
376
380
  body: valid_request_body.to_json,
377
- headers: valid_request_headers
381
+ headers: valid_request_headers,
378
382
  }
379
383
  end
380
384
 
@@ -384,33 +388,33 @@ describe FCM do
384
388
  ).to_return(
385
389
  body: valid_response_body.to_json,
386
390
  headers: {},
387
- status: 200
391
+ status: 200,
388
392
  )
389
393
  end
390
394
 
391
- it 'should send a post request' do
395
+ it "should send a post request" do
392
396
  response = subject.create(key_name, project_id, registration_ids)
393
397
  response.should eq(
394
398
  headers: {},
395
399
  status_code: 200,
396
- response: 'success',
397
- body: valid_response_body.to_json
400
+ response: "success",
401
+ body: valid_response_body.to_json,
398
402
  )
399
403
  end
400
404
  end # create context
401
405
 
402
- context 'add' do
406
+ context "add" do
403
407
  let(:valid_request_body) do
404
408
  default_valid_request_body.merge({
405
409
  operation: "add",
406
- notification_key: notification_key
410
+ notification_key: notification_key,
407
411
  })
408
412
  end
409
413
 
410
414
  let(:mock_request_attributes) do
411
415
  {
412
416
  body: valid_request_body.to_json,
413
- headers: valid_request_headers
417
+ headers: valid_request_headers,
414
418
  }
415
419
  end
416
420
 
@@ -420,33 +424,33 @@ describe FCM do
420
424
  ).to_return(
421
425
  body: valid_response_body.to_json,
422
426
  headers: {},
423
- status: 200
427
+ status: 200,
424
428
  )
425
429
  end
426
430
 
427
- it 'should send a post request' do
431
+ it "should send a post request" do
428
432
  response = subject.add(key_name, project_id, notification_key, registration_ids)
429
433
  response.should eq(
430
434
  headers: {},
431
435
  status_code: 200,
432
- response: 'success',
433
- body: valid_response_body.to_json
436
+ response: "success",
437
+ body: valid_response_body.to_json,
434
438
  )
435
439
  end
436
440
  end # add context
437
441
 
438
- context 'remove' do
442
+ context "remove" do
439
443
  let(:valid_request_body) do
440
444
  default_valid_request_body.merge({
441
445
  operation: "remove",
442
- notification_key: notification_key
446
+ notification_key: notification_key,
443
447
  })
444
448
  end
445
449
 
446
450
  let(:mock_request_attributes) do
447
451
  {
448
452
  body: valid_request_body.to_json,
449
- headers: valid_request_headers
453
+ headers: valid_request_headers,
450
454
  }
451
455
  end
452
456
 
@@ -456,23 +460,88 @@ describe FCM do
456
460
  ).to_return(
457
461
  body: valid_response_body.to_json,
458
462
  headers: {},
459
- status: 200
463
+ status: 200,
460
464
  )
461
465
  end
462
466
 
463
- it 'should send a post request' do
467
+ it "should send a post request" do
464
468
  response = subject.remove(key_name, project_id, notification_key, registration_ids)
465
469
  response.should eq(
466
470
  headers: {},
467
471
  status_code: 200,
468
- response: 'success',
469
- body: valid_response_body.to_json
472
+ response: "success",
473
+ body: valid_response_body.to_json,
470
474
  )
471
475
  end
472
476
  end # remove context
473
477
  end
474
478
 
475
- describe 'subscribing to a topic' do
479
+ describe "#recover_notification_key" do
480
+ it "sends a 'retrieve notification key' request" do
481
+ uri = "#{FCM::GROUP_NOTIFICATION_BASE_URI}/gcm/notification"
482
+ endpoint = stub_request(:get, uri).with(
483
+ headers: {
484
+ "Content-Type" => "application/json",
485
+ "Authorization" => "key=TEST_SERVER_KEY",
486
+ "project_id" => "TEST_PROJECT_ID",
487
+ },
488
+ query: { notification_key_name: "TEST_KEY_NAME" },
489
+ )
490
+ client = FCM.new("TEST_SERVER_KEY")
491
+
492
+ client.recover_notification_key("TEST_KEY_NAME", "TEST_PROJECT_ID")
493
+
494
+ expect(endpoint).to have_been_requested
495
+ end
496
+ end
497
+
498
+ describe "subscribing to a topic" do
476
499
  # TODO
477
500
  end
501
+
502
+ describe 'getting instance info' do
503
+ subject(:get_info) { client.get_instance_id_info(registration_id, options) }
504
+
505
+ let(:options) { nil }
506
+ let(:client) { FCM.new('TEST_SERVER_KEY') }
507
+ let(:base_uri) { "#{FCM::INSTANCE_ID_API}/iid/info" }
508
+ let(:uri) { "#{base_uri}/#{registration_id}" }
509
+ let(:mock_request_attributes) do
510
+ { headers: {
511
+ 'Authorization' => 'key=TEST_SERVER_KEY',
512
+ 'Content-Type' => 'application/json'
513
+ } }
514
+ end
515
+
516
+ context 'without options' do
517
+ it 'calls info endpoint' do
518
+ endpoint = stub_request(:get, uri).with(mock_request_attributes)
519
+ get_info
520
+ expect(endpoint).to have_been_requested
521
+ end
522
+ end
523
+
524
+ context 'with detail option' do
525
+ let(:uri) { "#{base_uri}/#{registration_id}?details=true" }
526
+ let(:options) { { details: true } }
527
+
528
+ it 'calls info endpoint' do
529
+ endpoint = stub_request(:get, uri).with(mock_request_attributes)
530
+ get_info
531
+ expect(endpoint).to have_been_requested
532
+ end
533
+ end
534
+ end
535
+
536
+ describe "credentials path" do
537
+ it "can be a path to a file" do
538
+ fcm = FCM.new("test", "README.md")
539
+ expect(fcm.__send__(:json_key).class).to eq(File)
540
+ end
541
+
542
+ it "can be an IO object" do
543
+ fcm = FCM.new("test", StringIO.new("hey"))
544
+ expect(fcm.__send__(:json_key).class).to eq(StringIO)
545
+ end
546
+ end
478
547
  end