test(telegram): fix business-chat send-attachments spec
The let(:channel) and the service's message.inbox.channel were different object instances, so the chat_id / business_connection_id stubs on the test instance never applied to the service. Other examples masked it because they only counted requests; the business-chat example matches on body and tripped. Set the values via conversation.additional_attributes (where the channel methods actually read from) instead of stubbing.
This commit is contained in:
@@ -3,13 +3,17 @@ require 'rails_helper'
|
||||
RSpec.describe Telegram::SendAttachmentsService do
|
||||
describe '#perform' do
|
||||
let(:channel) { create(:channel_telegram) }
|
||||
let(:message) { build(:message, conversation: create(:conversation, inbox: channel.inbox)) }
|
||||
# Channel#chat_id and #business_connection_id read from conversation.additional_attributes,
|
||||
# so set the values there directly — stubbing the let(:channel) instance doesn't affect
|
||||
# the service's message.inbox.channel reference (different object instance).
|
||||
let(:conversation) do
|
||||
create(:conversation, inbox: channel.inbox, additional_attributes: { 'chat_id' => 'chat123' })
|
||||
end
|
||||
let(:message) { build(:message, conversation: conversation) }
|
||||
let(:service) { described_class.new(message: message) }
|
||||
let(:telegram_api_url) { channel.telegram_api_url }
|
||||
|
||||
before do
|
||||
allow(channel).to receive(:chat_id).and_return('chat123')
|
||||
|
||||
stub_request(:post, "#{telegram_api_url}/sendMediaGroup")
|
||||
.to_return(status: 200, body: { ok: true, result: [{ message_id: 'media' }] }.to_json, headers: { 'Content-Type' => 'application/json' })
|
||||
|
||||
@@ -41,7 +45,11 @@ RSpec.describe Telegram::SendAttachmentsService do
|
||||
end
|
||||
|
||||
context 'when this is business chat' do
|
||||
before { allow(channel).to receive(:business_connection_id).and_return('eooW3KF5WB5HxTD7T826') }
|
||||
before do
|
||||
conversation.update!(additional_attributes: conversation.additional_attributes.merge(
|
||||
'business_connection_id' => 'eooW3KF5WB5HxTD7T826'
|
||||
))
|
||||
end
|
||||
|
||||
it 'sends all types of attachments in seperate groups and returns the last successful message ID from the batch' do
|
||||
attach_files(message)
|
||||
|
||||
Reference in New Issue
Block a user