From 5c7277a942b21befffaf32f3329a8940815d5911 Mon Sep 17 00:00:00 2001 From: Jake Sparling Date: Sat, 19 Feb 2022 16:57:21 -0700 Subject: [PATCH 1/3] Fix issue with instance_info endpoint params --- lib/fcm.rb | 4 +--- spec/fcm_spec.rb | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/fcm.rb b/lib/fcm.rb index f3ad0b8..b4e8854 100644 --- a/lib/fcm.rb +++ b/lib/fcm.rb @@ -188,9 +188,7 @@ def send_to_topic(topic, options = {}) end def get_instance_id_info(iid_token, options = {}) - params = { - query: options, - } + params = options for_uri(INSTANCE_ID_API) do |connection| response = connection.get("/iid/info/" + iid_token, params) diff --git a/spec/fcm_spec.rb b/spec/fcm_spec.rb index 0d1afd1..767235c 100644 --- a/spec/fcm_spec.rb +++ b/spec/fcm_spec.rb @@ -499,6 +499,43 @@ # TODO end + describe "getting instance info" do + subject(:get_instance_info) { client.get_instance_id_info(registration_id, options) } + + let(:options) { nil } + let(:client) { FCM.new("TEST_SERVER_KEY") } + let(:uri) { "#{FCM::INSTANCE_ID_API}/iid/info/#{registration_id}" } + let(:mock_request_attributes) { { + headers: { + 'Authorization' => 'key=TEST_SERVER_KEY', + 'Content-Type' => 'application/json' + } + } } + + context "without options" do + it "calls info endpoint" do + endpoint = stub_request(:get, uri).with(mock_request_attributes) + + get_instance_info + + expect(endpoint).to have_been_requested + end + end + + context "with detail option" do + let(:uri) { "#{FCM::INSTANCE_ID_API}/iid/info/#{registration_id}?details=true" } + let(:options) {{ details: true }} + + it "calls info endpoint" do + endpoint = stub_request(:get, uri).with(mock_request_attributes) + + get_instance_info + + expect(endpoint).to have_been_requested + end + end + end + describe "credentials path" do it "can be a path to a file" do fcm = FCM.new("test", "README.md") From 5bbe347d0441ccbaf6540f7c20aaec31881be7a3 Mon Sep 17 00:00:00 2001 From: Jake Sparling Date: Sat, 19 Feb 2022 17:16:48 -0700 Subject: [PATCH 2/3] formatting --- spec/fcm_spec.rb | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/spec/fcm_spec.rb b/spec/fcm_spec.rb index 767235c..eb844c9 100644 --- a/spec/fcm_spec.rb +++ b/spec/fcm_spec.rb @@ -499,38 +499,35 @@ # TODO end - describe "getting instance info" do - subject(:get_instance_info) { client.get_instance_id_info(registration_id, options) } + describe 'getting instance info' do + subject(:get_info) { client.get_instance_id_info(registration_id, options) } let(:options) { nil } let(:client) { FCM.new("TEST_SERVER_KEY") } - let(:uri) { "#{FCM::INSTANCE_ID_API}/iid/info/#{registration_id}" } - let(:mock_request_attributes) { { - headers: { - 'Authorization' => 'key=TEST_SERVER_KEY', - 'Content-Type' => 'application/json' - } - } } + let(:base_uri) { "#{FCM::INSTANCE_ID_API}/iid/info" } + let(:uri) { "#{base_uri}/#{registration_id}" } + let(:mock_request_attributes) do + { headers: { + 'Authorization' => 'key=TEST_SERVER_KEY', + 'Content-Type' => 'application/json' + } } + end - context "without options" do - it "calls info endpoint" do + context 'without options' do + it 'calls info endpoint' do endpoint = stub_request(:get, uri).with(mock_request_attributes) - - get_instance_info - + get_info expect(endpoint).to have_been_requested end end - context "with detail option" do - let(:uri) { "#{FCM::INSTANCE_ID_API}/iid/info/#{registration_id}?details=true" } - let(:options) {{ details: true }} + context 'with detail option' do + let(:uri) { "#{base_uri}/#{registration_id}?details=true" } + let(:options) { { details: true } } - it "calls info endpoint" do + it 'calls info endpoint' do endpoint = stub_request(:get, uri).with(mock_request_attributes) - - get_instance_info - + get_info expect(endpoint).to have_been_requested end end From 4db5a6020b93fd7a675978fbde873db1fe67af24 Mon Sep 17 00:00:00 2001 From: Jake Sparling Date: Sat, 19 Feb 2022 17:18:14 -0700 Subject: [PATCH 3/3] formatting --- spec/fcm_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/fcm_spec.rb b/spec/fcm_spec.rb index eb844c9..fb1ee9e 100644 --- a/spec/fcm_spec.rb +++ b/spec/fcm_spec.rb @@ -503,13 +503,13 @@ subject(:get_info) { client.get_instance_id_info(registration_id, options) } let(:options) { nil } - let(:client) { FCM.new("TEST_SERVER_KEY") } + let(:client) { FCM.new('TEST_SERVER_KEY') } let(:base_uri) { "#{FCM::INSTANCE_ID_API}/iid/info" } let(:uri) { "#{base_uri}/#{registration_id}" } let(:mock_request_attributes) do { headers: { - 'Authorization' => 'key=TEST_SERVER_KEY', - 'Content-Type' => 'application/json' + 'Authorization' => 'key=TEST_SERVER_KEY', + 'Content-Type' => 'application/json' } } end