Fix reseller package selection when older batches are exhausted
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-02-06 12:01:43 +01:00
parent 61d1bbc707
commit fa114ac0dc
5 changed files with 45 additions and 7 deletions

View File

@@ -181,4 +181,34 @@ class TenantModelTest extends TestCase
$this->assertFalse($tenant->consumeEventAllowance());
}
public function test_get_active_reseller_package_skips_exhausted_legacy_batches(): void
{
$tenant = Tenant::factory()->create();
$package = Package::factory()->reseller()->create([
'max_events_per_year' => 1,
]);
$exhaustedBatch = TenantPackage::factory()->for($tenant)->for($package)->create([
'used_events' => 1,
'active' => true,
'expires_at' => null,
'purchased_at' => now()->subDay(),
]);
$availableBatch = TenantPackage::factory()->for($tenant)->for($package)->create([
'used_events' => 0,
'active' => true,
'expires_at' => null,
'purchased_at' => now(),
]);
$resolved = $tenant->getActiveResellerPackage();
$this->assertNotNull($resolved);
$this->assertSame($availableBatch->id, $resolved?->id);
$this->assertNotSame($exhaustedBatch->id, $resolved?->id);
$this->assertTrue($tenant->hasEventAllowance());
}
}