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

39 lines
1.4 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
use App\Models\AutopodborRun;
use App\Models\Tenant;
use App\Services\Autopodbor\RunProgressChannel;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Tests\Concerns\SharesSupplierPdo;
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
it('привязанный канал пишет этап {stage,total,label} в прогон', function () {
$tenant = Tenant::factory()->create();
DB::statement('SET app.current_tenant_id = '.$tenant->id);
$run = AutopodborRun::create([
'tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'running',
'region_code' => 16, 'params' => [],
]);
$ch = app(RunProgressChannel::class);
$ch->bind($run->id);
$ch->stage(2, 4, 'Ищем фирмы в справочниках');
// Порядок ключей в jsonb Postgres не сохраняет — сравниваем по парам ключ/значение.
expect($run->fresh()->progress)->toEqual([
'stage' => 2, 'total' => 4, 'label' => 'Ищем фирмы в справочниках',
]);
});
it('канал без привязки (bind null) — тихо ничего не делает и не падает', function () {
$ch = app(RunProgressChannel::class);
$ch->bind(null);
$ch->stage(1, 1, 'что-то');
expect(true)->toBeTrue();
});