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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 15 deletions

View file

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

View file

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

View file

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

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!(
901 => 'Trial Expired',
902 => 'Account Suspended'
)
Rack::Utils::HTTP_STATUS_CODES[901] = 'Trial Expired'
Rack::Utils::HTTP_STATUS_CODES[902] = 'Account Suspended'

View file

@ -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]

View file

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