diff --git a/app/app/Console/Commands/BillingPreflightInitialSweepCommand.php b/app/app/Console/Commands/BillingPreflightInitialSweepCommand.php new file mode 100644 index 00000000..59cb58a8 --- /dev/null +++ b/app/app/Console/Commands/BillingPreflightInitialSweepCommand.php @@ -0,0 +1,37 @@ +warn('Разовый преfflight всех тенантов. Запускать ОДИН раз после выкатки Spec C.'); + (new BalancePreflightSweepJob)->handle(); + $this->info('Initial sweep завершён.'); + + return self::SUCCESS; + } +} diff --git a/app/tests/Feature/Billing/BillingPreflightInitialSweepTest.php b/app/tests/Feature/Billing/BillingPreflightInitialSweepTest.php new file mode 100644 index 00000000..92b663e1 --- /dev/null +++ b/app/tests/Feature/Billing/BillingPreflightInitialSweepTest.php @@ -0,0 +1,38 @@ +create([ + 'tier_no' => 1, + 'leads_in_tier' => null, + 'price_per_lead_kopecks' => 5000, + 'is_active' => true, + 'effective_from' => now(), + ]); +}); + +it('freezes pre-existing underfunded tenant on first run', function () { + Mail::fake(); + // 0₽ + проекты на 25 лидов → должен быть заморожен. + $tenant = Tenant::factory()->create(['balance_rub' => '0.00', 'frozen_by_balance_at' => null]); + Project::factory()->for($tenant)->create(['is_active' => true, 'daily_limit_target' => 25]); + + $this->artisan('billing:preflight-initial-sweep')->assertSuccessful(); + + expect($tenant->fresh()->frozen_by_balance_at)->not->toBeNull(); + Mail::assertQueued(BalanceFrozenMail::class, fn ($mail) => $mail->tenant->id === $tenant->id); +});