2026-05-27 04:18:04 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Jobs\Supplier\CleanupInactiveSupplierProjectsJob;
|
|
|
|
|
use App\Models\Project;
|
|
|
|
|
use App\Models\SupplierProject;
|
|
|
|
|
use App\Models\Tenant;
|
2026-06-17 05:17:12 +03:00
|
|
|
use App\Services\Supplier\SupplierPortalClient;
|
2026-06-25 08:19:53 +03:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
use Tests\Concerns\SharesSupplierPdo;
|
2026-05-27 04:18:04 +03:00
|
|
|
|
2026-06-25 08:19:53 +03:00
|
|
|
uses(DatabaseTransactions::class);
|
|
|
|
|
uses(SharesSupplierPdo::class);
|
2026-06-25 07:39:51 +03:00
|
|
|
|
2026-05-27 04:18:04 +03:00
|
|
|
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,
|
|
|
|
|
]);
|
2026-06-17 05:17:12 +03:00
|
|
|
DB::table('project_supplier_links')->insert([
|
2026-05-27 04:18:04 +03:00
|
|
|
'project_id' => $project->id,
|
|
|
|
|
'supplier_project_id' => $sp->id,
|
|
|
|
|
'platform' => $sp->platform,
|
|
|
|
|
'subject_code' => null,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-06-17 05:17:12 +03:00
|
|
|
(new CleanupInactiveSupplierProjectsJob)->handle(app(SupplierPortalClient::class));
|
2026-05-27 04:18:04 +03:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2026-06-17 05:17:12 +03:00
|
|
|
(new CleanupInactiveSupplierProjectsJob)->handle(app(SupplierPortalClient::class));
|
2026-05-27 04:18:04 +03:00
|
|
|
|
|
|
|
|
expect($sp->fresh()->inactive_since)->not->toBeNull();
|
|
|
|
|
});
|