Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/WalletTest.php
Show All 38 Lines | class WalletTest extends TestCase | ||||
{ | { | ||||
foreach ($this->users as $user) { | foreach ($this->users as $user) { | ||||
$this->deleteTestUser($user); | $this->deleteTestUser($user); | ||||
} | } | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test that turning wallet balance from negative to positive | * Test that turning wallet balance from negative to positive | ||||
* unsuspends the account | * unsuspends the account | ||||
*/ | */ | ||||
public function testBalancePositiveUnsuspend(): void | public function testBalancePositiveUnsuspend(): void | ||||
{ | { | ||||
$user = $this->getTestUser('UserWallet1@UserWallet.com'); | $user = $this->getTestUser('UserWallet1@UserWallet.com'); | ||||
$user->suspend(); | $user->suspend(); | ||||
Show All 26 Lines | public function testBalanceLastsUntil(): void | ||||
$user = $this->getTestUser('jane@kolabnow.com'); | $user = $this->getTestUser('jane@kolabnow.com'); | ||||
$package = Package::where('title', 'kolab')->first(); | $package = Package::where('title', 'kolab')->first(); | ||||
$user->assignPackage($package); | $user->assignPackage($package); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
// User/entitlements created today, balance=0 | // User/entitlements created today, balance=0 | ||||
$until = $wallet->balanceLastsUntil(); | $until = $wallet->balanceLastsUntil(); | ||||
$this->assertSame(Carbon::now()->toDateString(), $until->toDateString()); | $this->assertSame( | ||||
Carbon::now()->addMonthWithoutOverflow(1)->toDateString(), | |||||
$until->toDateString() | |||||
); | |||||
// User/entitlements created today, balance=-10 CHF | // User/entitlements created today, balance=-10 CHF | ||||
$wallet->balance = -1000; | $wallet->balance = -1000; | ||||
$until = $wallet->balanceLastsUntil(); | $until = $wallet->balanceLastsUntil(); | ||||
$this->assertSame(null, $until); | $this->assertSame(null, $until); | ||||
// User/entitlements created today, balance=-9,99 CHF (monthly cost) | // User/entitlements created today, balance=-9,99 CHF (monthly cost) | ||||
$wallet->balance = 999; | $wallet->balance = 999; | ||||
$until = $wallet->balanceLastsUntil(); | $until = $wallet->balanceLastsUntil(); | ||||
$daysInLastMonth = \App\Utils::daysInLastMonth(); | $daysInLastMonth = \App\Utils::daysInLastMonth(); | ||||
$this->assertSame( | $this->assertSame( | ||||
Carbon::now()->addDays($daysInLastMonth)->toDateString(), | Carbon::now()->addMonthsWithoutOverflow(1)->addDays($daysInLastMonth)->toDateString(), | ||||
$until->toDateString() | $until->toDateString() | ||||
); | ); | ||||
// Old entitlements, 100% discount | // Old entitlements, 100% discount | ||||
$this->backdateEntitlements($wallet->entitlements, Carbon::now()->subDays(40)); | $this->backdateEntitlements($wallet->entitlements, Carbon::now()->subDays(40)); | ||||
$discount = \App\Discount::where('discount', 100)->first(); | $discount = \App\Discount::where('discount', 100)->first(); | ||||
$wallet->discount()->associate($discount); | $wallet->discount()->associate($discount); | ||||
▲ Show 20 Lines • Show All 169 Lines • Show Last 20 Lines |