2019-10-12 18:08:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
FactoryBot.define do
|
|
|
|
factory :message do
|
2020-07-15 11:03:52 +00:00
|
|
|
content { 'Incoming Message' }
|
2019-10-12 18:08:41 +00:00
|
|
|
status { 'sent' }
|
|
|
|
message_type { 'incoming' }
|
2020-01-09 07:36:40 +00:00
|
|
|
content_type { 'text' }
|
|
|
|
account { create(:account) }
|
|
|
|
|
2022-12-08 12:55:24 +00:00
|
|
|
trait :instagram_story_mention do
|
|
|
|
content_attributes { { image_type: 'story_mention' } }
|
|
|
|
after(:build) do |message|
|
|
|
|
unless message.inbox.instagram?
|
|
|
|
message.inbox = create(:inbox, account: message.account,
|
|
|
|
channel: create(:channel_instagram_fb_page, account: message.account, instagram_id: 'instagram-123'))
|
|
|
|
end
|
|
|
|
attachment = message.attachments.new(account_id: message.account_id, file_type: :image, external_url: 'https://www.example.com/test.jpeg')
|
|
|
|
attachment.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
after(:build) do |message|
|
2020-08-11 04:27:42 +00:00
|
|
|
message.sender ||= message.outgoing? ? create(:user, account: message.account) : create(:contact, account: message.account)
|
2020-10-31 18:44:33 +00:00
|
|
|
message.inbox ||= message.conversation&.inbox || create(:inbox, account: message.account)
|
2020-07-16 19:02:32 +00:00
|
|
|
message.conversation ||= create(:conversation, account: message.account, inbox: message.inbox)
|
2020-01-09 07:36:40 +00:00
|
|
|
end
|
2019-10-12 18:08:41 +00:00
|
|
|
end
|
|
|
|
end
|