fix: Update tweet character count logic (#2709)
This commit is contained in:
@@ -9,7 +9,7 @@ describe Twitter::SendOnTwitterService do
|
||||
let(:widget_inbox) { create(:inbox, account: account) }
|
||||
let(:twitter_channel) { create(:channel_twitter_profile, account: account) }
|
||||
let(:twitter_inbox) { create(:inbox, channel: twitter_channel, account: account) }
|
||||
let(:contact) { create(:contact, account: account) }
|
||||
let(:contact) { create(:contact, account: account, additional_attributes: { screen_name: 'test_user' }) }
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: twitter_inbox) }
|
||||
let(:dm_conversation) do
|
||||
create(
|
||||
@@ -73,12 +73,50 @@ describe Twitter::SendOnTwitterService do
|
||||
expect(twitter_client).to have_received(:send_direct_message)
|
||||
end
|
||||
|
||||
it 'if conversation is a tweet' do
|
||||
create(:message, message_type: :incoming, inbox: twitter_inbox, account: account, conversation: tweet_conversation)
|
||||
message = create(:message, message_type: :outgoing, inbox: twitter_inbox, account: account, conversation: tweet_conversation)
|
||||
::Twitter::SendOnTwitterService.new(message: message).perform
|
||||
expect(twitter_client).to have_received(:send_tweet_reply)
|
||||
expect(message.reload.source_id).to eq '12345'
|
||||
context 'when conversation is a tweet' do
|
||||
it 'creates a response with correct reply if reply to message is incoming' do
|
||||
create(
|
||||
:message,
|
||||
message_type: :incoming,
|
||||
sender: contact,
|
||||
source_id: 'test-source-id-1',
|
||||
inbox: twitter_inbox,
|
||||
account: account,
|
||||
conversation: tweet_conversation
|
||||
)
|
||||
message = create(:message, message_type: :outgoing, inbox: twitter_inbox, account: account, conversation: tweet_conversation)
|
||||
::Twitter::SendOnTwitterService.new(message: message).perform
|
||||
expect(twitter_client).to have_received(:send_tweet_reply).with(
|
||||
reply_to_tweet_id: 'test-source-id-1',
|
||||
tweet: "@test_user #{message.content}"
|
||||
)
|
||||
expect(message.reload.source_id).to eq '12345'
|
||||
end
|
||||
|
||||
it 'creates a response with correct reply if reply to message is outgoing' do
|
||||
outgoing_message = create(
|
||||
:message,
|
||||
message_type: :outgoing,
|
||||
source_id: 'test-source-id-1',
|
||||
inbox: twitter_inbox,
|
||||
account: account,
|
||||
conversation: tweet_conversation
|
||||
)
|
||||
reply_message = create(
|
||||
:message,
|
||||
message_type: :outgoing,
|
||||
inbox: twitter_inbox,
|
||||
account: account,
|
||||
conversation: tweet_conversation,
|
||||
in_reply_to: outgoing_message.id
|
||||
)
|
||||
::Twitter::SendOnTwitterService.new(message: reply_message).perform
|
||||
expect(twitter_client).to have_received(:send_tweet_reply).with(
|
||||
reply_to_tweet_id: 'test-source-id-1',
|
||||
tweet: "@#{twitter_inbox.name} #{reply_message.content}"
|
||||
)
|
||||
expect(reply_message.reload.source_id).to eq '12345'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user