chore: Mark Facebook accounts for reconnection (#2405)

fixes: #2037
This commit is contained in:
Sojan Jose
2021-08-01 18:15:39 +05:30
committed by GitHub
parent 2890339734
commit e46aa1aa64
9 changed files with 112 additions and 22 deletions

View File

@@ -8,20 +8,17 @@ describe ::Messages::Facebook::MessageBuilder do
let!(:incoming_fb_text_message) { Integrations::Facebook::MessageParser.new(message_object) }
let(:fb_object) { double }
before do
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
allow(fb_object).to receive(:get_object).and_return(
{
first_name: 'Jane',
last_name: 'Dae',
account_id: facebook_channel.inbox.account_id,
profile_pic: 'https://via.placeholder.com/250x250.png'
}.with_indifferent_access
)
end
describe '#perform' do
it 'creates contact and message for the facebook inbox' do
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
allow(fb_object).to receive(:get_object).and_return(
{
first_name: 'Jane',
last_name: 'Dae',
account_id: facebook_channel.inbox.account_id,
profile_pic: 'https://via.placeholder.com/250x250.png'
}.with_indifferent_access
)
message_builder
contact = facebook_channel.inbox.contacts.first
@@ -30,5 +27,13 @@ describe ::Messages::Facebook::MessageBuilder do
expect(contact.name).to eq('Jane Dae')
expect(message.content).to eq('facebook message')
end
it 'increments channel authorization_error_count when error is thrown' do
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
allow(fb_object).to receive(:get_object).and_raise(Koala::Facebook::AuthenticationError.new(500, 'Error validating access token'))
message_builder
expect(facebook_channel.authorization_error_count).to eq(1)
end
end
end