diff --git a/app/phpunit.xml b/app/phpunit.xml index dbb4d1c6..ca050ac8 100644 --- a/app/phpunit.xml +++ b/app/phpunit.xml @@ -34,6 +34,10 @@ + + + diff --git a/app/tests/Feature/Console/BillingMigrateLeadsToRubTest.php b/app/tests/Feature/Console/BillingMigrateLeadsToRubTest.php index 228d45ce..c2a082d3 100644 --- a/app/tests/Feature/Console/BillingMigrateLeadsToRubTest.php +++ b/app/tests/Feature/Console/BillingMigrateLeadsToRubTest.php @@ -55,18 +55,23 @@ it('is idempotent — second run is no-op', function () { $this->artisan('billing:migrate-leads-to-rub')->assertOk(); expect($tenant->fresh()->balance_rub)->toBe($balanceAfterFirst); - expect(BalanceTransaction::where('type', BalanceTransaction::TYPE_MIGRATION)->count())->toBe(1); + // Считаем операции миграции ТОЛЬКО своего тенанта — команда работает по всей базе, + // а в тест-БД могут быть закоммиченные тенанты от других прогонов (изоляция теста). + expect(BalanceTransaction::where('tenant_id', $tenant->id) + ->where('type', BalanceTransaction::TYPE_MIGRATION)->count())->toBe(1); }); it('skips tenants with balance_leads = 0', function () { - Tenant::factory()->create([ + $tenant = Tenant::factory()->create([ 'balance_leads' => 0, 'balance_rub' => '500.00', ]); $this->artisan('billing:migrate-leads-to-rub')->assertOk(); - expect(BalanceTransaction::where('type', BalanceTransaction::TYPE_MIGRATION)->count())->toBe(0); + // Только свой тенант: balance_leads=0 → не мигрируется → 0 операций (не считаем чужих). + expect(BalanceTransaction::where('tenant_id', $tenant->id) + ->where('type', BalanceTransaction::TYPE_MIGRATION)->count())->toBe(0); }); it('aborts if no active tier 1 configured', function () { diff --git a/app/tests/Feature/Reports/BillingSummaryProviderTest.php b/app/tests/Feature/Reports/BillingSummaryProviderTest.php index aa4aafa8..d465d27f 100644 --- a/app/tests/Feature/Reports/BillingSummaryProviderTest.php +++ b/app/tests/Feature/Reports/BillingSummaryProviderTest.php @@ -64,7 +64,10 @@ test('агрегирует balance_transactions по типу: count + сумм test('исключает транзакции вне периода', function () { seedBillingTx($this->tenant->id, 'topup', 5000); - seedBillingTx($this->tenant->id, 'topup', 1000, Carbon::now()->subMonths(3)); + // «Вне периода» берём из СЛЕДУЮЩЕГО месяца: партиции balance_transactions заводятся + // наперёд (pg_partman premake), а назад со временем удаляются — past-дата (subMonths) + // рано или поздно упирается в отсутствующую старую партицию. + seedBillingTx($this->tenant->id, 'topup', 1000, Carbon::now()->addMonth()->day(15)); $rows = (new BillingSummaryProvider)->rows(billingJob($this->tenant->id));