Files
portal/app/tests/Feature/Supplier/CleanupInactiveOnPivotTest.php
T
Дмитрий 4188fcbc36 fix(supplier): R-16 — cleanup uses pivot, not legacy FK
CleanupInactiveSupplierProjectsJob Phase A/B/C subquery determined
active supplier_projects through legacy supplier_b{1,2,3}_project_id FKs,
which are NULL for Plan 3+ projects (using project_supplier_links pivot).
After 180d TTL these supplier_projects would be deleted from supplier,
breaking real lead flow. Subquery now uses pivot.
2026-05-27 04:18:04 +03:00

42 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Jobs\Supplier\CleanupInactiveSupplierProjectsJob;
use App\Models\Project;
use App\Models\SupplierProject;
use App\Models\Tenant;
it('does not mark inactive supplier_project that has pivot link to active project', function () {
$tenant = Tenant::factory()->create();
$project = Project::factory()->for($tenant)->create([
'is_active' => true,
// легаси FK НЕ заполнены (Plan 3+ архитектура):
'supplier_b1_project_id' => null,
'supplier_b2_project_id' => null,
'supplier_b3_project_id' => null,
]);
$sp = SupplierProject::factory()->create([
'inactive_since' => null,
]);
\DB::table('project_supplier_links')->insert([
'project_id' => $project->id,
'supplier_project_id' => $sp->id,
'platform' => $sp->platform,
'subject_code' => null,
]);
(new CleanupInactiveSupplierProjectsJob)->handle(app(\App\Services\Supplier\SupplierPortalClient::class));
expect($sp->fresh()->inactive_since)->toBeNull();
});
it('marks supplier_project inactive when no pivot link exists', function () {
$sp = SupplierProject::factory()->create(['inactive_since' => null]);
// нет project_supplier_links
(new CleanupInactiveSupplierProjectsJob)->handle(app(\App\Services\Supplier\SupplierPortalClient::class));
expect($sp->fresh()->inactive_since)->not->toBeNull();
});