Chore: Firebase Cloud Messaging Support (#858)

This commit is contained in:
Sojan Jose
2020-06-05 00:15:50 +05:30
committed by GitHub
parent e783c3af5d
commit a13a474c23
7 changed files with 59 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
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
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
it 'sends a fcm notification for firebase subscription' 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