Files
portal/app/tests/Feature/Models/PricingTierTest.php
T
Дмитрий 1e3c157603 fix(test): Plan 4 Task 1 regression — PricingTierTest::scopeActive baseline-aware
Task 1 (a907fea) добавил $this->call(PricingTierSeeder::class) в DatabaseSeeder,
который автоматически seed'ит 7 ступеней при migrate:fresh --seed на dev/testing.
Существующий PricingTierTest::scopeActive ожидал empty pricing_tiers до factory,
поэтому ->count() == 1 → 8 fail в isolation (pest tests/Feature/Models/PricingTierTest.php).

Fix: scopeActive теперь считает baseline = PricingTier::active()->count() ДО factory create,
ожидает baseline + 1 после factory (1 активный + past, 1 inactive, 1 active + future).

PricingTierTest::current() — не затронут: keyBy('tier_no') корректно перезаписывает
seed-rows (effective_from='1970-01-01') свежими factory-rows (effective_from=now()->subDay()).

Verified:
- pest tests/Feature/Models/PricingTierTest.php — 4/4 PASS, 12 assertions
- pest --parallel — 619 passed / 3 skipped / 0 failed / 1923 assertions

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 08:59:06 +03:00

64 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
use App\Models\PricingTier;
use Illuminate\Foundation\Testing\DatabaseTransactions;
uses(DatabaseTransactions::class);
test('PricingTier can be created via factory', function () {
$t = PricingTier::factory()->create();
expect($t->tier_no)->toBeInt()->toBeBetween(1, 7);
expect($t->price_per_lead_kopecks)->toBeInt()->toBeGreaterThan(0);
});
test('priceRubles accessor converts kopecks to rubles', function () {
$t = PricingTier::factory()->create([
'tier_no' => 1,
'price_per_lead_kopecks' => 6000,
]);
expect($t->price_rubles)->toBe(60.0);
});
test('scopeActive returns only is_active=true with effective_from <= today', function () {
// baseline: PricingTierSeeder seed'ит 7 ступеней с effective_from='1970-01-01' через
// DatabaseSeeder (Plan 4 Task 1). Тест проверяет delta от baseline после factory-create.
$baseline = PricingTier::active()->count();
PricingTier::factory()->create([
'is_active' => true,
'effective_from' => now()->subDay(),
'tier_no' => 1,
]);
PricingTier::factory()->create([
'is_active' => false,
'effective_from' => now()->subDay(),
'tier_no' => 2,
]);
PricingTier::factory()->create([
'is_active' => true,
'effective_from' => now()->addDay(),
'tier_no' => 3,
]);
expect(PricingTier::active()->count())->toBe($baseline + 1);
});
test('current() returns today active tier set keyed by tier_no', function () {
foreach (range(1, 7) as $n) {
PricingTier::factory()->create([
'tier_no' => $n,
'is_active' => true,
'effective_from' => now()->subDay(),
'leads_in_tier' => $n === 7 ? null : 100,
'price_per_lead_kopecks' => 7000 - ($n * 500),
]);
}
$current = PricingTier::current();
expect($current)->toHaveCount(7);
expect($current[1]->price_per_lead_kopecks)->toBe(6500);
expect($current[7]->leads_in_tier)->toBeNull();
});