6a0635e60a
Клиент ушёл со страницы во время сбора и вернулся — индикатор пропадал (жил только на опросе в памяти браузера), казалось, что процесс исчез. - competitor-эндпоинт отдаёт active_run (идущий по конкуренту сбор) — тест - loadCompetitor подхватывает active_run в currentRun (не затирая итог завершённого) - onMounted возобновляет опрос, если сбор ещё идёт → индикатор оживает, дожидаемся итога - тесты: active_run (бэк), loadCompetitor подхват/сохранение, подхват опроса на экране Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
2.1 KiB
PHP
48 lines
2.1 KiB
PHP
<?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);
|
|
});
|