From e22e97ad06cc2d9ef37dfe877829d88574f6ffce Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 22 Jan 2025 13:43:42 +0530 Subject: [PATCH] test: update chat_service spec --- enterprise/app/helpers/captain/chat_helper.rb | 1 - .../services/captain/copilot/chat_service_spec.rb | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/enterprise/app/helpers/captain/chat_helper.rb b/enterprise/app/helpers/captain/chat_helper.rb index 258328f9d..a10c9e797 100644 --- a/enterprise/app/helpers/captain/chat_helper.rb +++ b/enterprise/app/helpers/captain/chat_helper.rb @@ -35,7 +35,6 @@ module Captain::ChatHelper def handle_response(response) message = response.dig('choices', 0, 'message') - if message['tool_calls'] process_tool_calls(message['tool_calls']) else diff --git a/spec/enterprise/services/captain/copilot/chat_service_spec.rb b/spec/enterprise/services/captain/copilot/chat_service_spec.rb index 5e084a354..c4b759c85 100644 --- a/spec/enterprise/services/captain/copilot/chat_service_spec.rb +++ b/spec/enterprise/services/captain/copilot/chat_service_spec.rb @@ -8,10 +8,14 @@ RSpec.describe Captain::Copilot::ChatService do let(:mock_captain_agent) { instance_double(Captain::Agent) } let(:mock_captain_tool) { instance_double(Captain::Tool) } + let(:mock_openai_client) { instance_double(OpenAI::Client) } - describe '#execure' do + describe '#execute' do before do create(:installation_config) { create(:installation_config, name: 'CAPTAIN_OPEN_AI_API_KEY', value: 'test-key') } + allow(OpenAI::Client).to receive(:new).and_return(mock_openai_client) + allow(mock_openai_client).to receive(:chat).and_return({ choices: [{ message: { content: '{ "result": "Hey" }' } }] }.with_indifferent_access) + 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) @@ -23,7 +27,7 @@ RSpec.describe Captain::Copilot::ChatService do end it 'increments usage' do - described_class.new(assistant, { previous_messages: ['Hello'], conversation_history: 'Hi' }).execute('Hey') + described_class.new(assistant, { previous_messages: ['Hello'], conversation_history: 'Hi' }).generate_response('Hey') expect(account).to have_received(:increment_response_usage).once end end