2020-06-12 17:42:47 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2020-06-25 18:05:16 +00:00
|
|
|
describe Integrations::Slack::SendOnSlackService do
|
2020-06-12 17:42:47 +00:00
|
|
|
let(:account) { create(:account) }
|
|
|
|
let!(:inbox) { create(:inbox, account: account) }
|
|
|
|
let!(:contact) { create(:contact) }
|
|
|
|
|
|
|
|
let!(:hook) { create(:integrations_hook, account: account) }
|
|
|
|
let!(:conversation) { create(:conversation, account: account, inbox: inbox, contact: contact) }
|
|
|
|
let!(:message) { create(:message, account: account, inbox: inbox, conversation: conversation) }
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
it 'sent message to slack' do
|
2020-06-25 18:05:16 +00:00
|
|
|
builder = described_class.new(message: message, hook: hook)
|
2020-06-12 17:42:47 +00:00
|
|
|
stub_request(:post, 'https://slack.com/api/chat.postMessage')
|
|
|
|
.to_return(status: 200, body: '', headers: {})
|
2020-06-22 07:49:26 +00:00
|
|
|
slack_client = double
|
|
|
|
expect(builder).to receive(:slack_client).and_return(slack_client)
|
2020-06-12 17:42:47 +00:00
|
|
|
|
2020-06-22 07:49:26 +00:00
|
|
|
expect(slack_client).to receive(:chat_postMessage).with(
|
2020-06-12 17:42:47 +00:00
|
|
|
channel: hook.reference_id,
|
|
|
|
text: message.content,
|
2020-08-11 04:27:42 +00:00
|
|
|
username: "Contact: #{message.sender.name}",
|
2020-06-22 07:49:26 +00:00
|
|
|
thread_ts: conversation.identifier,
|
|
|
|
icon_url: anything
|
2020-06-12 17:42:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
builder.perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|