test(supplier): pivot-link AutoPause+Billing tests + redeclare guard (Plan 2 cascade)
This commit is contained in:
@@ -19,15 +19,19 @@ beforeEach(function (): void {
|
||||
DB::statement("SELECT set_config('app.current_tenant_id', '0', true)");
|
||||
});
|
||||
|
||||
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,
|
||||
]);
|
||||
// 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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
it('returns project linked via pivot to the supplier_project', function (): void {
|
||||
|
||||
@@ -11,8 +11,10 @@ use App\Models\SupplierProject;
|
||||
use App\Models\Tenant;
|
||||
use App\Services\Billing\LedgerService;
|
||||
use App\Services\DuplicateDetector;
|
||||
use App\Services\LeadDistributor;
|
||||
use App\Services\LeadRouter;
|
||||
use App\Services\NotificationService;
|
||||
use App\Services\RegionTagResolver;
|
||||
use App\Services\SupplierProjects\SupplierProjectResolver;
|
||||
use Database\Seeders\PricingTierSeeder;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
@@ -47,6 +49,7 @@ function makeFlowWithBalance(array $balance): array
|
||||
'effective_daily_limit_today' => 10, 'delivered_today' => 0,
|
||||
'delivery_days_mask' => 127, 'region_mask' => 255,
|
||||
]);
|
||||
linkProjectToSupplier($project, $supplierProject);
|
||||
$lead = SupplierLead::factory()->create([
|
||||
'vid' => random_int(100_000_000, 999_999_999),
|
||||
'phone' => '79991234567',
|
||||
@@ -66,6 +69,8 @@ function runJob(int $leadId): void
|
||||
app(DuplicateDetector::class),
|
||||
app(NotificationService::class),
|
||||
app(LedgerService::class),
|
||||
app(LeadDistributor::class),
|
||||
app(RegionTagResolver::class),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -151,12 +156,14 @@ it('sharing-flow isolation: tenant A on zero paused, tenant B with balance recei
|
||||
'daily_limit_target' => 10, 'effective_daily_limit_today' => 10,
|
||||
'delivered_today' => 0, 'delivery_days_mask' => 127, 'region_mask' => 255,
|
||||
]);
|
||||
linkProjectToSupplier($projectA, $supplierProject);
|
||||
$projectB = Project::factory()->create([
|
||||
'tenant_id' => $tenantB->id, 'signal_type' => 'site', 'signal_identifier' => 'example.com',
|
||||
'supplier_b1_project_id' => $supplierProject->id, 'is_active' => true,
|
||||
'daily_limit_target' => 10, 'effective_daily_limit_today' => 10,
|
||||
'delivered_today' => 0, 'delivery_days_mask' => 127, 'region_mask' => 255,
|
||||
]);
|
||||
linkProjectToSupplier($projectB, $supplierProject);
|
||||
$lead = SupplierLead::factory()->create([
|
||||
'vid' => random_int(100_000_000, 999_999_999),
|
||||
'phone' => '79991234567',
|
||||
|
||||
@@ -13,8 +13,10 @@ use App\Models\SupplierProject;
|
||||
use App\Models\Tenant;
|
||||
use App\Services\Billing\LedgerService;
|
||||
use App\Services\DuplicateDetector;
|
||||
use App\Services\LeadDistributor;
|
||||
use App\Services\LeadRouter;
|
||||
use App\Services\NotificationService;
|
||||
use App\Services\RegionTagResolver;
|
||||
use App\Services\SupplierProjects\SupplierProjectResolver;
|
||||
use Database\Seeders\PricingTierSeeder;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
@@ -66,6 +68,7 @@ function prepareSharingFlow(int $tenantsCount, array $balances): array
|
||||
'delivery_days_mask' => 127,
|
||||
'region_mask' => 255,
|
||||
]);
|
||||
linkProjectToSupplier($project, $supplierProject);
|
||||
$tenants[] = $tenant;
|
||||
$projects[] = $project;
|
||||
}
|
||||
@@ -90,6 +93,8 @@ function dispatchJob(int $supplierLeadId): void
|
||||
app(DuplicateDetector::class),
|
||||
app(NotificationService::class),
|
||||
app(LedgerService::class),
|
||||
app(LeadDistributor::class),
|
||||
app(RegionTagResolver::class),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user