Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Jobs/WalletCheckTest.php
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | public function testHandleInitial(): void | ||||
$wallet->refresh(); | $wallet->refresh(); | ||||
$today_regexp = '/' . Carbon::now()->toDateString() . ' [0-9]{2}:[0-9]{2}:[0-9]{2}/'; | $today_regexp = '/' . Carbon::now()->toDateString() . ' [0-9]{2}:[0-9]{2}:[0-9]{2}/'; | ||||
$this->assertRegExp($today_regexp, $wallet->getSetting('balance_negative_since')); | $this->assertRegExp($today_regexp, $wallet->getSetting('balance_negative_since')); | ||||
$this->assertRegExp($today_regexp, $wallet->getSetting('balance_warning_initial')); | $this->assertRegExp($today_regexp, $wallet->getSetting('balance_warning_initial')); | ||||
} | } | ||||
/** | /** | ||||
* Test job handle, reminder notification | * Test job handle, top-up before reminder notification | ||||
* | * | ||||
* @depends testHandleInitial | * @depends testHandleInitial | ||||
*/ | */ | ||||
public function testHandleBeforeReminder(): void | |||||
{ | |||||
Mail::fake(); | |||||
$user = $this->getTestUser('ned@kolab.org'); | |||||
$wallet = $user->wallets()->first(); | |||||
$now = Carbon::now(); | |||||
// Balance turned negative 7-1 days ago | |||||
$wallet->setSetting('balance_negative_since', $now->subDays(7 - 1)->toDateTimeString()); | |||||
$job = new WalletCheck($wallet); | |||||
$res = $job->handle(); | |||||
Mail::assertNothingSent(); | |||||
// TODO: Test that it actually executed the topUpWallet() | |||||
$this->assertSame(WalletCheck::THRESHOLD_BEFORE_REMINDER, $res); | |||||
$this->assertFalse($user->fresh()->isSuspended()); | |||||
} | |||||
/** | |||||
* Test job handle, reminder notification | |||||
* | |||||
* @depends testHandleBeforeReminder | |||||
*/ | |||||
public function testHandleReminder(): void | public function testHandleReminder(): void | ||||
{ | { | ||||
Mail::fake(); | Mail::fake(); | ||||
$user = $this->getTestUser('ned@kolab.org'); | $user = $this->getTestUser('ned@kolab.org'); | ||||
$user->setSetting('external_email', 'external@test.com'); | $user->setSetting('external_email', 'external@test.com'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$now = Carbon::now(); | $now = Carbon::now(); | ||||
Show All 14 Lines | public function testHandleReminder(): void | ||||
Mail::fake(); | Mail::fake(); | ||||
$job = new WalletCheck($wallet); | $job = new WalletCheck($wallet); | ||||
$job->handle(); | $job->handle(); | ||||
Mail::assertNothingSent(); | Mail::assertNothingSent(); | ||||
} | } | ||||
/** | /** | ||||
* Test job handle, account suspending | * Test job handle, top-up wallet before account suspending | ||||
* | * | ||||
* @depends testHandleReminder | * @depends testHandleReminder | ||||
*/ | */ | ||||
public function testHandleBeforeSuspended(): void | |||||
{ | |||||
Mail::fake(); | |||||
$user = $this->getTestUser('ned@kolab.org'); | |||||
$wallet = $user->wallets()->first(); | |||||
$now = Carbon::now(); | |||||
// Balance turned negative 7+14-1 days ago | |||||
$days = 7 + 14 - 1; | |||||
$wallet->setSetting('balance_negative_since', $now->subDays($days)->toDateTimeString()); | |||||
$job = new WalletCheck($wallet); | |||||
$res = $job->handle(); | |||||
Mail::assertNothingSent(); | |||||
// TODO: Test that it actually executed the topUpWallet() | |||||
$this->assertSame(WalletCheck::THRESHOLD_BEFORE_SUSPEND, $res); | |||||
$this->assertFalse($user->fresh()->isSuspended()); | |||||
} | |||||
/** | |||||
* Test job handle, account suspending | |||||
* | |||||
* @depends testHandleBeforeSuspended | |||||
*/ | |||||
public function testHandleSuspended(): void | public function testHandleSuspended(): void | ||||
{ | { | ||||
Mail::fake(); | Mail::fake(); | ||||
$user = $this->getTestUser('ned@kolab.org'); | $user = $this->getTestUser('ned@kolab.org'); | ||||
$user->setSetting('external_email', 'external@test.com'); | $user->setSetting('external_email', 'external@test.com'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$now = Carbon::now(); | $now = Carbon::now(); | ||||
▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines |