fix: Handle Facebook reel attachment type (#13691)
Fixes https://linear.app/chatwoot/issue/PLA-96/argumenterror-reel-is-not-a-valid-file-type-argumenterror Fixes a crash in `when a user shares a Facebook reel via Messenger. Facebook sends these attachments with `type: "reel"`, which isn't a valid `file_type` enum value on the Attachment model (only `ig_reel` exists, matching Instagram's format). --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -155,6 +155,30 @@ RSpec.describe Attachment do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'push_event_data for ig_reel attachments' do
|
||||
it 'returns external_url as data_url when no file is attached' do
|
||||
attachment = message.attachments.create!(
|
||||
account_id: message.account_id,
|
||||
file_type: :ig_reel,
|
||||
external_url: 'https://www.facebook.com/reel/123456'
|
||||
)
|
||||
|
||||
event_data = attachment.push_event_data
|
||||
expect(event_data[:data_url]).to eq('https://www.facebook.com/reel/123456')
|
||||
expect(event_data[:thumb_url]).to eq('')
|
||||
end
|
||||
|
||||
it 'returns file_url as data_url when file is attached' do
|
||||
attachment = message.attachments.new(account_id: message.account_id, file_type: :ig_reel,
|
||||
external_url: 'https://www.instagram.com/reel/123')
|
||||
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
|
||||
attachment.save!
|
||||
|
||||
event_data = attachment.push_event_data
|
||||
expect(event_data[:data_url]).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
describe 'push_event_data for embed attachments' do
|
||||
it 'returns external url as data_url' do
|
||||
attachment = message.attachments.create!(account_id: message.account_id, file_type: :embed, external_url: 'https://example.com/embed')
|
||||
|
||||
Reference in New Issue
Block a user