-
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
Conversation
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) | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Metrics/LineLength: Line is too long. [111/80]
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [121/80]
end | ||
|
||
let(:authorizer_double) { double("token_fetcher") } | ||
let(:json_key_path) { double("file alike object") } |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
) | ||
end | ||
|
||
let(:authorizer_double) { double("token_fetcher") } |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
# ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream | ||
body: "{}", | ||
headers: {}, | ||
status: 200, |
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.
Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call.
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 comment
The 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", | ||
"Authorization" => "Bearer #{access_token}", |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
let(:access_token) { "access_token" } | ||
let(:valid_request_v1_headers) do | ||
{ | ||
"Content-Type" => "application/json", |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
pending "should send message" | ||
let(:project_name) { "project_name" } | ||
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 comment
The 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.
@@ -24,7 +24,75 @@ | |||
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 comment
The 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.
extra_headers = { | ||
'Authorization' => "Bearer #{jwt_token}" | ||
} | ||
for_uri(BASE_URI_V1, extra_headers) do |connection| |
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! 🙇
Just add a few refactoring code, mainly for
#send_v1
methodadd rspec test for #send_v1 method
refactor #send_v1 method
#for_uri(BASE_URI_V1, extra_headers) do end
private methoddelete unused var / constant / comment
delete
attr_accessor :timeout, :api_key, :json_key_path, :project_base_uri