Feat: Manage conversation for tweets based on the tweet flag (#3353)

Add tweet conversation only if tweets are enabled.

Fixes #1961
This commit is contained in:
Tejaswini Chile
2021-12-16 00:24:50 +05:30
committed by GitHub
parent e2e459a1ac
commit 9984edd3ef
12 changed files with 73 additions and 17 deletions

View File

@@ -362,6 +362,19 @@ RSpec.describe 'Inboxes API', type: :request do
expect(api_channel.reload.webhook_url).to eq('webhook.test')
end
it 'updates twitter inbox when administrator' do
api_channel = create(:channel_twitter_profile, account: account, tweets_enabled: true)
api_inbox = create(:inbox, channel: api_channel, account: account)
patch "/api/v1/accounts/#{account.id}/inboxes/#{api_inbox.id}",
headers: admin.create_new_auth_token,
params: { channel: { tweets_enabled: false } },
as: :json
expect(response).to have_http_status(:success)
expect(api_channel.reload.tweets_enabled).to eq(false)
end
it 'updates email inbox when administrator' do
email_channel = create(:channel_email, account: account)
email_inbox = create(:inbox, channel: email_channel, account: account)

View File

@@ -6,7 +6,7 @@ describe Webhooks::Twitter do
let!(:account) { create(:account) }
# FIX ME: recipient id is set to 1 inside event factories
let!(:twitter_channel) { create(:channel_twitter_profile, account: account, profile_id: '1') }
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!(:tweet_params) { build(:tweet_create_event).with_indifferent_access }
@@ -32,6 +32,27 @@ describe Webhooks::Twitter do
it 'creates incoming message in the twitter inbox' do
twitter_webhook.new(tweet_params).consume
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
expect(twitter_inbox.contacts.count).to be 1
expect(twitter_inbox.conversations.count).to be 1
expect(twitter_inbox.messages.count).to be 1