Files
portal/app/tests/Feature/Billing/BillingPreflightInitialSweepTest.php
T
Дмитрий fe4a409480 feat(billing-v2-c): one-time billing:preflight-initial-sweep
Task 1.9 плана 2026-05-24-billing-v2-spec-c-preflight-vtb.

Разовая artisan-команда для запуска при выкатке Spec C — прогоняет
BalancePreflightSweepJob по всем тенантам, замораживает legacy-
тенантов в минусе. Идемпотентна (sweep-job triggers только на
active↔frozen переходах, стабильное состояние не трогает).

TDD: 1 тест GREEN.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 20:39:20 +03:00

39 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Mail\BalanceFrozenMail;
use App\Models\PricingTier;
use App\Models\Project;
use App\Models\Tenant;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Tests\Concerns\SharesSupplierPdo;
uses(DatabaseTransactions::class);
uses(SharesSupplierPdo::class);
beforeEach(function () {
DB::statement("SELECT set_config('app.current_tenant_id', '0', true)");
PricingTier::query()->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);
});