Fix reseller package selection when older batches are exhausted
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user