chore: Add climate-control gem for handling the test ENV vars (#3267)

This commit is contained in:
Akhil G Krishnan
2021-10-25 13:13:25 +05:30
committed by GitHub
parent 06289b03ea
commit 84df9c807d
8 changed files with 85 additions and 81 deletions

View File

@@ -14,26 +14,23 @@ describe Notification::PushNotificationService do
describe '#perform' do
it 'sends webpush notifications for webpush subscription' do
ENV['VAPID_PUBLIC_KEY'] = 'test'
create(:notification_subscription, user: notification.user)
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)
ENV['VAPID_PUBLIC_KEY'] = nil
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
ENV['FCM_SERVER_KEY'] = 'test'
ENV['ENABLE_PUSH_RELAY_SERVER'] = 'false'
create(:notification_subscription, user: notification.user, subscription_type: 'fcm')
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)
ENV['FCM_SERVER_KEY'] = nil
ENV['ENABLE_PUSH_RELAY_SERVER'] = nil
described_class.new(notification: notification).perform
expect(FCM).to have_received(:new)
expect(Webpush).not_to have_received(:payload_send)
end
end
end
end