Skip to content
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

Merged
merged 7 commits into from
Apr 28, 2022

Conversation

Roy-Mao
Copy link
Collaborator

@Roy-Mao Roy-Mao commented Apr 28, 2022

Just add a few refactoring code, mainly for #send_v1 method

  1. add rspec test for #send_v1 method

    • preparation for refactoring later
  2. refactor #send_v1 method

    • to use the shared #for_uri(BASE_URI_V1, extra_headers) do end private method
  3. delete unused var / constant / comment

  4. delete attr_accessor :timeout, :api_key, :json_key_path, :project_base_uri

    • better to encapsulate these attributes within the instance itself instead of being exposed to outside

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 })
Copy link

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)
Copy link

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") }
Copy link

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") }
Copy link

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,
Copy link

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: "{}",
Copy link

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}",
Copy link

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",
Copy link

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" }
Copy link

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" }
Copy link

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|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! 🙇

@sabman sabman merged commit 07941b3 into decision-labs:master Apr 28, 2022
@Roy-Mao Roy-Mao deleted the refactor_branch branch May 11, 2022 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants