Update partner packages, copy, and demo switcher
This commit is contained in:
@@ -155,13 +155,17 @@ class EventControllerTest extends TenantTestCase
|
||||
{
|
||||
$tenant = $this->tenant;
|
||||
$eventType = EventType::factory()->create();
|
||||
$includedPackage = Package::factory()->endcustomer()->create([
|
||||
'slug' => 'standard',
|
||||
'gallery_days' => 30,
|
||||
]);
|
||||
$package = Package::factory()->create(['type' => 'reseller', 'max_events_per_year' => 1]);
|
||||
TenantPackage::factory()->create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'used_events' => 0,
|
||||
'active' => true,
|
||||
'expires_at' => now()->addYear(),
|
||||
'expires_at' => null,
|
||||
]);
|
||||
|
||||
// First event succeeds
|
||||
@@ -175,6 +179,13 @@ class EventControllerTest extends TenantTestCase
|
||||
|
||||
$response1->assertStatus(201);
|
||||
|
||||
$event = Event::where('tenant_id', $tenant->id)->where('slug', 'first-event')->firstOrFail();
|
||||
$this->assertDatabaseHas('event_packages', [
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $includedPackage->id,
|
||||
'purchased_price' => 0.00,
|
||||
]);
|
||||
|
||||
// Second event fails due to limit
|
||||
$response2 = $this->authenticatedRequest('POST', '/api/v1/tenant/events', [
|
||||
'name' => 'Second Event',
|
||||
@@ -188,6 +199,39 @@ class EventControllerTest extends TenantTestCase
|
||||
->assertJsonPath('error.code', 'event_limit_exceeded');
|
||||
}
|
||||
|
||||
public function test_create_event_rejects_unavailable_service_tier_for_partner_kontingent(): void
|
||||
{
|
||||
$tenant = $this->tenant;
|
||||
$eventType = EventType::factory()->create();
|
||||
|
||||
Package::factory()->endcustomer()->create(['slug' => 'standard', 'gallery_days' => 30]);
|
||||
Package::factory()->endcustomer()->create(['slug' => 'pro', 'gallery_days' => 30]);
|
||||
|
||||
$partnerPackage = Package::factory()->reseller()->create([
|
||||
'max_events_per_year' => 5,
|
||||
'included_package_slug' => 'standard',
|
||||
]);
|
||||
|
||||
TenantPackage::factory()->create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $partnerPackage->id,
|
||||
'used_events' => 0,
|
||||
'active' => true,
|
||||
'expires_at' => null,
|
||||
]);
|
||||
|
||||
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/events', [
|
||||
'name' => 'Premium Event',
|
||||
'slug' => 'premium-event',
|
||||
'event_date' => Carbon::now()->addDays(10)->toDateString(),
|
||||
'event_type_id' => $eventType->id,
|
||||
'service_package_slug' => 'pro',
|
||||
]);
|
||||
|
||||
$response->assertStatus(402)
|
||||
->assertJsonPath('error.code', 'event_tier_unavailable');
|
||||
}
|
||||
|
||||
public function test_update_event_accepts_live_show_settings(): void
|
||||
{
|
||||
$eventType = EventType::factory()->create();
|
||||
|
||||
@@ -34,7 +34,7 @@ class PackageLimitEvaluatorTest extends TestCase
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$violation = $this->evaluator->assessEventCreation($tenant);
|
||||
$violation = $this->evaluator->assessEventCreation($tenant, null);
|
||||
|
||||
$this->assertNull($violation);
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class PackageLimitEvaluatorTest extends TestCase
|
||||
|
||||
$tenant->refresh();
|
||||
|
||||
$violation = $this->evaluator->assessEventCreation($tenant);
|
||||
$violation = $this->evaluator->assessEventCreation($tenant, null);
|
||||
|
||||
$this->assertNotNull($violation);
|
||||
$this->assertSame('event_limit_exceeded', $violation['code']);
|
||||
|
||||
@@ -83,5 +83,6 @@ class TenantUsageTrackerTest extends TestCase
|
||||
$tenantPackage->refresh();
|
||||
|
||||
$this->assertNotNull($tenantPackage->event_limit_notified_at);
|
||||
$this->assertFalse($tenantPackage->active);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,4 +146,39 @@ class TenantModelTest extends TestCase
|
||||
$this->assertFalse($tenant->features['analytics']);
|
||||
}
|
||||
|
||||
public function test_consume_event_allowance_moves_to_next_credit_batch(): void
|
||||
{
|
||||
$tenant = Tenant::factory()->create();
|
||||
|
||||
$firstPackage = Package::factory()->reseller()->create([
|
||||
'max_events_per_year' => 1,
|
||||
]);
|
||||
|
||||
$secondPackage = Package::factory()->reseller()->create([
|
||||
'max_events_per_year' => 1,
|
||||
]);
|
||||
|
||||
$firstBatch = TenantPackage::factory()->for($tenant)->for($firstPackage)->create([
|
||||
'used_events' => 0,
|
||||
'active' => true,
|
||||
'expires_at' => null,
|
||||
'purchased_at' => now()->subDay(),
|
||||
]);
|
||||
|
||||
$secondBatch = TenantPackage::factory()->for($tenant)->for($secondPackage)->create([
|
||||
'used_events' => 0,
|
||||
'active' => true,
|
||||
'expires_at' => null,
|
||||
'purchased_at' => now(),
|
||||
]);
|
||||
|
||||
$this->assertTrue($tenant->consumeEventAllowance());
|
||||
$this->assertFalse($firstBatch->fresh()->active);
|
||||
$this->assertTrue($secondBatch->fresh()->active);
|
||||
|
||||
$this->assertTrue($tenant->consumeEventAllowance());
|
||||
$this->assertFalse($secondBatch->fresh()->active);
|
||||
|
||||
$this->assertFalse($tenant->consumeEventAllowance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class TenantPackageTest extends TestCase
|
||||
$this->assertTrue($tenantPackage->expires_at->lessThanOrEqualTo(now()->addYears(2)));
|
||||
}
|
||||
|
||||
public function test_reseller_packages_still_expire(): void
|
||||
public function test_reseller_packages_do_not_expire_by_default_but_can_be_expired(): void
|
||||
{
|
||||
$package = Package::factory()->reseller()->create(['max_events_per_year' => 5]);
|
||||
|
||||
@@ -41,8 +41,8 @@ class TenantPackageTest extends TestCase
|
||||
|
||||
$tenantPackage->refresh();
|
||||
|
||||
$this->assertNotNull($tenantPackage->expires_at);
|
||||
$this->assertTrue($tenantPackage->expires_at->isFuture());
|
||||
$this->assertNull($tenantPackage->expires_at);
|
||||
$this->assertTrue($tenantPackage->isActive());
|
||||
|
||||
$tenantPackage->forceFill(['expires_at' => now()->subDay()])->save();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user