2020-06-12 17:42:47 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe HookJob, type: :job do
|
2021-05-05 15:36:11 +00:00
|
|
|
subject(:job) { described_class.perform_later(hook, event_name, event_data) }
|
2020-06-12 17:42:47 +00:00
|
|
|
|
|
|
|
let(:account) { create(:account) }
|
|
|
|
let(:hook) { create(:integrations_hook, account: account) }
|
2021-05-05 15:36:11 +00:00
|
|
|
let(:event_name) { 'message.created' }
|
|
|
|
let(:event_data) { { message: create(:message, account: account) } }
|
2020-06-12 17:42:47 +00:00
|
|
|
|
2021-05-05 15:36:11 +00:00
|
|
|
it 'enqueues the job' do
|
2020-06-12 17:42:47 +00:00
|
|
|
expect { job }.to have_enqueued_job(described_class)
|
2021-05-05 15:36:11 +00:00
|
|
|
.with(hook, event_name, event_data)
|
2020-06-12 17:42:47 +00:00
|
|
|
.on_queue('integrations')
|
|
|
|
end
|
2021-05-05 15:36:11 +00:00
|
|
|
|
|
|
|
context 'when handleable events like message.created' do
|
|
|
|
let(:process_service) { double }
|
|
|
|
|
|
|
|
before do
|
|
|
|
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)
|
|
|
|
described_class.perform_now(hook, event_name, event_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls Integrations::Dialogflow::ProcessorService when its a dialogflow intergation' do
|
|
|
|
hook = create(:integrations_hook, app_id: 'dialogflow', account: account)
|
|
|
|
allow(Integrations::Dialogflow::ProcessorService).to receive(:new).and_return(process_service)
|
|
|
|
expect(Integrations::Dialogflow::ProcessorService).to receive(:new)
|
|
|
|
described_class.perform_now(hook, event_name, event_data)
|
|
|
|
end
|
|
|
|
end
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|