2020-02-02 19:09:00 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'webhooks/twitter'
|
|
|
|
|
|
|
|
describe Webhooks::Twitter do
|
2020-02-09 10:17:48 +00:00
|
|
|
subject(:twitter_webhook) { described_class }
|
2020-02-02 19:09:00 +00:00
|
|
|
|
|
|
|
let!(:account) { create(:account) }
|
|
|
|
# FIX ME: recipient id is set to 1 inside event factories
|
2021-12-15 18:54:50 +00:00
|
|
|
let!(:twitter_channel) { create(:channel_twitter_profile, account: account, profile_id: '1', tweets_enabled: true) }
|
2020-06-09 18:24:35 +00:00
|
|
|
let!(:twitter_inbox) { create(:inbox, channel: twitter_channel, account: account, greeting_enabled: false) }
|
2020-02-09 10:17:48 +00:00
|
|
|
let!(:dm_params) { build(:twitter_message_create_event).with_indifferent_access }
|
|
|
|
let!(:tweet_params) { build(:tweet_create_event).with_indifferent_access }
|
2020-11-16 05:16:53 +00:00
|
|
|
let!(:tweet_params_from_blocked_user) { build(:tweet_create_event, user_has_blocked: true).with_indifferent_access }
|
2020-02-02 19:09:00 +00:00
|
|
|
|
|
|
|
describe '#perform' do
|
2020-02-09 10:17:48 +00:00
|
|
|
context 'with direct_message params' do
|
2020-02-02 19:09:00 +00:00
|
|
|
it 'creates incoming message in the twitter inbox' do
|
2020-02-09 10:17:48 +00:00
|
|
|
twitter_webhook.new(dm_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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with tweet_params params' do
|
2020-11-16 05:16:53 +00:00
|
|
|
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
|
|
|
|
expect(twitter_inbox.contacts.count).to be 0
|
|
|
|
expect(twitter_inbox.conversations.count).to be 0
|
|
|
|
expect(twitter_inbox.messages.count).to be 0
|
|
|
|
end
|
|
|
|
|
2020-02-09 10:17:48 +00:00
|
|
|
it 'creates incoming message in the twitter inbox' do
|
|
|
|
twitter_webhook.new(tweet_params).consume
|
2021-12-15 18:54:50 +00:00
|
|
|
twitter_inbox.reload
|
|
|
|
expect(twitter_inbox.contacts.count).to be 1
|
|
|
|
expect(twitter_inbox.conversations.count).to be 1
|
|
|
|
expect(twitter_inbox.messages.count).to be 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with tweet_enabled flag disabled' do
|
|
|
|
before do
|
|
|
|
twitter_channel.update(tweets_enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create incoming message in the twitter inbox for tweet' do
|
|
|
|
twitter_webhook.new(tweet_params).consume
|
|
|
|
expect(twitter_inbox.contacts.count).to be 0
|
|
|
|
expect(twitter_inbox.conversations.count).to be 0
|
|
|
|
expect(twitter_inbox.messages.count).to be 0
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates incoming message in the twitter inbox' do
|
|
|
|
twitter_webhook.new(dm_params).consume
|
2020-02-02 19:09:00 +00:00
|
|
|
expect(twitter_inbox.contacts.count).to be 1
|
|
|
|
expect(twitter_inbox.conversations.count).to be 1
|
|
|
|
expect(twitter_inbox.messages.count).to be 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|