Feat: twitter image support (#4429)
This commit is contained in:
75
spec/factories/twitter/twitter_dm_image_event.rb
Normal file
75
spec/factories/twitter/twitter_dm_image_event.rb
Normal file
@@ -0,0 +1,75 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :twitter_dm_image_event, class: Hash do
|
||||
for_user_id { '1' }
|
||||
direct_message_events do
|
||||
[{
|
||||
'type' => 'message_create',
|
||||
'id' => '123',
|
||||
'message_create' => {
|
||||
'target' => { 'recipient_id' => '1' },
|
||||
'sender_id' => '2',
|
||||
'source_app_id' => '268278',
|
||||
'message_data' => {
|
||||
'text' => 'Blue Bird',
|
||||
'attachment' => {
|
||||
'media' => {
|
||||
'display_url' => 'pic.twitter.com/5J1WJSRCy9',
|
||||
'expanded_url' => 'https://twitter.com/nolan_test/status/930077847535812610/photo/1',
|
||||
'id' => 9.300778475358126e17,
|
||||
'id_str' => '930077847535812610',
|
||||
'indices' => [
|
||||
13,
|
||||
36
|
||||
],
|
||||
'media_url' => 'http://pbs.twimg.com/media/DOhM30VVwAEpIHq.jpg',
|
||||
'media_url_https' => 'https://pbs.twimg.com/media/DOhM30VVwAEpIHq.jpg',
|
||||
'sizes' => {
|
||||
'thumb' => {
|
||||
'h' => 150,
|
||||
'resize' => 'crop',
|
||||
'w' => 150
|
||||
},
|
||||
'large' => {
|
||||
'h' => 1366,
|
||||
'resize' => 'fit',
|
||||
'w' => 2048
|
||||
},
|
||||
'medium' => {
|
||||
'h' => 800,
|
||||
'resize' => 'fit',
|
||||
'w' => 1200
|
||||
},
|
||||
'small' => {
|
||||
'h' => 454,
|
||||
'resize' => 'fit',
|
||||
'w' => 680
|
||||
}
|
||||
},
|
||||
'type' => 'photo',
|
||||
'url' => 'https://t.co/5J1WJSRCy9'
|
||||
}
|
||||
}.with_indifferent_access
|
||||
}
|
||||
}
|
||||
}.with_indifferent_access]
|
||||
end
|
||||
users do
|
||||
{
|
||||
'1' => {
|
||||
id: '1',
|
||||
name: 'person 1',
|
||||
profile_image_url: 'https://chatwoot-assets.local/sample.png'
|
||||
},
|
||||
'2' => {
|
||||
id: '1',
|
||||
name: 'person 1',
|
||||
profile_image_url: 'https://chatwoot-assets.local/sample.png'
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
initialize_with { attributes }
|
||||
end
|
||||
end
|
||||
@@ -9,6 +9,7 @@ describe Webhooks::Twitter do
|
||||
let!(:twitter_channel) { create(:channel_twitter_profile, account: account, profile_id: '1', tweets_enabled: true) }
|
||||
let!(:twitter_inbox) { create(:inbox, channel: twitter_channel, account: account, greeting_enabled: false) }
|
||||
let!(:dm_params) { build(:twitter_message_create_event).with_indifferent_access }
|
||||
let!(:dm_image_params) { build(:twitter_dm_image_event).with_indifferent_access }
|
||||
let!(:tweet_params) { build(:tweet_create_event).with_indifferent_access }
|
||||
let!(:tweet_params_from_blocked_user) { build(:tweet_create_event, user_has_blocked: true).with_indifferent_access }
|
||||
|
||||
@@ -22,6 +23,21 @@ describe Webhooks::Twitter do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with direct_message attachment params' do
|
||||
before do
|
||||
stub_request(:get, 'http://pbs.twimg.com/media/DOhM30VVwAEpIHq.jpg')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
end
|
||||
|
||||
it 'creates incoming message with attachments in the twitter inbox' do
|
||||
twitter_webhook.new(dm_image_params).consume
|
||||
expect(twitter_inbox.contacts.count).to be 1
|
||||
expect(twitter_inbox.conversations.count).to be 1
|
||||
expect(twitter_inbox.messages.count).to be 1
|
||||
expect(twitter_inbox.messages.last.attachments.count).to be 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'with tweet_params params' do
|
||||
it 'does not create incoming message in the twitter inbox if it is a blocked user' do
|
||||
twitter_webhook.new(tweet_params_from_blocked_user).consume
|
||||
|
||||
Reference in New Issue
Block a user