Files
chatwoot/spec/services/notification/push_notification_service_spec.rb
Sojan Jose 38aee8d9ea chore: Switch to web-push gem (#6390)
- The previous gem, `webpush` was last updated a while ago. Also, with the recent ruby upgrade, we needed a fix for zaru/webpush#106. Hence switching to the `web-push` gem where the issues are fixed.
2023-02-03 18:55:22 +05:30

37 lines
1.3 KiB
Ruby

require 'rails_helper'
describe Notification::PushNotificationService do
let!(:account) { create(:account) }
let!(:user) { create(:user, account: account) }
let!(:notification) { create(:notification, user: user, account: user.accounts.first) }
let(:fcm_double) { double }
before do
allow(WebPush).to receive(:payload_send).and_return(true)
allow(FCM).to receive(:new).and_return(fcm_double)
allow(fcm_double).to receive(:send).and_return({ body: { 'results': [] }.to_json })
end
describe '#perform' do
it 'sends webpush notifications for webpush subscription' do
with_modified_env VAPID_PUBLIC_KEY: 'test' do
create(:notification_subscription, user: notification.user)
described_class.new(notification: notification).perform
expect(WebPush).to have_received(:payload_send)
expect(FCM).not_to have_received(:new)
end
end
it 'sends a fcm notification for firebase subscription' do
with_modified_env FCM_SERVER_KEY: 'test', ENABLE_PUSH_RELAY_SERVER: 'false' do
create(:notification_subscription, user: notification.user, subscription_type: 'fcm')
described_class.new(notification: notification).perform
expect(FCM).to have_received(:new)
expect(WebPush).not_to have_received(:payload_send)
end
end
end
end