From ce822e1e58b20a0070428259d41204e710a53ad2 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 14 Jan 2026 11:30:29 +0530 Subject: [PATCH] test: captain api helper --- .../concerns/captain_featurable_spec.rb | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/spec/models/concerns/captain_featurable_spec.rb b/spec/models/concerns/captain_featurable_spec.rb index 7221ad055..8af9e5489 100644 --- a/spec/models/concerns/captain_featurable_spec.rb +++ b/spec/models/concerns/captain_featurable_spec.rb @@ -131,4 +131,48 @@ RSpec.describe CaptainFeaturable do end end end + + describe '#captain_api_key' do + before do + create(:installation_config, name: 'CAPTAIN_OPEN_AI_API_KEY', value: 'system-key') + end + + context 'when openai hook is configured with api key' do + before do + create(:integrations_hook, account: account, app_id: 'openai', status: 'enabled', settings: { 'api_key' => 'hook-key' }) + end + + it 'returns the hook api key' do + expect(account.captain_api_key).to eq('hook-key') + end + + it 'returns true for using_openai_hook_key?' do + expect(account.using_openai_hook_key?).to be true + end + end + + context 'when openai hook is not configured' do + it 'returns the system api key' do + expect(account.captain_api_key).to eq('system-key') + end + + it 'returns false for using_openai_hook_key?' do + expect(account.using_openai_hook_key?).to be false + end + end + + context 'when openai hook is disabled' do + before do + create(:integrations_hook, account: account, app_id: 'openai', status: 'disabled', settings: { 'api_key' => 'hook-key' }) + end + + it 'returns the system api key' do + expect(account.captain_api_key).to eq('system-key') + end + + it 'returns false for using_openai_hook_key?' do + expect(account.using_openai_hook_key?).to be false + end + end + end end