test(Panel::class, ['tab' => 'integrations']) ->assertSee('Integracja AI'); }); test('saving the AI config persists settings and encrypts the api key at rest', function () { $admin = adminUser(); Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations']) ->set('aiConfig.enabled', true) ->set('aiConfig.baseUrl', 'https://api.groq.test/openai/v1') ->set('aiConfig.apiKey', 'super-secret-key') ->set('aiConfig.model', 'llama-3.3-70b-versatile') ->set('aiConfig.verifySsl', true) ->call('saveAiConfig') ->assertOk(); expect(Settings::get('ai_base_url'))->toBe('https://api.groq.test/openai/v1'); expect(Settings::get('ai_model'))->toBe('llama-3.3-70b-versatile'); expect(Settings::get('ai_api_key'))->toBe('super-secret-key'); $stored = Setting::query()->where('key', 'ai_api_key')->value('value'); expect($stored)->not->toBe('super-secret-key'); }); test('leaving the api key field blank on save keeps the previously stored key', function () { Settings::set('ai_api_key', 'already-stored-key'); $admin = adminUser(); Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations']) ->set('aiConfig.enabled', true) ->set('aiConfig.baseUrl', 'https://api.groq.test/openai/v1') ->set('aiConfig.model', 'llama-3.3-70b-versatile') ->call('saveAiConfig') ->assertOk(); expect(Settings::get('ai_api_key'))->toBe('already-stored-key'); }); test('testAiConnection reports the result of a live probe using unsaved form values', function () { Http::fake(['api.groq.test/*' => Http::response(['choices' => [['message' => ['content' => 'pong']]]])]); $admin = adminUser(); Livewire::actingAs($admin)->test(Panel::class, ['tab' => 'integrations']) ->set('aiConfig.enabled', true) ->set('aiConfig.baseUrl', 'https://api.groq.test/openai/v1') ->set('aiConfig.apiKey', 'key') ->set('aiConfig.model', 'llama-3.3-70b-versatile') ->call('testAiConnection') ->assertSet('aiTestResult', 'ok'); });