diff --git a/app/tests/Feature/Jobs/RouteSupplierLeadJobTest.php b/app/tests/Feature/Jobs/RouteSupplierLeadJobTest.php index baa4131f..5bfc4f4b 100644 --- a/app/tests/Feature/Jobs/RouteSupplierLeadJobTest.php +++ b/app/tests/Feature/Jobs/RouteSupplierLeadJobTest.php @@ -46,27 +46,7 @@ function runRouteJob(int $supplierLeadId): void ); } -/** - * Link Лидерра-project to supplier_project via the new pivot (Plan 1 model). - * LeadRouter post-Plan-2 eligibility query reads project_supplier_links only — - * legacy supplier_b{1,2,3}_project_id FK is ignored for routing. - * - * Guarded against re-declaration — LeadRouterTest.php declares the same helper - * globally; Pest loads both files in one PHP process, so the second declaration - * would Fatal. Bodies are semantically identical. - */ -if (! function_exists('linkProjectToSupplier')) { - function linkProjectToSupplier(Project $project, SupplierProject $supplier): void - { - DB::table('project_supplier_links')->insert([ - 'project_id' => $project->id, - 'supplier_project_id' => $supplier->id, - 'platform' => $supplier->platform, - // @phpstan-ignore-next-line property.notFound — subject_code in $fillable/casts, IDE stubs lag - 'subject_code' => $supplier->subject_code, - ]); - } -} +// `linkProjectToSupplier` helper now lives in tests/Pest.php — single source. it('routes 1 lead to N tenants — creates N deal copies (sharing-model)', function (): void { $supplier = SupplierProject::factory()->create([ @@ -563,9 +543,7 @@ it('caps deal creation at 3 recipients and tags deal with subject from payload', 'tenant_id' => $t->id, 'is_active' => true, 'daily_limit_target' => 10, 'delivered_today' => 0, 'delivery_days_mask' => 127, ]); - DB::table('project_supplier_links')->insert([ - 'project_id' => $p->id, 'supplier_project_id' => $sp->id, 'platform' => 'B1', 'subject_code' => 82, - ]); + linkProjectToSupplier($p, $sp); } $lead = SupplierLead::factory()->create([ diff --git a/app/tests/Feature/Services/LeadRouterTest.php b/app/tests/Feature/Services/LeadRouterTest.php index 694c2550..a54747bb 100644 --- a/app/tests/Feature/Services/LeadRouterTest.php +++ b/app/tests/Feature/Services/LeadRouterTest.php @@ -19,20 +19,7 @@ beforeEach(function (): void { DB::statement("SELECT set_config('app.current_tenant_id', '0', true)"); }); -// Guarded — RouteSupplierLeadJobTest.php declares the same helper; Pest loads -// both files in one process, so unguarded redeclare would Fatal. -if (! function_exists('linkProjectToSupplier')) { - function linkProjectToSupplier(Project $project, SupplierProject $sp): void - { - DB::table('project_supplier_links')->insert([ - 'project_id' => $project->id, - 'supplier_project_id' => $sp->id, - 'platform' => $sp->platform, - // @phpstan-ignore-next-line property.notFound — subject_code is in $fillable/casts, IDE stubs lag - 'subject_code' => $sp->subject_code, - ]); - } -} +// `linkProjectToSupplier` helper now lives in tests/Pest.php — single source. it('returns project linked via pivot to the supplier_project', function (): void { $tenant = Tenant::factory()->create(['balance_leads' => 100]); diff --git a/app/tests/Pest.php b/app/tests/Pest.php index 5f4655de..86715d44 100644 --- a/app/tests/Pest.php +++ b/app/tests/Pest.php @@ -1,6 +1,9 @@ subject_code may be null. + */ +function linkProjectToSupplier(Project $project, SupplierProject $supplier): void +{ + DB::table('project_supplier_links')->insert([ + 'project_id' => $project->id, + 'supplier_project_id' => $supplier->id, + 'platform' => $supplier->platform, + // @phpstan-ignore-next-line property.notFound — subject_code is in $fillable/casts, IDE stubs lag + 'subject_code' => $supplier->subject_code, + ]); +}