refactor(tests): consolidate linkProjectToSupplier helper to tests/Pest.php (Plan 2 review I-1/I-2)
This commit is contained in:
@@ -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([
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\SupplierProject;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
/*
|
||||
@@ -50,3 +53,23 @@ function something()
|
||||
{
|
||||
// ..
|
||||
}
|
||||
|
||||
/**
|
||||
* Link a Лидерра-project to a supplier_project via the M:N pivot
|
||||
* (Plan 1 model). Post-Plan-2 LeadRouter eligibility queries the pivot
|
||||
* only; legacy supplier_b{1,2,3}_project_id FK is ignored for routing.
|
||||
*
|
||||
* Single source — replaces previous duplicated declarations in
|
||||
* LeadRouterTest.php / RouteSupplierLeadJobTest.php (Plan 2 cleanup).
|
||||
* pivot created_at has DEFAULT NOW(); supplier->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,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user