Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/PasswordResetTest.php
Show All 10 Lines | |||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$user = $this->getTestUser('passwordresettest@' . \config('app.domain')); | $this->deleteTestUser('passwordresettest@' . \config('app.domain')); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
User::where('email', 'passwordresettest@' . \config('app.domain')) | $this->deleteTestUser('passwordresettest@' . \config('app.domain')); | ||||
->delete(); | |||||
parent::tearDown(); | |||||
} | } | ||||
/** | /** | ||||
* Test password-reset/init with invalid input | * Test password-reset/init with invalid input | ||||
*/ | */ | ||||
public function testPasswordResetInitInvalidInput(): void | public function testPasswordResetInitInvalidInput(): void | ||||
{ | { | ||||
// Empty input data | // Empty input data | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | class PasswordResetTest extends TestCase | ||||
public function testPasswordResetInitValidInput() | public function testPasswordResetInitValidInput() | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
// Assert that no jobs were pushed... | // Assert that no jobs were pushed... | ||||
Queue::assertNothingPushed(); | Queue::assertNothingPushed(); | ||||
// Add required external email address to user settings | // Add required external email address to user settings | ||||
$user = User::where('email', 'passwordresettest@' . \config('app.domain'))->first(); | $user = $this->getTestUser('passwordresettest@' . \config('app.domain')); | ||||
$user->setSetting('external_email', 'ext@email.com'); | $user->setSetting('external_email', 'ext@email.com'); | ||||
$data = [ | $data = [ | ||||
'email' => 'passwordresettest@' . \config('app.domain'), | 'email' => 'passwordresettest@' . \config('app.domain'), | ||||
]; | ]; | ||||
$response = $this->post('/api/auth/password-reset/init', $data); | $response = $this->post('/api/auth/password-reset/init', $data); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
Show All 32 Lines | public function testPasswordResetVerifyInvalidInput() | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertCount(2, $json['errors']); | $this->assertCount(2, $json['errors']); | ||||
$this->assertArrayHasKey('short_code', $json['errors']); | $this->assertArrayHasKey('short_code', $json['errors']); | ||||
// Add verification code and required external email address to user settings | // Add verification code and required external email address to user settings | ||||
$user = User::where('email', 'passwordresettest@' . \config('app.domain'))->first(); | $user = $this->getTestUser('passwordresettest@' . \config('app.domain')); | ||||
$code = new VerificationCode(['mode' => 'password-reset']); | $code = new VerificationCode(['mode' => 'password-reset']); | ||||
$user->verificationcodes()->save($code); | $user->verificationcodes()->save($code); | ||||
// Data with existing code but missing short_code | // Data with existing code but missing short_code | ||||
$data = [ | $data = [ | ||||
'code' => $code->code, | 'code' => $code->code, | ||||
]; | ]; | ||||
Show All 25 Lines | class PasswordResetTest extends TestCase | ||||
/** | /** | ||||
* Test password-reset/verify with valid input | * Test password-reset/verify with valid input | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function testPasswordResetVerifyValidInput() | public function testPasswordResetVerifyValidInput() | ||||
{ | { | ||||
// Add verification code and required external email address to user settings | // Add verification code and required external email address to user settings | ||||
$user = User::where('email', 'passwordresettest@' . \config('app.domain'))->first(); | $user = $this->getTestUser('passwordresettest@' . \config('app.domain')); | ||||
$code = new VerificationCode(['mode' => 'password-reset']); | $code = new VerificationCode(['mode' => 'password-reset']); | ||||
$user->verificationcodes()->save($code); | $user->verificationcodes()->save($code); | ||||
// Data with invalid code | // Data with invalid code | ||||
$data = [ | $data = [ | ||||
'short_code' => $code->short_code, | 'short_code' => $code->short_code, | ||||
'code' => $code->code, | 'code' => $code->code, | ||||
]; | ]; | ||||
Show All 19 Lines | public function testPasswordResetInvalidInput() | ||||
$response = $this->post('/api/auth/password-reset', $data); | $response = $this->post('/api/auth/password-reset', $data); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertCount(1, $json['errors']); | $this->assertCount(1, $json['errors']); | ||||
$this->assertArrayHasKey('password', $json['errors']); | $this->assertArrayHasKey('password', $json['errors']); | ||||
$user = User::where('email', 'passwordresettest@' . \config('app.domain'))->first(); | $user = $this->getTestUser('passwordresettest@' . \config('app.domain')); | ||||
$code = new VerificationCode(['mode' => 'password-reset']); | $code = new VerificationCode(['mode' => 'password-reset']); | ||||
$user->verificationcodes()->save($code); | $user->verificationcodes()->save($code); | ||||
// Data with existing code but missing password | // Data with existing code but missing password | ||||
$data = [ | $data = [ | ||||
'code' => $code->code, | 'code' => $code->code, | ||||
]; | ]; | ||||
Show All 40 Lines | class PasswordResetTest extends TestCase | ||||
/** | /** | ||||
* Test password reset with valid input | * Test password reset with valid input | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function testPasswordResetValidInput() | public function testPasswordResetValidInput() | ||||
{ | { | ||||
$user = User::where('email', 'passwordresettest@' . \config('app.domain'))->first(); | $user = $this->getTestUser('passwordresettest@' . \config('app.domain')); | ||||
$code = new VerificationCode(['mode' => 'password-reset']); | $code = new VerificationCode(['mode' => 'password-reset']); | ||||
$user->verificationcodes()->save($code); | $user->verificationcodes()->save($code); | ||||
Queue::fake(); | Queue::fake(); | ||||
Queue::assertNothingPushed(); | Queue::assertNothingPushed(); | ||||
$data = [ | $data = [ | ||||
'password' => 'test', | 'password' => 'test', | ||||
Show All 32 Lines |