feat(ee): Add copilot integration (v1) to the conversation sidebar (#10566)
This commit is contained in:
@@ -2,13 +2,15 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Captain Integrations API', type: :request do
|
||||
let!(:account) { create(:account) }
|
||||
let(:conversation) { create(:conversation, account: account) }
|
||||
let!(:agent) { create(:user, account: account, role: :agent) }
|
||||
let!(:hook) do
|
||||
create(:integrations_hook, account: account, app_id: 'captain', settings: {
|
||||
access_token: SecureRandom.hex,
|
||||
account_email: Faker::Internet.email,
|
||||
assistant_id: '1',
|
||||
account_id: '1'
|
||||
account_id: '1',
|
||||
inbox_ids: []
|
||||
})
|
||||
end
|
||||
let(:captain_api_url) { 'https://captain.example.com/' }
|
||||
@@ -77,4 +79,45 @@ RSpec.describe 'Captain Integrations API', type: :request do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/integrations/captain/copilot' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post copilot_api_v1_account_integrations_captain_url(account_id: account.id),
|
||||
params: { method: 'get', route: 'some_route' },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
context 'when valid request method and route' do
|
||||
let(:route) { 'assistants/1/copilot' }
|
||||
let(:method) { 'get' }
|
||||
|
||||
it 'proxies the request to Copilot API' do
|
||||
stub_request(:post, "#{captain_api_url}api/accounts/#{hook.settings['account_id']}/#{route}")
|
||||
.with(headers: {
|
||||
'X-User-Email' => hook.settings['account_email'],
|
||||
'X-User-Token' => hook.settings['access_token'],
|
||||
'Content-Type' => 'application/json'
|
||||
})
|
||||
.to_return(status: 200, body: 'Success', headers: {})
|
||||
|
||||
post copilot_api_v1_account_integrations_captain_url(account_id: account.id),
|
||||
params: {
|
||||
message: 'hello',
|
||||
previous_messages: [],
|
||||
conversation_id: conversation.display_id
|
||||
},
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to eq('Success')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user