Skip to content

Commit

Permalink
fix: issue with slack job (#7179)
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaswinichile committed May 24, 2023
1 parent bfaca85 commit 8e79cf7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
7 changes: 2 additions & 5 deletions app/jobs/hook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ def process_slack_integration(hook, event_name, event_data)

message = event_data[:message]
if message.attachments.blank?
::SendOnSlackJob.perform_later(message: message,
hook: hook)
::SendOnSlackJob.perform_later(message, hook)
else
::SendOnSlackJob.set(wait: 2.seconds).perform_later(
message: message, hook: hook
)
::SendOnSlackJob.set(wait: 2.seconds).perform_later(message, hook)
end
end

Expand Down
3 changes: 1 addition & 2 deletions app/jobs/send_on_slack_job.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class SendOnSlackJob < ApplicationJob
queue_as :medium
pattr_initialize [:message!, :hook!]

def perform
def perform(message, hook)
Integrations::Slack::SendOnSlackService.new(message: message, hook: hook).perform
end
end
4 changes: 2 additions & 2 deletions spec/jobs/hook_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
it 'calls SendOnSlackJob when its a slack hook' do
hook = create(:integrations_hook, app_id: 'slack', account: account)
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)
end

Expand All @@ -34,7 +34,7 @@
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(: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)
end

Expand Down
15 changes: 9 additions & 6 deletions spec/jobs/send_on_slack_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@
let(:process_service) { double }

before do
stub_request(:post, 'https://slack.com/api/chat.postMessage')
allow(process_service).to receive(:perform)
end

it 'calls Integrations::Slack::SendOnSlackService when its a slack hook' do
hook = create(:integrations_hook, app_id: 'slack', account: account)
allow(Integrations::Slack::SendOnSlackService).to receive(:new).and_return(process_service)
expect(Integrations::Slack::SendOnSlackService).to receive(:new).with(message: event_data[:message], hook: hook)
described_class.perform_now(message: event_data[:message], hook: hook)
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).and_return(slack_service_instance)
described_class.perform_now(event_data[:message], hook)
end

it 'calls Integrations::Slack::SendOnSlackService when its a slack hook for template message' do
event_data = { message: create(:message, account: account, message_type: :template) }
hook = create(:integrations_hook, app_id: 'slack', account: account)
allow(Integrations::Slack::SendOnSlackService).to receive(:new).and_return(process_service)
expect(Integrations::Slack::SendOnSlackService).to receive(:new).with(message: event_data[:message], hook: hook)
described_class.perform_now(message: event_data[:message], hook: hook)
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).and_return(slack_service_instance)
described_class.perform_now(event_data[:message], hook)
end
end
end

0 comments on commit 8e79cf7

Please sign in to comment.