Files
portal/app/tests/Feature/Supplier/CleanupInactiveOnPivotTest.php
T

42 lines
1.4 KiB
PHP
Raw Normal View History

<?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();
});