[verified] Remove Chatwoot Hub push relay
This commit is contained in:
@@ -30,19 +30,35 @@ describe Notification::PushNotificationService do
|
||||
end
|
||||
|
||||
it 'sends a fcm notification for firebase subscription' do
|
||||
with_modified_env ENABLE_PUSH_RELAY_SERVER: 'false' do
|
||||
create(:notification_subscription, user: notification.user, subscription_type: 'fcm')
|
||||
create(:notification_subscription, user: notification.user, subscription_type: 'fcm')
|
||||
|
||||
described_class.new(notification: notification).perform
|
||||
expect(Notification::FcmService).to have_received(:new)
|
||||
expect(fcm_double).to have_received(:send_v1)
|
||||
expect(WebPush).not_to have_received(:payload_send)
|
||||
expect(Rails.logger).to have_received(:info).with("FCM push sent to #{user.email} with title #{notification.push_message_title}")
|
||||
end
|
||||
described_class.new(notification: notification).perform
|
||||
expect(Notification::FcmService).to have_received(:new)
|
||||
expect(fcm_double).to have_received(:send_v1)
|
||||
expect(WebPush).not_to have_received(:payload_send)
|
||||
expect(Rails.logger).to have_received(:info).with("FCM push sent to #{user.email} with title #{notification.push_message_title}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Firebase credentials are not configured' do
|
||||
before do
|
||||
allow(Rails.logger).to receive(:warn)
|
||||
allow(GlobalConfigService).to receive(:load).with('FIREBASE_PROJECT_ID', nil).and_return(nil)
|
||||
allow(GlobalConfigService).to receive(:load).with('FIREBASE_CREDENTIALS', nil).and_return(nil)
|
||||
end
|
||||
|
||||
it 'skips FCM without using the Chatwoot Hub relay' do
|
||||
create(:notification_subscription, user: notification.user, subscription_type: 'fcm')
|
||||
|
||||
described_class.new(notification: notification).perform
|
||||
|
||||
expect(Rails.logger).to have_received(:warn).with(
|
||||
'FCM push skipped: Firebase credentials are not configured; no remote push relay is used'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the push server returns error' do
|
||||
it 'sends webpush notifications for webpush subscription' do
|
||||
with_modified_env VAPID_PUBLIC_KEY: 'test' do
|
||||
|
||||
77
spec/services/notification/push_test_service_spec.rb
Normal file
77
spec/services/notification/push_test_service_spec.rb
Normal file
@@ -0,0 +1,77 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Notification::PushTestService do
|
||||
let!(:user) { create(:user) }
|
||||
let!(:subscription) do
|
||||
create(
|
||||
:notification_subscription,
|
||||
:fcm,
|
||||
user: user,
|
||||
identifier: 'fcm-test',
|
||||
subscription_attributes: { 'push_token' => 'test-token', 'device_id' => 'device-123456' }
|
||||
)
|
||||
end
|
||||
let(:fcm_double) { instance_double(FCM) }
|
||||
let(:fcm_service_double) { instance_double(Notification::FcmService, fcm_client: fcm_double) }
|
||||
|
||||
describe '#perform' do
|
||||
context 'when Firebase credentials are not configured' do
|
||||
before do
|
||||
allow(GlobalConfigService).to receive(:load).and_return(nil)
|
||||
allow(GlobalConfigService).to receive(:load).with('FIREBASE_PROJECT_ID', nil).and_return(nil)
|
||||
allow(GlobalConfigService).to receive(:load).with('FIREBASE_CREDENTIALS', nil).and_return(nil)
|
||||
end
|
||||
|
||||
it 'skips FCM without using the Chatwoot Hub relay' do
|
||||
result = described_class.new(user: user, subscription_ids: [subscription.id]).perform.first
|
||||
|
||||
expect(result).to include(
|
||||
type: 'fcm',
|
||||
status: :skipped,
|
||||
message: 'Firebase credentials are not configured; no remote push relay is used'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Firebase credentials are configured' do
|
||||
before do
|
||||
allow(GlobalConfigService).to receive(:load).and_return(nil)
|
||||
allow(Notification::FcmService).to receive(:new).and_return(fcm_service_double)
|
||||
allow(fcm_double).to receive(:send_v1).and_return(status_code: 200, body: '{}')
|
||||
allow(GlobalConfigService).to receive(:load).with('FIREBASE_PROJECT_ID', nil).and_return('test-project')
|
||||
allow(GlobalConfigService).to receive(:load).with('FIREBASE_CREDENTIALS', nil).and_return('test-credentials')
|
||||
end
|
||||
|
||||
it 'sends FCM directly without using the Chatwoot Hub relay' do
|
||||
result = described_class.new(user: user, subscription_ids: [subscription.id]).perform.first
|
||||
|
||||
expect(Notification::FcmService).to have_received(:new)
|
||||
expect(fcm_double).to have_received(:send_v1)
|
||||
expect(result[:status]).to eq(:success)
|
||||
end
|
||||
end
|
||||
|
||||
it 'keeps browser WebPush available' do
|
||||
browser_subscription = create(
|
||||
:notification_subscription,
|
||||
:browser_push,
|
||||
user: user,
|
||||
identifier: 'browser-test',
|
||||
subscription_attributes: {
|
||||
'endpoint' => 'https://push.example.test/endpoint',
|
||||
'p256dh' => 'test-p256dh',
|
||||
'auth' => 'test-auth'
|
||||
}
|
||||
)
|
||||
allow(VapidService).to receive(:public_key).and_return('test-public-key')
|
||||
allow(VapidService).to receive(:private_key).and_return('test-private-key')
|
||||
allow(WebPush).to receive(:payload_send).and_return(true)
|
||||
|
||||
result = described_class.new(user: user, subscription_ids: [browser_subscription.id]).perform.first
|
||||
|
||||
expect(WebPush).to have_received(:payload_send)
|
||||
expect(result[:type]).to eq('browser_push')
|
||||
expect(result[:status]).to eq(:success)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user