Skip to content

Commit

Permalink
follow hound rule: prefer single-quoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy-Mao committed Apr 28, 2022
1 parent 0baceca commit c1bda3d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
8 changes: 5 additions & 3 deletions lib/fcm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ def send_notification_v1(message)

post_body = { 'message': message }
extra_headers = {
"Authorization" => "Bearer #{jwt_token}"
'Authorization' => "Bearer #{jwt_token}"
}
for_uri(BASE_URI_V1, extra_headers) do |connection|
response = connection.post("#{@project_name}/messages:send", post_body.to_json)
response = connection.post(
"#{@project_name}/messages:send", post_body.to_json
)
build_response(response)
end
end
Expand Down Expand Up @@ -224,7 +226,7 @@ def for_uri(uri, extra_headers = {})
) do |faraday|
faraday.adapter Faraday.default_adapter
faraday.headers["Content-Type"] = "application/json"
faraday.headers["Authorization"] = "key=#{@api_key}"
faraday.headers['Authorization'] = "key=#{@api_key}"
extra_headers.each do |key, value|
faraday.headers[key] = value
end
Expand Down
38 changes: 20 additions & 18 deletions spec/fcm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,38 @@

let(:send_v1_params) do
{
"token" => "4sdsx",
"notification" => {
"title" => "Breaking News",
"body" => "New news story available."
'token' => '4sdsx',
'notification' => {
'title' => 'Breaking News',
'body' => 'New news story available.'
},
"data" => {
"story_id" => "story_12345"
'data' => {
'story_id' => 'story_12345'
},
"android" => {
"notification" => {
"click_action": "TOP_STORY_ACTIVITY",
"body" => "Check out the Top Story"
'android' => {
'notification' => {
'click_action' => 'TOP_STORY_ACTIVITY',
'body' => 'Check out the Top Story'
}
},
"apns" => {
"payload" => {
"aps" => {
"category" => "NEW_MESSAGE_CATEGORY"
'apns' => {
'payload' => {
'aps' => {
'category' => 'NEW_MESSAGE_CATEGORY'
}
}
}
}
end

let(:valid_request_v1_body) do
{ "message" => send_v1_params }
{ '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,
headers: valid_request_v1_headers
).to_return(
# ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream
body: "{}",
Expand All @@ -86,9 +86,11 @@
stub_fcm_send_v1_request
end

it "should send notification of HTTP V1 using POST to FCM server" do
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)
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
Expand Down

0 comments on commit c1bda3d

Please sign in to comment.