Files
leadchat/spec/models/integrations/app_spec.rb
Pranav d070743383 feat(ee): Add Captain features (#10665)
Migration Guide: https://chwt.app/v4/migration

This PR imports all the work related to Captain into the EE codebase. Captain represents the AI-based features in Chatwoot and includes the following key components:

- Assistant: An assistant has a persona, the product it would be trained on. At the moment, the data at which it is trained is from websites. Future integrations on Notion documents, PDF etc. This PR enables connecting an assistant to an inbox. The assistant would run the conversation every time before transferring it to an agent.
- Copilot for Agents: When an agent is supporting a customer, we will be able to offer additional help to lookup some data or fetch information from integrations etc via copilot.
- Conversation FAQ generator: When a conversation is resolved, the Captain integration would identify questions which were not in the knowledge base.
- CRM memory: Learns from the conversations and identifies important information about the contact.

---------

Co-authored-by: Vishnu Narayanan <vishnu@chatwoot.com>
Co-authored-by: Sojan <sojan@pepalo.com>
Co-authored-by: iamsivin <iamsivin@gmail.com>
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
2025-01-14 16:15:47 -08:00

106 lines
2.7 KiB
Ruby

require 'rails_helper'
RSpec.describe Integrations::App do
let(:apps) { described_class }
let(:app) { apps.find(id: app_name) }
let(:account) { create(:account) }
describe '#name' do
let(:app_name) { 'slack' }
it 'returns the name' do
expect(app.name).to eq('Slack')
end
end
describe '#logo' do
let(:app_name) { 'slack' }
it 'returns the logo' do
expect(app.logo).to eq('slack.png')
end
end
describe '#action' do
let(:app_name) { 'slack' }
before do
allow(Current).to receive(:account).and_return(account)
end
context 'when the app is slack' do
it 'returns the action URL with client_id and redirect_uri' do
with_modified_env SLACK_CLIENT_ID: 'dummy_client_id' do
expect(app.action).to include('client_id=dummy_client_id')
expect(app.action).to include(
"/app/accounts/#{account.id}/settings/integrations/slack"
)
end
end
end
end
describe '#active?' do
let(:app_name) { 'slack' }
context 'when the app is slack' do
it 'returns true if SLACK_CLIENT_SECRET is present' do
with_modified_env SLACK_CLIENT_SECRET: 'random_secret' do
expect(app.active?(account)).to be true
end
end
end
context 'when the app is linear' do
let(:app_name) { 'linear' }
it 'returns true if the linear integration feature is disabled' do
expect(app.active?(account)).to be false
end
it 'returns false if the linear integration feature is enabled' do
account.enable_features('linear_integration')
account.save!
expect(app.active?(account)).to be true
end
end
context 'when other apps are queried' do
let(:app_name) { 'webhook' }
it 'returns true' do
expect(app.active?(account)).to be true
end
end
end
describe '#enabled?' do
context 'when the app is webhook' do
let(:app_name) { 'webhook' }
it 'returns false if the account does not have any webhooks' do
expect(app.enabled?(account)).to be false
end
it 'returns true if the account has webhooks' do
create(:webhook, account: account)
expect(app.enabled?(account)).to be true
end
end
context 'when the app is anything other than webhook' do
let(:app_name) { 'openai' }
it 'returns false if the account does not have any hooks for the app' do
expect(app.enabled?(account)).to be false
end
it 'returns true if the account has hooks for the app' do
create(:integrations_hook, :openai, account: account)
expect(app.enabled?(account)).to be true
end
end
end
end