Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Jobs/PasswordResetEmailTest.php
Show All 16 Lines | class PasswordResetEmailTest extends TestCase | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->code = new VerificationCode([ | $this->deleteTestUser('PasswordReset@UserAccount.com'); | ||||
'mode' => 'password-reset', | |||||
]); | |||||
$user = $this->getTestUser('PasswordReset@UserAccount.com'); | |||||
$user->verificationcodes()->save($this->code); | |||||
$user->setSettings(['external_email' => 'etx@email.com']); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->code->user->delete(); | $this->deleteTestUser('PasswordReset@UserAccount.com'); | ||||
parent::tearDown(); | |||||
} | } | ||||
/** | /** | ||||
* Test job handle | * Test job handle | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function testPasswordResetEmailHandle() | public function testPasswordResetEmailHandle() | ||||
{ | { | ||||
$code = new VerificationCode([ | |||||
'mode' => 'password-reset', | |||||
]); | |||||
$user = $this->getTestUser('PasswordReset@UserAccount.com'); | |||||
$user->verificationcodes()->save($code); | |||||
$user->setSettings(['external_email' => 'etx@email.com']); | |||||
Mail::fake(); | Mail::fake(); | ||||
// Assert that no jobs were pushed... | // Assert that no jobs were pushed... | ||||
Mail::assertNothingSent(); | Mail::assertNothingSent(); | ||||
$job = new PasswordResetEmail($this->code); | $job = new PasswordResetEmail($code); | ||||
$job->handle(); | $job->handle(); | ||||
// Assert the email sending job was pushed once | // Assert the email sending job was pushed once | ||||
Mail::assertSent(PasswordReset::class, 1); | Mail::assertSent(PasswordReset::class, 1); | ||||
// Assert the mail was sent to the code's email | // Assert the mail was sent to the code's email | ||||
Mail::assertSent(PasswordReset::class, function ($mail) { | Mail::assertSent(PasswordReset::class, function ($mail) use ($code) { | ||||
return $mail->hasTo($this->code->user->getSetting('external_email')); | return $mail->hasTo($code->user->getSetting('external_email')); | ||||
}); | }); | ||||
} | } | ||||
} | } |