From 2024d50390514718e1aa82c485f2e683aef3e058 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 20 Jan 2025 15:13:27 +0530 Subject: [PATCH] feat: add spec for chat_service --- .../captain/copilot/chat_service_spec.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 spec/enterprise/services/captain/copilot/chat_service_spec.rb diff --git a/spec/enterprise/services/captain/copilot/chat_service_spec.rb b/spec/enterprise/services/captain/copilot/chat_service_spec.rb new file mode 100644 index 000000000..256945416 --- /dev/null +++ b/spec/enterprise/services/captain/copilot/chat_service_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +RSpec.describe Captain::Copilot::ChatService do + let(:account) { create(:account, custom_attributes: { plan_name: 'startups' }) } + let(:inbox) { create(:inbox, account: account) } + let(:assistant) { create(:captain_assistant, account: account) } + let!(:captain_inbox_association) { create(:captain_inbox, captain_assistant: assistant, inbox: inbox) } + + let(:mock_captain_agent) { double('Captain::Agent') } + let(:mock_captain_tool) { double('Captain::Tool') } + + describe '#execure' do + before do + create(:installation_config) { create(:installation_config, name: 'CAPTAIN_OPEN_AI_API_KEY', value: 'test-key') } + allow(Captain::Agent).to receive(:new).and_return(mock_captain_agent) + allow(mock_captain_agent).to receive(:execute).and_return(true) + allow(mock_captain_agent).to receive(:register_tool).and_return(true) + + allow(Captain::Tool).to receive(:new).and_return(mock_captain_tool) + allow(mock_captain_tool).to receive(:register_method).and_return(true) + + allow(account).to receive(:increment_response_usage).and_return(true) + end + + it 'increments usage' do + described_class.new(assistant, { previous_messages: 'Hello', conversation_history: 'Hi' }).execute('Hey') + expect(account).to have_received(:increment_response_usage).once + end + end +end