Chore: Fix failing sidekiq events for contact create (#966)

This commit is contained in:
Sojan Jose
2020-06-16 19:39:57 +05:30
committed by GitHub
parent b0bbd757b5
commit 04f6460afb
7 changed files with 21 additions and 15 deletions

View File

@@ -102,8 +102,8 @@ AllCops:
Exclude: Exclude:
- 'bin/**/*' - 'bin/**/*'
- 'db/schema.rb' - 'db/schema.rb'
- 'config/**/*'
- 'public/**/*' - 'public/**/*'
- 'config/initializers/bot.rb'
- 'vendor/**/*' - 'vendor/**/*'
- 'node_modules/**/*' - 'node_modules/**/*'
- 'lib/tasks/auto_annotate_models.rake' - 'lib/tasks/auto_annotate_models.rake'

View File

@@ -38,8 +38,8 @@ class Contact < ApplicationRecord
has_many :messages, dependent: :destroy has_many :messages, dependent: :destroy
before_validation :downcase_email before_validation :downcase_email
after_create :dispatch_create_event after_create_commit :dispatch_create_event
after_update :dispatch_update_event after_update_commit :dispatch_update_event
def get_source_id(inbox_id) def get_source_id(inbox_id)
contact_inboxes.find_by!(inbox_id: inbox_id).source_id contact_inboxes.find_by!(inbox_id: inbox_id).source_id

View File

@@ -41,8 +41,12 @@ class Notification::PushNotificationService
app_account_conversation_url(account_id: conversation.account_id, id: conversation.display_id) app_account_conversation_url(account_id: conversation.account_id, id: conversation.display_id)
end end
def send_browser_push?(subscription)
ENV['VAPID_PUBLIC_KEY'] && subscription.browser_push?
end
def send_browser_push(subscription) def send_browser_push(subscription)
return unless subscription.browser_push? return unless send_browser_push?(subscription)
Webpush.payload_send( Webpush.payload_send(
message: JSON.generate(push_message), message: JSON.generate(push_message),
@@ -63,6 +67,7 @@ class Notification::PushNotificationService
end end
def send_fcm_push(subscription) def send_fcm_push(subscription)
return unless ENV['FCM_SERVER_KEY']
return unless subscription.fcm? return unless subscription.fcm?
fcm = FCM.new(ENV['FCM_SERVER_KEY']) fcm = FCM.new(ENV['FCM_SERVER_KEY'])

View File

@@ -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'))

View File

@@ -1,4 +1,2 @@
Rack::Utils::HTTP_STATUS_CODES.merge!( Rack::Utils::HTTP_STATUS_CODES[901] = 'Trial Expired'
901 => 'Trial Expired', Rack::Utils::HTTP_STATUS_CODES[902] = 'Account Suspended'
902 => 'Account Suspended'
)

View File

@@ -87,11 +87,11 @@ Rails.application.routes.draw do
end end
resource :notification_settings, only: [:show, :update] resource :notification_settings, only: [:show, :update]
resources :webhooks, except: [:show] resources :webhooks, except: [:show]
namespace :integrations do namespace :integrations do
resources :apps, only: [:index, :show] resources :apps, only: [:index, :show]
resources :slack, only: [:create, :update, :destroy] resources :slack, only: [:create, :update, :destroy]
end end
end end
end end
# end of account scoped api routes # end of account scoped api routes
@@ -106,7 +106,6 @@ Rails.application.routes.draw do
resources :agent_bots, only: [:index] resources :agent_bots, only: [:index]
namespace :widget do namespace :widget do
resources :events, only: [:create] resources :events, only: [:create]
resources :messages, only: [:index, :create, :update] resources :messages, only: [:index, :create, :update]

View File

@@ -14,19 +14,23 @@ describe Notification::PushNotificationService do
describe '#perform' do describe '#perform' do
it 'sends webpush notifications for webpush subscription' do it 'sends webpush notifications for webpush subscription' do
ENV['VAPID_PUBLIC_KEY'] = 'test'
create(:notification_subscription, user: notification.user) create(:notification_subscription, user: notification.user)
described_class.new(notification: notification).perform described_class.new(notification: notification).perform
expect(Webpush).to have_received(:payload_send) expect(Webpush).to have_received(:payload_send)
expect(FCM).not_to have_received(:new) expect(FCM).not_to have_received(:new)
ENV['ENABLE_ACCOUNT_SIGNUP'] = nil
end end
it 'sends a fcm notification for firebase subscription' do it 'sends a fcm notification for firebase subscription' do
ENV['FCM_SERVER_KEY'] = 'test'
create(:notification_subscription, user: notification.user, subscription_type: 'fcm') create(:notification_subscription, user: notification.user, subscription_type: 'fcm')
described_class.new(notification: notification).perform described_class.new(notification: notification).perform
expect(FCM).to have_received(:new) expect(FCM).to have_received(:new)
expect(Webpush).not_to have_received(:payload_send) expect(Webpush).not_to have_received(:payload_send)
ENV['ENABLE_ACCOUNT_SIGNUP'] = nil
end end
end end
end end