From c71c7df3bad73e333a20bcbbc3e7e72dd6d2920f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Thu, 25 Jun 2026 05:20:14 +0300 Subject: [PATCH] =?UTF-8?q?test:=20=D0=BA=D0=B0=D0=BF=D1=87=D0=B0-=D0=B4?= =?UTF-8?q?=D1=80=D0=B0=D0=B9=D0=B2=D0=B5=D1=80=20null=20=D0=B2=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B0=D1=85=20=D0=BF=D0=BB=D1=8E=D1=81=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BE=D0=BB=D1=8F=D1=86=D0=B8=D1=8F=20migrate=20?= =?UTF-8?q?=D0=B8=20billing-summary=20=D0=BE=D1=82=20=D1=81=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=8F=D0=BD=D0=B8=D1=8F=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Капча: добавлен тестовый драйвер CAPTCHA_DRIVER=null и CAPTCHA_FAKE_PASSES в phpunit.xml, иначе тесты наследовали боевой yandex из .env и регистрация падала на проверке я не робот. Плюс изоляция двух тестов от состояния учебной базы: BillingMigrateLeadsToRubTest считает операции своего тенанта, BillingSummaryProviderTest берёт дату вне периода из следующего месяца. Co-Authored-By: Claude Opus 4.8 (1M context) --- app/phpunit.xml | 4 ++++ .../Feature/Console/BillingMigrateLeadsToRubTest.php | 11 ++++++++--- .../Feature/Reports/BillingSummaryProviderTest.php | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) 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));