Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/EntitlementTest.php
Show First 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | class EntitlementTest extends TestCase | ||||
/** | /** | ||||
* @todo This really should be in User or Wallet tests file | * @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); | ||||
// some additional SKUs so we have something to delete. | // some additional SKUs so we have something to delete. | ||||
$user->assignSku($storage, 4); | $user->assignSku($storage, 4); | ||||
// the mailbox, the groupware, the 2 original storage and the additional 4 | // the mailbox, the groupware, the 2 original storage and the additional 4 | ||||
$this->assertCount(8, $user->fresh()->entitlements); | $this->assertCount(8, $user->fresh()->entitlements); | ||||
Show All 27 Lines | public function testBillDeletedEntitlement(): void | ||||
$this->assertTrue($wallet->balance >= $balance - $max); | $this->assertTrue($wallet->balance >= $balance - $max); | ||||
$this->assertTrue($wallet->balance <= $balance - $min); | $this->assertTrue($wallet->balance <= $balance - $min); | ||||
$transactions = \App\Transaction::where('object_id', $wallet->id) | $transactions = \App\Transaction::where('object_id', $wallet->id) | ||||
->where('object_type', \App\Wallet::class)->get(); | ->where('object_type', \App\Wallet::class)->get(); | ||||
// one round of the monthly invoicing, four sku deletions getting invoiced | // one round of the monthly invoicing, four sku deletions getting invoiced | ||||
$this->assertCount(5, $transactions); | $this->assertCount(5, $transactions); | ||||
// Test that deleting an entitlement on a degraded account costs nothing | |||||
$balance = $wallet->balance; | |||||
User::where('id', $user->id)->update(['status' => $user->status | User::STATUS_DEGRADED]); | |||||
$backdate = Carbon::now()->subWeeks(7); | |||||
$this->backdateEntitlements($user->entitlements()->get(), $backdate); | |||||
$groupware = \App\Sku::where('title', 'groupware')->first(); | |||||
$entitlement = $wallet->entitlements()->where('sku_id', $groupware->id)->first(); | |||||
$entitlement->delete(); | |||||
$this->assertSame($wallet->refresh()->balance, $balance); | |||||
} | } | ||||
} | } |