Skip to content

Commit 8fb5f27

Browse files
committed
Add spec for web push controller
1 parent 465c4e8 commit 8fb5f27

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

spec/requests/pwa/web_pushes_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require "rails_helper"
2+
3+
RSpec.describe "/pwa/web_pushes", type: :request do
4+
describe "POST" do
5+
before do
6+
allow(WebPush).to receive(:payload_send)
7+
end
8+
9+
it "creates a new web push subscription" do
10+
title = "Hello"
11+
message = "World"
12+
subscription = {
13+
endpoint: "https://fcm.googleapis.com/fcm/send/KEY",
14+
keys: {
15+
p256dh: SecureRandom.base64(16),
16+
auth: SecureRandom.base64(8)
17+
}
18+
}
19+
20+
post pwa_web_pushes_path, params: {web_push: {title:, message:, subscription: subscription.to_json}}
21+
perform_enqueued_jobs
22+
23+
message_json = {
24+
title: title,
25+
body: message,
26+
icon: "/icon-192.png"
27+
}.to_json
28+
expect(WebPush).to have_received(:payload_send).with(hash_including(
29+
message: message_json,
30+
endpoint: subscription[:endpoint],
31+
p256dh: subscription.dig(:keys, :p256dh),
32+
auth: subscription.dig(:keys, :auth),
33+
vapid: {
34+
subject: Rails.application.credentials.vapid.subject,
35+
public_key: Rails.application.credentials.vapid.public_key,
36+
private_key: Rails.application.credentials.vapid.private_key
37+
},
38+
ssl_timeout: kind_of(Integer),
39+
open_timeout: kind_of(Integer),
40+
read_timeout: kind_of(Integer)
41+
))
42+
end
43+
end
44+
end

0 commit comments

Comments
 (0)