forked from apiato/apiato
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(email-verification): make email verification actually work! hopef…
…ully!
- Loading branch information
1 parent
253e8a1
commit 49d324a
Showing
17 changed files
with
314 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,23 +17,48 @@ | |
*/ | ||
class RegisterUserActionTest extends TestCase | ||
{ | ||
public function testSendNotification_AfterUserRegistration(): void | ||
public function testAfterUserRegistration_GivenEmailVerificationEnabled_SendNotification(): void | ||
{ | ||
if (!config('appSection-authentication.require_email_verification')) { | ||
$this->markTestSkipped(); | ||
} | ||
Notification::fake(); | ||
|
||
config(['appSection-authentication.require_email_verification', false]); | ||
$data = [ | ||
'email' => '[email protected]', | ||
'password' => 'so-secret', | ||
'verification_url' => config('appSection-authentication.allowed-verify-email-urls')[0], | ||
]; | ||
|
||
$request = new RegisterUserRequest($data); | ||
request()->merge($request->all()); | ||
$user = app(RegisterUserAction::class)->run($request); | ||
|
||
$this->assertEquals($data['email'], $user->email); | ||
$this->assertModelExists($user); | ||
$this->assertEquals(strtolower($data['email']), $user->email); | ||
Notification::assertSentTo($user, Welcome::class); | ||
Notification::assertSentTo($user, VerifyEmail::class); | ||
} | ||
|
||
public function testAfterUserRegistration_GivenEmailVerificationDisabled_ShouldNotSendVerifyEmailNotification(): void | ||
{ | ||
if (config('appSection-authentication.require_email_verification')) { | ||
Notification::assertSentTo($user, VerifyEmail::class); | ||
$this->markTestSkipped(); | ||
} | ||
Notification::fake(); | ||
$data = [ | ||
'email' => '[email protected]', | ||
'password' => 'so-secret', | ||
'verification_url' => config('appSection-authentication.allowed-verify-email-urls')[0], | ||
]; | ||
|
||
$request = new RegisterUserRequest($data); | ||
request()->merge($request->all()); | ||
$user = app(RegisterUserAction::class)->run($request); | ||
|
||
$this->assertModelExists($user); | ||
$this->assertEquals(strtolower($data['email']), $user->email); | ||
Notification::assertSentTo($user, Welcome::class); | ||
Notification::assertNotSentTo($user, VerifyEmail::class); | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
app/Containers/AppSection/Authentication/Tests/Unit/SendVerificationEmailActionTest.php
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
app/Containers/AppSection/Authentication/Tests/Unit/SendVerificationEmailTaskTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Containers\AppSection\Authentication\Tests\Unit; | ||
|
||
use App\Containers\AppSection\Authentication\Notifications\VerifyEmail; | ||
use App\Containers\AppSection\Authentication\Tasks\SendVerificationEmailTask; | ||
use App\Containers\AppSection\Authentication\Tests\TestCase; | ||
use App\Containers\AppSection\User\Models\User; | ||
use Illuminate\Support\Facades\Notification; | ||
|
||
/** | ||
* Class SendVerificationEmailTaskTest. | ||
* | ||
* @group authentication | ||
* @group unit | ||
*/ | ||
class SendVerificationEmailTaskTest extends TestCase | ||
{ | ||
public function testGivenEmailVerificationEnabled_SendVerificationEmail(): void | ||
{ | ||
Notification::fake(); | ||
$unverifiedUser = User::factory()->unverified()->create(); | ||
config(['appSection-authentication.require_email_verification' => true]); | ||
|
||
app(SendVerificationEmailTask::class)->run($unverifiedUser, 'this_doesnt_matter_for_the_test'); | ||
|
||
Notification::assertSentTo($unverifiedUser, VerifyEmail::class); | ||
} | ||
|
||
public function testGivenEmailVerificationDisabled_ShouldNotSendVerificationEmail(): void | ||
{ | ||
Notification::fake(); | ||
$unverifiedUser = User::factory()->unverified()->create(); | ||
config(['appSection-authentication.require_email_verification' => false]); | ||
|
||
app(SendVerificationEmailTask::class)->run($unverifiedUser); | ||
|
||
Notification::assertNotSentTo($unverifiedUser, VerifyEmail::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.