Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/EntitlementTest.php
Show All 30 Lines | class EntitlementTest extends TestCase | ||||
{ | { | ||||
$this->deleteTestUser('entitlement-test@kolabnow.com'); | $this->deleteTestUser('entitlement-test@kolabnow.com'); | ||||
$this->deleteTestUser('entitled-user@custom-domain.com'); | $this->deleteTestUser('entitled-user@custom-domain.com'); | ||||
$this->deleteTestDomain('custom-domain.com'); | $this->deleteTestDomain('custom-domain.com'); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | |||||
* Test for Entitlement::costsPerDay() | |||||
*/ | |||||
public function testCostsPerDay(): void | public function testCostsPerDay(): void | ||||
{ | { | ||||
// 444 | // 444 | ||||
// 28 days: 15.86 | // 28 days: 15.86 | ||||
// 31 days: 14.32 | // 31 days: 14.32 | ||||
$user = $this->getTestUser('entitlement-test@kolabnow.com'); | $user = $this->getTestUser('entitlement-test@kolabnow.com'); | ||||
$package = Package::where('title', 'kolab')->first(); | $package = Package::where('title', 'kolab')->first(); | ||||
$mailbox = Sku::where('title', 'mailbox')->first(); | $mailbox = Sku::where('title', 'mailbox')->first(); | ||||
$user->assignPackage($package); | $user->assignPackage($package); | ||||
$entitlement = $user->entitlements->where('sku_id', $mailbox->id)->first(); | $entitlement = $user->entitlements->where('sku_id', $mailbox->id)->first(); | ||||
$costsPerDay = $entitlement->costsPerDay(); | $costsPerDay = $entitlement->costsPerDay(); | ||||
$this->assertTrue($costsPerDay < 15.86); | $this->assertTrue($costsPerDay < 15.86); | ||||
$this->assertTrue($costsPerDay > 14.32); | $this->assertTrue($costsPerDay > 14.32); | ||||
} | } | ||||
/** | /** | ||||
* Tests for User::AddEntitlement() | * Tests for entitlements | ||||
* @todo This really should be in User or Wallet tests file | |||||
*/ | */ | ||||
public function testUserAddEntitlement(): void | public function testEntitlements(): void | ||||
{ | { | ||||
$packageDomain = Package::where('title', 'domain-hosting')->first(); | $packageDomain = Package::where('title', 'domain-hosting')->first(); | ||||
$packageKolab = Package::where('title', 'kolab')->first(); | $packageKolab = Package::where('title', 'kolab')->first(); | ||||
$skuDomain = Sku::where('title', 'domain-hosting')->first(); | $skuDomain = Sku::where('title', 'domain-hosting')->first(); | ||||
$skuMailbox = Sku::where('title', 'mailbox')->first(); | $skuMailbox = Sku::where('title', 'mailbox')->first(); | ||||
$owner = $this->getTestUser('entitlement-test@kolabnow.com'); | $owner = $this->getTestUser('entitlement-test@kolabnow.com'); | ||||
Show All 24 Lines | public function testEntitlements(): void | ||||
Carbon::now()->subMonthsWithoutOverflow(1) | Carbon::now()->subMonthsWithoutOverflow(1) | ||||
); | ); | ||||
$wallet->chargeEntitlements(); | $wallet->chargeEntitlements(); | ||||
$this->assertTrue($wallet->fresh()->balance < 0); | $this->assertTrue($wallet->fresh()->balance < 0); | ||||
} | } | ||||
public function testAddExistingEntitlement(): void | /** | ||||
{ | * @todo This really should be in User tests file | ||||
$this->markTestIncomplete(); | */ | ||||
} | |||||
public function testEntitlementFunctions(): void | public function testEntitlementFunctions(): void | ||||
{ | { | ||||
$user = $this->getTestUser('entitlement-test@kolabnow.com'); | $user = $this->getTestUser('entitlement-test@kolabnow.com'); | ||||
$package = \App\Package::where('title', 'kolab')->first(); | $package = \App\Package::where('title', 'kolab')->first(); | ||||
$user->assignPackage($package); | $user->assignPackage($package); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$this->assertNotNull($wallet); | $this->assertNotNull($wallet); | ||||
$sku = \App\Sku::where('title', 'mailbox')->first(); | $sku = \App\Sku::where('title', 'mailbox')->first(); | ||||
$this->assertNotNull($sku); | |||||
$entitlement = Entitlement::where('wallet_id', $wallet->id) | $entitlement = Entitlement::where('wallet_id', $wallet->id) | ||||
->where('sku_id', $sku->id)->first(); | ->where('sku_id', $sku->id)->first(); | ||||
$this->assertNotNull($entitlement); | $this->assertNotNull($entitlement); | ||||
$this->assertSame($sku->id, $entitlement->sku->id); | |||||
$eSKU = $entitlement->sku; | $this->assertSame($wallet->id, $entitlement->wallet->id); | ||||
$this->assertSame($sku->id, $eSKU->id); | $this->assertEquals($user->id, $entitlement->entitleable->id); | ||||
$this->assertTrue($entitlement->entitleable instanceof \App\User); | |||||
$eWallet = $entitlement->wallet; | |||||
$this->assertSame($wallet->id, $eWallet->id); | |||||
$eEntitleable = $entitlement->entitleable; | |||||
$this->assertEquals($user->id, $eEntitleable->id); | |||||
$this->assertTrue($eEntitleable instanceof \App\User); | |||||
} | } | ||||
/** | |||||
* @todo This really should be in User or Wallet tests file | |||||
*/ | |||||
public function testBillDeletedEntitlement(): void | public function testBillDeletedEntitlement(): void | ||||
{ | { | ||||
$user = $this->getTestUser('entitlement-test@kolabnow.com'); | $user = $this->getTestUser('entitlement-test@kolabnow.com'); | ||||
$package = \App\Package::where('title', 'kolab')->first(); | $package = \App\Package::where('title', 'kolab')->first(); | ||||
$storage = \App\Sku::where('title', 'storage')->first(); | $storage = \App\Sku::where('title', 'storage')->first(); | ||||
$user->assignPackage($package); | $user->assignPackage($package); | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |