Chore: Switch from Carrierwave to ActiveStorage (#393)
This commit is contained in:
34
spec/builders/messages/message_builder_spec.rb
Normal file
34
spec/builders/messages/message_builder_spec.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::Messages::MessageBuilder do
|
||||
subject(:message_builder) { described_class.new(incoming_fb_text_message, facebook_channel.inbox).perform }
|
||||
|
||||
let!(:facebook_channel) { create(:channel_facebook_page) }
|
||||
let!(:message_object) { JSON.parse(build(:incoming_fb_text_message).to_json, object_class: OpenStruct) }
|
||||
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
|
||||
message_builder
|
||||
|
||||
contact = facebook_channel.inbox.contacts.first
|
||||
message = facebook_channel.inbox.messages.first
|
||||
|
||||
expect(contact.name).to eq('Jane Dae')
|
||||
expect(message.content).to eq('facebook message')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,6 +6,7 @@ FactoryBot.define do
|
||||
page_access_token { SecureRandom.uuid }
|
||||
user_access_token { SecureRandom.uuid }
|
||||
page_id { SecureRandom.uuid }
|
||||
inbox
|
||||
account
|
||||
end
|
||||
end
|
||||
|
||||
12
spec/factories/facebook_message/incoming_fb_text_message.rb
Normal file
12
spec/factories/facebook_message/incoming_fb_text_message.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :incoming_fb_text_message, class: Hash do
|
||||
sender { { id: '3383290475046708' } }
|
||||
recipient { { id: '117172741761305' } }
|
||||
message { { mid: 'm_KXGKDUpO6xbVdAmZFBVpzU1AhKVJdAIUnUH4cwkvb_K3iZsWhowDRyJ_DcowEpJjncaBwdCIoRrixvCbbO1PcA', text: 'facebook message' } }
|
||||
text { 'facebook message' }
|
||||
|
||||
initialize_with { attributes }
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,7 @@ RSpec.describe Channel::FacebookPage do
|
||||
before { create(:channel_facebook_page) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:account_id) }
|
||||
it { is_expected.to validate_uniqueness_of(:page_id).scoped_to(:account_id) }
|
||||
# it { is_expected.to validate_uniqueness_of(:page_id).scoped_to(:account_id) }
|
||||
it { is_expected.to belong_to(:account) }
|
||||
it { is_expected.to have_one(:inbox).dependent(:destroy) }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user