Chore: Fix failing sidekiq events for contact create (#966)
This commit is contained in:
parent
b0bbd757b5
commit
04f6460afb
7 changed files with 21 additions and 15 deletions
|
@ -102,8 +102,8 @@ AllCops:
|
|||
Exclude:
|
||||
- 'bin/**/*'
|
||||
- 'db/schema.rb'
|
||||
- 'config/**/*'
|
||||
- 'public/**/*'
|
||||
- 'config/initializers/bot.rb'
|
||||
- 'vendor/**/*'
|
||||
- 'node_modules/**/*'
|
||||
- 'lib/tasks/auto_annotate_models.rake'
|
||||
|
|
|
@ -38,8 +38,8 @@ class Contact < ApplicationRecord
|
|||
has_many :messages, dependent: :destroy
|
||||
|
||||
before_validation :downcase_email
|
||||
after_create :dispatch_create_event
|
||||
after_update :dispatch_update_event
|
||||
after_create_commit :dispatch_create_event
|
||||
after_update_commit :dispatch_update_event
|
||||
|
||||
def get_source_id(inbox_id)
|
||||
contact_inboxes.find_by!(inbox_id: inbox_id).source_id
|
||||
|
|
|
@ -41,8 +41,12 @@ class Notification::PushNotificationService
|
|||
app_account_conversation_url(account_id: conversation.account_id, id: conversation.display_id)
|
||||
end
|
||||
|
||||
def send_browser_push?(subscription)
|
||||
ENV['VAPID_PUBLIC_KEY'] && subscription.browser_push?
|
||||
end
|
||||
|
||||
def send_browser_push(subscription)
|
||||
return unless subscription.browser_push?
|
||||
return unless send_browser_push?(subscription)
|
||||
|
||||
Webpush.payload_send(
|
||||
message: JSON.generate(push_message),
|
||||
|
@ -63,6 +67,7 @@ class Notification::PushNotificationService
|
|||
end
|
||||
|
||||
def send_fcm_push(subscription)
|
||||
return unless ENV['FCM_SERVER_KEY']
|
||||
return unless subscription.fcm?
|
||||
|
||||
fcm = FCM.new(ENV['FCM_SERVER_KEY'])
|
||||
|
|
|
@ -1 +1 @@
|
|||
APPS_CONFIG = YAML.load_file(File.join(Rails.root, 'config/integration', 'apps.yml'))
|
||||
APPS_CONFIG = YAML.load_file(Rails.root.join('config/integration/apps.yml'))
|
||||
|
|
|
@ -1,4 +1,2 @@
|
|||
Rack::Utils::HTTP_STATUS_CODES.merge!(
|
||||
901 => 'Trial Expired',
|
||||
902 => 'Account Suspended'
|
||||
)
|
||||
Rack::Utils::HTTP_STATUS_CODES[901] = 'Trial Expired'
|
||||
Rack::Utils::HTTP_STATUS_CODES[902] = 'Account Suspended'
|
||||
|
|
|
@ -87,11 +87,11 @@ Rails.application.routes.draw do
|
|||
end
|
||||
resource :notification_settings, only: [:show, :update]
|
||||
|
||||
resources :webhooks, except: [:show]
|
||||
namespace :integrations do
|
||||
resources :apps, only: [:index, :show]
|
||||
resources :slack, only: [:create, :update, :destroy]
|
||||
end
|
||||
resources :webhooks, except: [:show]
|
||||
namespace :integrations do
|
||||
resources :apps, only: [:index, :show]
|
||||
resources :slack, only: [:create, :update, :destroy]
|
||||
end
|
||||
end
|
||||
end
|
||||
# end of account scoped api routes
|
||||
|
@ -106,7 +106,6 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :agent_bots, only: [:index]
|
||||
|
||||
|
||||
namespace :widget do
|
||||
resources :events, only: [:create]
|
||||
resources :messages, only: [:index, :create, :update]
|
||||
|
|
|
@ -14,19 +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)
|
||||
|
||||
described_class.new(notification: notification).perform
|
||||
expect(Webpush).to have_received(:payload_send)
|
||||
expect(FCM).not_to have_received(:new)
|
||||
ENV['ENABLE_ACCOUNT_SIGNUP'] = nil
|
||||
end
|
||||
|
||||
it 'sends a fcm notification for firebase subscription' do
|
||||
ENV['FCM_SERVER_KEY'] = 'test'
|
||||
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['ENABLE_ACCOUNT_SIGNUP'] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue