Files
portal/app/tests/Feature/Autopodbor/CompetitorActiveRunApiTest.php
T

48 lines
2.1 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
use App\Models\AutopodborCompetitor;
use App\Models\AutopodborRun;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Queue;
use Tests\Concerns\SharesSupplierPdo;
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
beforeEach(fn () => Queue::fake());
it('GET competitor — отдаёт active_run, если по конкуренту ИДЁТ сбор (для подхвата индикатора)', function () {
$tenant = Tenant::factory()->create();
$user = User::factory()->create(['tenant_id' => $tenant->id]);
DB::statement('SET app.current_tenant_id = '.$tenant->id);
$comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'name' => 'ДСК', 'dedup_key' => 'dsk', 'box' => 'field']);
AutopodborRun::create([
'tenant_id' => $tenant->id, 'kind' => 'study', 'status' => 'running', 'region_code' => 24,
'params' => [], 'competitor_id' => $comp->id,
'progress' => ['stage' => 1, 'total' => 1, 'label' => 'Изучаю: ДСК'],
]);
$this->actingAs($user)->getJson("/api/autopodbor/competitors/{$comp->id}")
->assertOk()
->assertJsonPath('active_run.status', 'running')
->assertJsonPath('active_run.progress.label', 'Изучаю: ДСК');
});
it('GET competitor — active_run пуст, если сбор не идёт (завершён)', function () {
$tenant = Tenant::factory()->create();
$user = User::factory()->create(['tenant_id' => $tenant->id]);
DB::statement('SET app.current_tenant_id = '.$tenant->id);
$comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'name' => 'ДСК', 'dedup_key' => 'dsk', 'box' => 'field']);
AutopodborRun::create([
'tenant_id' => $tenant->id, 'kind' => 'study', 'status' => 'done', 'region_code' => 24,
'params' => [], 'competitor_id' => $comp->id,
]);
$this->actingAs($user)->getJson("/api/autopodbor/competitors/{$comp->id}")
->assertOk()
->assertJsonPath('active_run', null);
});