insert([ 'tenant_id' => $tenantId, 'deal_id' => 900000 + $i, 'deal_received_at' => $chargedAt, 'tier_no' => 1, 'price_per_lead_kopecks' => 50000, 'charge_source' => 'rub', 'charged_at' => $chargedAt, 'created_at' => now()->toDateTimeString(), ]); } } test('daysLeft = 0 если affordableLeads <= 0', function () { $tenant = Tenant::factory()->create(); expect(app(RunwayCalculator::class)->daysLeft($tenant->id, 0))->toBe(0); expect(app(RunwayCalculator::class)->daysLeft($tenant->id, -5))->toBe(0); }); test('daysLeft = null если нет списаний за 30 дней', function () { $tenant = Tenant::factory()->create(); expect(app(RunwayCalculator::class)->daysLeft($tenant->id, 100))->toBeNull(); }); test('daysLeft = floor(affordable / средний дневной за 30 дней)', function () { $tenant = Tenant::factory()->create(); seedLeadCharges($tenant->id, 30, now()->subDays(5)->toDateTimeString()); // 30/30 = 1 лид/день expect(app(RunwayCalculator::class)->daysLeft($tenant->id, 90))->toBe(90); }); test('daysLeft игнорирует списания старше 30 дней', function () { $tenant = Tenant::factory()->create(); seedLeadCharges($tenant->id, 30, now()->subDays(40)->toDateTimeString()); // вне окна expect(app(RunwayCalculator::class)->daysLeft($tenant->id, 90))->toBeNull(); });