fix: Automatically remove expired story mention (#5300)
When a user mentions the connected Instagram page in a story, the story's content is downloaded in Chatwoot, then if the user deletes the story, the content persists in the platform. fixes: #5258
This commit is contained in:
@@ -180,4 +180,34 @@ RSpec.describe Message, type: :model do
|
||||
expect(message.email_notifiable_message?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when facebook channel with unavailable story link' do
|
||||
let(:instagram_message) { create(:message, :instagram_story_mention) }
|
||||
|
||||
before do
|
||||
# stubbing the request to facebook api during the message creation
|
||||
stub_request(:get, %r{https://graph.facebook.com/.*}).to_return(status: 200, body: {
|
||||
story: { mention: { link: 'http://graph.facebook.com/test-story-mention', id: '17920786367196703' } },
|
||||
from: { username: 'Sender-id-1', id: 'Sender-id-1' },
|
||||
id: 'instagram-message-id-1234'
|
||||
}.to_json, headers: {})
|
||||
end
|
||||
|
||||
it 'deletes the attachment for deleted stories' do
|
||||
expect(instagram_message.attachments.count).to eq 1
|
||||
stub_request(:get, %r{https://graph.facebook.com/.*}).to_return(status: 404)
|
||||
instagram_message.push_event_data
|
||||
expect(instagram_message.reload.attachments.count).to eq 0
|
||||
end
|
||||
|
||||
it 'deletes the attachment for expired stories' do
|
||||
expect(instagram_message.attachments.count).to eq 1
|
||||
# for expired stories, the link will be empty
|
||||
stub_request(:get, %r{https://graph.facebook.com/.*}).to_return(status: 200, body: {
|
||||
story: { mention: { link: '', id: '17920786367196703' } }
|
||||
}.to_json, headers: {})
|
||||
instagram_message.push_event_data
|
||||
expect(instagram_message.reload.attachments.count).to eq 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user