From a7e26cb61fff8d8600abd8982b9316e87831fea3 Mon Sep 17 00:00:00 2001 From: Milos Holba Date: Sat, 22 May 2021 16:01:25 +0200 Subject: [PATCH] update tests for the user email verification --- app/Http/Controllers/Admin/UserController.php | 1 + .../Controllers/App/SetupWizardController.php | 1 + tests/Feature/Accounts/AuthTest.php | 5 +++++ tests/Feature/Accounts/UserAccountTest.php | 15 ++++++++------- tests/Feature/Admin/AdminTest.php | 3 +++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 3a036e45..4f463a7c 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -178,6 +178,7 @@ class UserController extends Controller 'role' => $request->role, 'email' => $request->email, 'password' => bcrypt($request->password), + 'email_verified_at' => now(), ]); UserSettings::unguard(); diff --git a/app/Http/Controllers/App/SetupWizardController.php b/app/Http/Controllers/App/SetupWizardController.php index 18f8381d..d97458b0 100644 --- a/app/Http/Controllers/App/SetupWizardController.php +++ b/app/Http/Controllers/App/SetupWizardController.php @@ -404,6 +404,7 @@ class SetupWizardController extends Controller 'role' => 'admin', 'email' => $request->email, 'password' => bcrypt($request->password), + 'email_verified_at' => now(), ]); $user diff --git a/tests/Feature/Accounts/AuthTest.php b/tests/Feature/Accounts/AuthTest.php index 6b2ccb30..32f4ec8b 100644 --- a/tests/Feature/Accounts/AuthTest.php +++ b/tests/Feature/Accounts/AuthTest.php @@ -54,6 +54,10 @@ class AuthTest extends TestCase 'name' => 'registration', 'value' => 1, ], + [ + 'name' => 'user_verification', + 'value' => 1, + ] ])->each(function ($setting) { Setting::create([ 'name' => $setting['name'], @@ -70,6 +74,7 @@ class AuthTest extends TestCase $this->assertDatabaseHas('users', [ 'email' => 'john@doe.com', + 'email_verified_at' => null, ]); $this->assertDatabaseHas('user_settings', [ diff --git a/tests/Feature/Accounts/UserAccountTest.php b/tests/Feature/Accounts/UserAccountTest.php index b95cc6c3..991a0b81 100644 --- a/tests/Feature/Accounts/UserAccountTest.php +++ b/tests/Feature/Accounts/UserAccountTest.php @@ -266,7 +266,6 @@ class UserAccountTest extends TestCase */ public function it_user_email_verify() { - // TODO:make request with signature $user = User::factory(User::class) ->create([ 'email_verified_at' => null @@ -278,9 +277,11 @@ class UserAccountTest extends TestCase ['id' => $user->id, 'hash' => sha1($user->email)] ); - $this->getJson($verificationUrl); + $response = $this->getJson($verificationUrl); - $this->assertNotNull($user->email_verified_at); + $response->assertRedirect('sign-in'); + + $this->assertNotNull(User::find($user->id)->get('email_verified_at')); } /** @@ -294,10 +295,10 @@ class UserAccountTest extends TestCase ->create([ 'email_verified_at' => null ]); - - Sanctum::actingAs($user); - - $this->postJson('/api/user/email/resend/verify') + + $this->postJson('/api/user/email/resend/verify', [ + 'email' => $user->email, + ]) ->assertStatus(200); Notification::assertTimesSent(1, VerifyEmail::class); diff --git a/tests/Feature/Admin/AdminTest.php b/tests/Feature/Admin/AdminTest.php index 87fff466..7e244acf 100644 --- a/tests/Feature/Admin/AdminTest.php +++ b/tests/Feature/Admin/AdminTest.php @@ -308,6 +308,9 @@ class AdminTest extends TestCase 'email' => 'john@doe.com' ]); + $this->assertNotNull(User::whereEmail('john@doe.com') + ->get('email_verified_at')); + $this->assertDatabaseHas('user_settings', [ 'name' => 'John Doe' ]);