Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Console/Wallet/TrialEndTest.php
Show All 10 Lines | |||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->deleteTestUser('wallets-controller@kolabnow.com'); | $this->deleteTestUser('test-user1@kolabnow.com'); | ||||
$this->deleteTestUser('test-user22@kolabnow.com'); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('wallets-controller@kolabnow.com'); | $this->deleteTestUser('test-user1@kolabnow.com'); | ||||
$this->deleteTestUser('test-user22@kolabnow.com'); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test command run | * Test command run | ||||
*/ | */ | ||||
public function testHandle(): void | public function testHandle(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$user = $this->getTestUser('wallets-controller@kolabnow.com', [ | $package = \App\Package::withEnvTenantContext()->where('title', 'lite')->first(); | ||||
$user = $this->getTestUser('test-user1@kolabnow.com', [ | |||||
'status' => User::STATUS_IMAP_READY | User::STATUS_LDAP_READY | User::STATUS_ACTIVE, | 'status' => User::STATUS_IMAP_READY | User::STATUS_LDAP_READY | User::STATUS_ACTIVE, | ||||
]); | ]); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$user->assignPackage($package); | |||||
DB::table('users')->update(['created_at' => \now()->clone()->subMonthsNoOverflow(2)->subHours(1)]); | DB::table('users')->update(['created_at' => \now()->clone()->subMonthsNoOverflow(2)->subHours(1)]); | ||||
// Expect no wallets in after-trial state | // No wallets in after-trial state, no email sent | ||||
Queue::fake(); | |||||
$code = \Artisan::call("wallet:trial-end"); | |||||
Queue::assertNothingPushed(); | |||||
// Expect no email sent (out of time boundaries) | |||||
$user->created_at = \now()->clone()->subMonthsNoOverflow(1)->addHour(); | |||||
$user->save(); | |||||
Queue::fake(); | Queue::fake(); | ||||
$code = \Artisan::call("wallet:trial-end"); | $code = \Artisan::call("wallet:trial-end"); | ||||
Queue::assertNothingPushed(); | Queue::assertNothingPushed(); | ||||
// Test an email sent | // Test an email sent | ||||
$user->created_at = \now()->clone()->subMonthNoOverflow(); | $user->created_at = \now()->clone()->subMonthsNoOverflow(1); | ||||
$user->save(); | $user->save(); | ||||
Queue::fake(); | Queue::fake(); | ||||
$code = \Artisan::call("wallet:trial-end"); | $code = \Artisan::call("wallet:trial-end"); | ||||
Queue::assertPushed(\App\Jobs\TrialEndEmail::class, 1); | Queue::assertPushed(\App\Jobs\TrialEndEmail::class, 1); | ||||
Queue::assertPushed(\App\Jobs\TrialEndEmail::class, function ($job) use ($user) { | Queue::assertPushed(\App\Jobs\TrialEndEmail::class, function ($job) use ($user) { | ||||
$job_user = TestCase::getObjectProperty($job, 'account'); | $job_user = TestCase::getObjectProperty($job, 'account'); | ||||
return $job_user->id === $user->id; | return $job_user->id === $user->id; | ||||
Show All 21 Lines | public function testHandle(): void | ||||
$user->save(); | $user->save(); | ||||
$user->delete(); | $user->delete(); | ||||
Queue::fake(); | Queue::fake(); | ||||
$code = \Artisan::call("wallet:trial-end"); | $code = \Artisan::call("wallet:trial-end"); | ||||
Queue::assertNothingPushed(); | Queue::assertNothingPushed(); | ||||
$this->assertNull($wallet->getSetting('trial_end_notice')); | $this->assertNull($wallet->getSetting('trial_end_notice')); | ||||
// Make sure the non-controller users are omitted | |||||
$user2 = $this->getTestUser('test-user2@kolabnow.com', [ | |||||
'status' => User::STATUS_IMAP_READY | User::STATUS_LDAP_READY | User::STATUS_ACTIVE, | |||||
]); | |||||
$user->assignPackage($package, $user2); | |||||
$user2->created_at = \now()->clone()->subMonthsNoOverflow(1); | |||||
$user2->save(); | |||||
Queue::fake(); | |||||
$code = \Artisan::call("wallet:trial-end"); | |||||
Queue::assertNothingPushed(); | |||||
} | } | ||||
} | } |