You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
<?php
|
|
|
|
use App\Domains\Identity\Actions\Onboarding\VerifyUserEmail;
|
|
use App\Domains\Identity\Events\Onboarding\UserEmailWasVerified;
|
|
use App\Domains\Identity\Models\User;
|
|
use Illuminate\Auth\Events\Verified;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
uses(Tests\TestCase::class, RefreshDatabase::class);
|
|
|
|
test('it can verify user email', function () {
|
|
Event::fake();
|
|
|
|
$user = User::factory()->unverified()->create();
|
|
|
|
$action = new VerifyUserEmail();
|
|
$result = $action->execute($user);
|
|
|
|
expect($result)->toBeTrue()
|
|
->and($user->fresh()->hasVerifiedEmail())->toBeTrue();
|
|
|
|
Event::assertDispatched(Verified::class);
|
|
Event::assertDispatched(UserEmailWasVerified::class);
|
|
});
|
|
|
|
test('it returns false if email is already verified', function () {
|
|
Event::fake();
|
|
|
|
$user = User::factory()->create([
|
|
'email_verified_at' => now(),
|
|
]);
|
|
|
|
$action = new VerifyUserEmail();
|
|
$result = $action->execute($user);
|
|
|
|
expect($result)->toBeFalse();
|
|
|
|
Event::assertNotDispatched(Verified::class);
|
|
Event::assertNotDispatched(UserEmailWasVerified::class);
|
|
});
|
|
|