fix: issue with slack job (#7179)
This commit is contained in:
@@ -21,12 +21,9 @@ class HookJob < ApplicationJob
|
|||||||
|
|
||||||
message = event_data[:message]
|
message = event_data[:message]
|
||||||
if message.attachments.blank?
|
if message.attachments.blank?
|
||||||
::SendOnSlackJob.perform_later(message: message,
|
::SendOnSlackJob.perform_later(message, hook)
|
||||||
hook: hook)
|
|
||||||
else
|
else
|
||||||
::SendOnSlackJob.set(wait: 2.seconds).perform_later(
|
::SendOnSlackJob.set(wait: 2.seconds).perform_later(message, hook)
|
||||||
message: message, hook: hook
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
class SendOnSlackJob < ApplicationJob
|
class SendOnSlackJob < ApplicationJob
|
||||||
queue_as :medium
|
queue_as :medium
|
||||||
pattr_initialize [:message!, :hook!]
|
|
||||||
|
|
||||||
def perform
|
def perform(message, hook)
|
||||||
Integrations::Slack::SendOnSlackService.new(message: message, hook: hook).perform
|
Integrations::Slack::SendOnSlackService.new(message: message, hook: hook).perform
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ RSpec.describe HookJob do
|
|||||||
it 'calls SendOnSlackJob when its a slack hook' do
|
it 'calls SendOnSlackJob when its a slack hook' do
|
||||||
hook = create(:integrations_hook, app_id: 'slack', account: account)
|
hook = create(:integrations_hook, app_id: 'slack', account: account)
|
||||||
allow(SendOnSlackJob).to receive(:perform_later).and_return(process_service)
|
allow(SendOnSlackJob).to receive(:perform_later).and_return(process_service)
|
||||||
expect(SendOnSlackJob).to receive(:perform_later).with(message: event_data[:message], hook: hook)
|
expect(SendOnSlackJob).to receive(:perform_later).with(event_data[:message], hook)
|
||||||
described_class.perform_now(hook, event_name, event_data)
|
described_class.perform_now(hook, event_name, event_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ RSpec.describe HookJob do
|
|||||||
hook = create(:integrations_hook, app_id: 'slack', account: account)
|
hook = create(:integrations_hook, app_id: 'slack', account: account)
|
||||||
allow(SendOnSlackJob).to receive(:set).with(wait: 2.seconds).and_return(SendOnSlackJob)
|
allow(SendOnSlackJob).to receive(:set).with(wait: 2.seconds).and_return(SendOnSlackJob)
|
||||||
allow(SendOnSlackJob).to receive(:perform_later).and_return(process_service)
|
allow(SendOnSlackJob).to receive(:perform_later).and_return(process_service)
|
||||||
expect(SendOnSlackJob).to receive(:perform_later).with(message: event_data[:message], hook: hook)
|
expect(SendOnSlackJob).to receive(:perform_later).with(event_data[:message], hook)
|
||||||
described_class.perform_now(hook, event_name, event_data)
|
described_class.perform_now(hook, event_name, event_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -11,22 +11,25 @@ RSpec.describe SendOnSlackJob do
|
|||||||
let(:process_service) { double }
|
let(:process_service) { double }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
stub_request(:post, 'https://slack.com/api/chat.postMessage')
|
||||||
allow(process_service).to receive(:perform)
|
allow(process_service).to receive(:perform)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls Integrations::Slack::SendOnSlackService when its a slack hook' do
|
it 'calls Integrations::Slack::SendOnSlackService when its a slack hook' do
|
||||||
hook = create(:integrations_hook, app_id: 'slack', account: account)
|
hook = create(:integrations_hook, app_id: 'slack', account: account)
|
||||||
allow(Integrations::Slack::SendOnSlackService).to receive(:new).and_return(process_service)
|
slack_service_instance = Integrations::Slack::SendOnSlackService.new(message: event_data[:message], hook: hook)
|
||||||
expect(Integrations::Slack::SendOnSlackService).to receive(:new).with(message: event_data[:message], hook: hook)
|
expect(Integrations::Slack::SendOnSlackService).to receive(:new).with(message: event_data[:message],
|
||||||
described_class.perform_now(message: event_data[:message], hook: hook)
|
hook: hook).and_return(slack_service_instance)
|
||||||
|
described_class.perform_now(event_data[:message], hook)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls Integrations::Slack::SendOnSlackService when its a slack hook for template message' do
|
it 'calls Integrations::Slack::SendOnSlackService when its a slack hook for template message' do
|
||||||
event_data = { message: create(:message, account: account, message_type: :template) }
|
event_data = { message: create(:message, account: account, message_type: :template) }
|
||||||
hook = create(:integrations_hook, app_id: 'slack', account: account)
|
hook = create(:integrations_hook, app_id: 'slack', account: account)
|
||||||
allow(Integrations::Slack::SendOnSlackService).to receive(:new).and_return(process_service)
|
slack_service_instance = Integrations::Slack::SendOnSlackService.new(message: event_data[:message], hook: hook)
|
||||||
expect(Integrations::Slack::SendOnSlackService).to receive(:new).with(message: event_data[:message], hook: hook)
|
expect(Integrations::Slack::SendOnSlackService).to receive(:new).with(message: event_data[:message],
|
||||||
described_class.perform_now(message: event_data[:message], hook: hook)
|
hook: hook).and_return(slack_service_instance)
|
||||||
|
described_class.perform_now(event_data[:message], hook)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user