Files
ladill-woo-manager/tests/Feature/WooAfiaTest.php
T
isaaccladandCursor 26b1d5b433
Deploy Ladill Woo Manager / deploy (push) Successful in 1m19s
Wire Afia AI assistant for Woo Manager via platform relay.
The chat panel and POST /ai/chat route were missing after the Invoice scaffold; Afia now relays through the platform when no local OpenAI key is set.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 01:23:21 +00:00

63 lines
2.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use App\Services\Afia\AfiaService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class WooAfiaTest extends TestCase
{
use RefreshDatabase;
public function test_dashboard_includes_afia_panel_and_chat_route(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('woo.dashboard'))
->assertOk()
->assertSee('Open Afia AI assistant', false)
->assertSee('Woo Manager assistant', false)
->assertSee(route('woo.ai.chat'), false);
}
public function test_afia_chat_returns_reply_when_enabled(): void
{
config(['afia.enabled' => true, 'afia.api_key' => 'test-key']);
$this->mock(AfiaService::class, function ($mock) {
$mock->shouldReceive('enabled')->andReturn(true);
$mock->shouldReceive('chat')->once()->andReturn('Install the Ladill plugin and click Connect with Ladill.');
});
$this->actingAs(User::factory()->create())
->postJson(route('woo.ai.chat'), ['message' => 'How do I connect my store?'])
->assertOk()
->assertJsonPath('reply', 'Install the Ladill plugin and click Connect with Ladill.');
}
public function test_afia_chat_uses_platform_relay_when_local_key_missing(): void
{
config([
'afia.enabled' => true,
'afia.api_key' => '',
'afia.platform_api_url' => 'https://platform.test/api',
'afia.platform_api_key' => 'woo-relay-key',
]);
Http::fake([
'platform.test/api/afia/chat' => Http::response([
'reply' => 'Use Sync from store on the Orders page.',
]),
]);
$this->actingAs(User::factory()->create())
->postJson(route('woo.ai.chat'), ['message' => 'How do I sync orders?'])
->assertOk()
->assertJsonPath('reply', 'Use Sync from store on the Orders page.');
}
}