iachat/spec/enterprise/jobs/captain/tools/firecrawl_parser_job_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

63 lines
2.0 KiB
Ruby

require 'rails_helper'
RSpec.describe Captain::Tools::FirecrawlParserJob, type: :job do
describe '#perform' do
let(:assistant) { create(:captain_assistant) }
let(:payload) do
{
markdown: 'Launch Week I is here! 🚀',
metadata: {
title: 'Home - Firecrawl',
ogTitle: 'Firecrawl',
ogUrl: 'https://www.firecrawl.dev/'
}
}
end
it 'creates a new document when one does not exist' do
expect do
described_class.perform_now(assistant_id: assistant.id, payload: payload)
end.to change(assistant.documents, :count).by(1)
document = assistant.documents.last
expect(document).to have_attributes(
content: payload[:markdown],
name: payload[:metadata][:ogTitle],
external_link: payload[:metadata][:ogUrl],
status: 'available'
)
end
it 'updates existing document when one exists' do
existing_document = create(:captain_document,
assistant: assistant,
account: assistant.account,
external_link: payload[:metadata][:ogUrl],
content: 'old content',
name: 'old title',
status: :in_progress)
expect do
described_class.perform_now(assistant_id: assistant.id, payload: payload)
end.not_to change(assistant.documents, :count)
existing_document.reload
expect(existing_document).to have_attributes(
content: payload[:markdown],
name: payload[:metadata][:ogTitle],
status: 'available'
)
end
context 'when an error occurs' do
it 'raises an error with a descriptive message' do
allow(Captain::Assistant).to receive(:find).and_raise(ActiveRecord::RecordNotFound)
expect do
described_class.perform_now(assistant_id: -1, payload: payload)
end.to raise_error(/Failed to parse FireCrawl data/)
end
end
end
end