feat: Provision captain accounts automatically (#10168)
- Provision accounts on Chatwoot cloud automatically if the feature is enabled
This commit is contained in:
@@ -51,4 +51,48 @@ RSpec.describe Integrations::Hook do
|
||||
expect(openai_double).to have_received(:perform)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'creating a captain hook' do
|
||||
let(:account) { create(:account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:settings) { { inbox_ids: inbox.id } }
|
||||
|
||||
it 'raises an error if captain is not enabled' do
|
||||
expect { create(:integrations_hook, app_id: 'captain', account: account, settings: settings) }.to raise_error('Captain is not enabled')
|
||||
end
|
||||
|
||||
context 'when captain is enabled' do
|
||||
before do
|
||||
account.enable_features('captain_integration')
|
||||
account.save!
|
||||
InstallationConfig.where(name: 'CAPTAIN_APP_URL').first_or_create(value: 'https://app.chatwoot.com')
|
||||
stub_request(:post, ChatwootHub::CAPTAIN_ACCOUNTS_URL).to_return(body: {
|
||||
account_email: 'test@example.com',
|
||||
captain_account_id: 1,
|
||||
access_token: 'access_token',
|
||||
assistant_id: 1
|
||||
}.to_json)
|
||||
end
|
||||
|
||||
it 'populates the settings with captain settings' do
|
||||
hook = create(:integrations_hook, app_id: 'captain', account: account, settings: settings)
|
||||
expect(hook.settings['account_email']).to be_present
|
||||
expect(hook.settings['assistant_id']).to be_present
|
||||
expect(hook.settings['access_token']).to be_present
|
||||
expect(hook.settings['assistant_id']).to be_present
|
||||
end
|
||||
|
||||
it 'raises an error if the request to captain hub fails' do
|
||||
stub_request(:post, ChatwootHub::CAPTAIN_ACCOUNTS_URL).to_return(
|
||||
status: 500,
|
||||
body: {
|
||||
error: 'Failed to get captain settings'
|
||||
}.to_json
|
||||
)
|
||||
expect do
|
||||
create(:integrations_hook, app_id: 'captain', account: account, settings: settings)
|
||||
end.to raise_error('Failed to get captain settings: {"error":"Failed to get captain settings"}')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user