-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A refactoring PR of send_v1 method #104
Changes from 6 commits
aca1ee8
67bcec1
3240bda
f217a4c
1b173fa
0baceca
c1bda3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,73 @@ | |
end | ||
|
||
describe "#send_v1" do | ||
pending "should send message" | ||
let(:project_name) { "project_name" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
let(:send_v1_url) { "#{FCM::BASE_URI_V1}#{project_name}/messages:send" } | ||
let(:access_token) { "access_token" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
let(:valid_request_v1_headers) do | ||
{ | ||
"Content-Type" => "application/json", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
"Authorization" => "Bearer #{access_token}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
} | ||
end | ||
|
||
let(:send_v1_params) do | ||
{ | ||
"token" => "4sdsx", | ||
"notification" => { | ||
"title" => "Breaking News", | ||
"body" => "New news story available." | ||
}, | ||
"data" => { | ||
"story_id" => "story_12345" | ||
}, | ||
"android" => { | ||
"notification" => { | ||
"click_action": "TOP_STORY_ACTIVITY", | ||
"body" => "Check out the Top Story" | ||
} | ||
}, | ||
"apns" => { | ||
"payload" => { | ||
"aps" => { | ||
"category" => "NEW_MESSAGE_CATEGORY" | ||
} | ||
} | ||
} | ||
} | ||
end | ||
|
||
let(:valid_request_v1_body) do | ||
{ "message" => send_v1_params } | ||
end | ||
|
||
let(:stub_fcm_send_v1_request) do | ||
stub_request(:post, send_v1_url).with( | ||
body: valid_request_v1_body.to_json, | ||
headers: valid_request_v1_headers, | ||
).to_return( | ||
# ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream | ||
body: "{}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
headers: {}, | ||
status: 200, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call. |
||
) | ||
end | ||
|
||
let(:authorizer_double) { double("token_fetcher") } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
let(:json_key_path) { double("file alike object") } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
|
||
before do | ||
expect(json_key_path).to receive(:respond_to?).and_return(true) | ||
expect(Google::Auth::ServiceAccountCredentials).to receive_message_chain(:make_creds).and_return(authorizer_double) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [121/80] |
||
expect(authorizer_double).to receive(:fetch_access_token!).and_return({ "access_token" => access_token }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter. |
||
stub_fcm_send_v1_request | ||
end | ||
|
||
it "should send notification of HTTP V1 using POST to FCM server" do | ||
fcm = FCM.new(api_key, json_key_path, project_name) | ||
fcm.send_v1(send_v1_params).should eq(response: "success", body: "{}", headers: {}, status_code: 200) | ||
stub_fcm_send_v1_request.should have_been_made.times(1) | ||
end | ||
end | ||
|
||
describe "sending notification" do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! 🙇