Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Add test in case the email was already verified. #310

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions stubs/api/pest-tests/Feature/Auth/EmailVerificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,22 @@

expect($user->fresh()->hasVerifiedEmail())->toBeFalse();
});

test('email is already verified', function () {
$user = User::factory()->create([
'email_verified_at' => now(),
]);

Event::fake();

$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);

$response = $this->actingAs($user)->get($verificationUrl);

Event::assertNotDispatched(Verified::class);
$response->assertRedirect(config('app.frontend_url').RouteServiceProvider::HOME.'?verified=1');
});
20 changes: 20 additions & 0 deletions stubs/api/tests/Feature/Auth/EmailVerificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,24 @@ public function test_email_is_not_verified_with_invalid_hash(): void

$this->assertFalse($user->fresh()->hasVerifiedEmail());
}

public function test_email_is_already_verified(): void
{
$user = User::factory()->create([
'email_verified_at' => now(),
]);

Event::fake();

$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);

$response = $this->actingAs($user)->get($verificationUrl);

Event::assertNotDispatched(Verified::class);
$response->assertRedirect(config('app.frontend_url').RouteServiceProvider::HOME.'?verified=1');
}
}
19 changes: 19 additions & 0 deletions stubs/default/pest-tests/Feature/Auth/EmailVerificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,22 @@

expect($user->fresh()->hasVerifiedEmail())->toBeFalse();
});

test('email is already verified', function () {
$user = User::factory()->create([
'email_verified_at' => now(),
]);

Event::fake();

$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);

$response = $this->actingAs($user)->get($verificationUrl);

Event::assertNotDispatched(Verified::class);
$response->assertRedirect(RouteServiceProvider::HOME.'?verified=1');
});
20 changes: 20 additions & 0 deletions stubs/default/tests/Feature/Auth/EmailVerificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,24 @@ public function test_email_is_not_verified_with_invalid_hash(): void

$this->assertFalse($user->fresh()->hasVerifiedEmail());
}

public function test_email_is_already_verified(): void
{
$user = User::factory()->create([
'email_verified_at' => now(),
]);

Event::fake();

$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);

$response = $this->actingAs($user)->get($verificationUrl);

Event::assertNotDispatched(Verified::class);
$response->assertRedirect(RouteServiceProvider::HOME.'?verified=1');
}
}