Feature: API Channel (#1052)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::Messages::IncomingMessageBuilder do
|
||||
describe ::Messages::Facebook::MessageBuilder do
|
||||
subject(:message_builder) { described_class.new(incoming_fb_text_message, facebook_channel.inbox).perform }
|
||||
|
||||
let!(:facebook_channel) { create(:channel_facebook_page) }
|
||||
54
spec/builders/messages/message_builder_spec.rb
Normal file
54
spec/builders/messages/message_builder_spec.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::Messages::MessageBuilder do
|
||||
subject(:message_builder) { described_class.new(user, conversation, params).perform }
|
||||
|
||||
let(:account) { create(:account) }
|
||||
let(:user) { create(:user, account: account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:inbox_member) { create(:inbox_member, inbox: inbox, account: account) }
|
||||
let(:conversation) { create(:conversation, inbox: inbox, account: account) }
|
||||
let(:params) do
|
||||
ActionController::Parameters.new({
|
||||
content: 'test'
|
||||
})
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
it 'creates a message' do
|
||||
message = message_builder
|
||||
expect(message.content).to eq params[:content]
|
||||
end
|
||||
end
|
||||
|
||||
describe '#perform when message_type is incoming' do
|
||||
context 'when channel is not api' do
|
||||
let(:params) do
|
||||
ActionController::Parameters.new({
|
||||
content: 'test',
|
||||
message_type: 'incoming'
|
||||
})
|
||||
end
|
||||
|
||||
it 'creates throws error when channel is not api' do
|
||||
expect { message_builder }.to raise_error 'Incoming messages are only allowed in Api inboxes'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when channel is api' do
|
||||
let(:channel_api) { create(:channel_api, account: account) }
|
||||
let(:conversation) { create(:conversation, inbox: channel_api.inbox, account: account) }
|
||||
let(:params) do
|
||||
ActionController::Parameters.new({
|
||||
content: 'test',
|
||||
message_type: 'incoming'
|
||||
})
|
||||
end
|
||||
|
||||
it 'creates message when channel is api' do
|
||||
message = message_builder
|
||||
expect(message.message_type).to eq params[:message_type]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -65,6 +65,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
|
||||
it 'creates the contact' do
|
||||
expect do
|
||||
@@ -74,6 +75,15 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'creates the contact identifier when inbox id is passed' do
|
||||
expect do
|
||||
post "/api/v1/accounts/#{account.id}/contacts", headers: admin.create_new_auth_token,
|
||||
params: valid_params.merge({ inbox_id: inbox.id })
|
||||
end.to change(ContactInbox, :count).by(1)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
9
spec/factories/channel/channel_api.rb
Normal file
9
spec/factories/channel/channel_api.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
FactoryBot.define do
|
||||
factory :channel_api, class: 'Channel::Api' do
|
||||
webhook_url { 'http://example.com' }
|
||||
account
|
||||
after(:create) do |channel_api|
|
||||
create(:inbox, channel: channel_api, account: channel_api.account)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,10 +5,10 @@ describe Webhooks::Trigger do
|
||||
|
||||
describe '#execute' do
|
||||
it 'triggers webhook' do
|
||||
params = { hello: 'hello' }
|
||||
url = 'htpps://test.com'
|
||||
params = { hello: :hello }
|
||||
url = 'https://test.com'
|
||||
|
||||
expect(RestClient).to receive(:post).with(url, params).once
|
||||
expect(RestClient).to receive(:post).with(url, params.to_json, { accept: :json, content_type: :json }).once
|
||||
trigger.execute(url, params)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user