Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/SkuTest.php
Show All 26 Lines | class SkuTest extends TestCase | ||||
} | } | ||||
public function testPackageEntitlements(): void | public function testPackageEntitlements(): void | ||||
{ | { | ||||
$user = $this->getTestUser('jane@kolabnow.com'); | $user = $this->getTestUser('jane@kolabnow.com'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$package = Package::where('title', 'lite')->first(); | $package = Package::withEnvTenantContext()->where('title', 'lite')->first(); | ||||
$sku_mailbox = Sku::where('title', 'mailbox')->first(); | |||||
$sku_storage = Sku::where('title', 'storage')->first(); | |||||
$user = $user->assignPackage($package); | $user = $user->assignPackage($package); | ||||
$this->backdateEntitlements($user->fresh()->entitlements, Carbon::now()->subMonthsWithoutOverflow(1)); | $this->backdateEntitlements($user->fresh()->entitlements, Carbon::now()->subMonthsWithoutOverflow(1)); | ||||
$wallet->chargeEntitlements(); | $wallet->chargeEntitlements(); | ||||
$this->assertTrue($wallet->balance < 0); | $this->assertTrue($wallet->balance < 0); | ||||
} | } | ||||
public function testSkuEntitlements(): void | public function testSkuEntitlements(): void | ||||
{ | { | ||||
$this->assertCount(4, Sku::where('title', 'mailbox')->first()->entitlements); | $this->assertCount(5, Sku::withEnvTenantContext()->where('title', 'mailbox')->first()->entitlements); | ||||
} | } | ||||
public function testSkuPackages(): void | public function testSkuPackages(): void | ||||
{ | { | ||||
$this->assertCount(2, Sku::where('title', 'mailbox')->first()->packages); | $this->assertCount(2, Sku::withEnvTenantContext()->where('title', 'mailbox')->first()->packages); | ||||
} | } | ||||
public function testSkuHandlerDomainHosting(): void | public function testSkuHandlerDomainHosting(): void | ||||
{ | { | ||||
$sku = Sku::where('title', 'domain-hosting')->first(); | $sku = Sku::withEnvTenantContext()->where('title', 'domain-hosting')->first(); | ||||
$entitlement = $sku->entitlements->first(); | $entitlement = $sku->entitlements->first(); | ||||
$this->assertSame( | $this->assertSame( | ||||
Handlers\DomainHosting::entitleableClass(), | Handlers\DomainHosting::entitleableClass(), | ||||
$entitlement->entitleable_type | $entitlement->entitleable_type | ||||
); | ); | ||||
} | } | ||||
public function testSkuHandlerMailbox(): void | public function testSkuHandlerMailbox(): void | ||||
{ | { | ||||
$sku = Sku::where('title', 'mailbox')->first(); | $sku = Sku::withEnvTenantContext()->where('title', 'mailbox')->first(); | ||||
$entitlement = $sku->entitlements->first(); | $entitlement = $sku->entitlements->first(); | ||||
$this->assertSame( | $this->assertSame( | ||||
Handlers\Mailbox::entitleableClass(), | Handlers\Mailbox::entitleableClass(), | ||||
$entitlement->entitleable_type | $entitlement->entitleable_type | ||||
); | ); | ||||
} | } | ||||
public function testSkuHandlerStorage(): void | public function testSkuHandlerStorage(): void | ||||
{ | { | ||||
$sku = Sku::where('title', 'storage')->first(); | $sku = Sku::withEnvTenantContext()->where('title', 'storage')->first(); | ||||
$entitlement = $sku->entitlements->first(); | $entitlement = $sku->entitlements->first(); | ||||
$this->assertSame( | $this->assertSame( | ||||
Handlers\Storage::entitleableClass(), | Handlers\Storage::entitleableClass(), | ||||
$entitlement->entitleable_type | $entitlement->entitleable_type | ||||
); | ); | ||||
} | } | ||||
public function testSkuTenant(): void | public function testSkuTenant(): void | ||||
{ | { | ||||
$sku = Sku::where('title', 'storage')->first(); | $sku = Sku::withEnvTenantContext()->where('title', 'storage')->first(); | ||||
$tenant = $sku->tenant()->first(); | $tenant = $sku->tenant()->first(); | ||||
$this->assertInstanceof(\App\Tenant::class, $tenant); | $this->assertInstanceof(\App\Tenant::class, $tenant); | ||||
$this->assertSame(1, $tenant->id); | |||||
$tenant = $sku->tenant; | $tenant = $sku->tenant; | ||||
$this->assertInstanceof(\App\Tenant::class, $tenant); | $this->assertInstanceof(\App\Tenant::class, $tenant); | ||||
$this->assertSame(1, $tenant->id); | |||||
} | } | ||||
} | } |