Skip to content

Commit 9619dde

Browse files
committed
confirmed event tests
1 parent ad3cdef commit 9619dde

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/ConfirmationTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace BeyondCode\EmailConfirmation\Tests;
44

5+
use BeyondCode\EmailConfirmation\Events\Confirmed;
56
use Illuminate\Auth\Notifications\ResetPassword;
7+
use Illuminate\Support\Facades\Event;
68
use Illuminate\Support\Facades\Notification;
79
use BeyondCode\EmailConfirmation\Tests\Models\User;
810
use BeyondCode\EmailConfirmation\Notifications\ConfirmEmail;
@@ -139,4 +141,37 @@ public function it_does_not_allow_reset_password_request_for_unconfirmed_users()
139141

140142
Notification::assertNotSentTo($user, ResetPassword::class);
141143
}
144+
145+
/** @test */
146+
public function it_dispatches_confirmed_event_on_successful_confirmation()
147+
{
148+
Event::fake();
149+
150+
$user = User::create([
151+
'email' => '[email protected]',
152+
'password' => bcrypt('test123'),
153+
'confirmed_at' => null,
154+
'confirmation_code' => 'abcdefg'
155+
]);
156+
157+
$response = $this->get('/register/confirm/abcdefg');
158+
159+
Event::assertDispatched(Confirmed::class, function ($e) use ($user) {
160+
return $e->user->email === $user->email;
161+
});
162+
163+
$response->assertRedirect('/login');
164+
}
165+
166+
/** @test */
167+
public function it_does_not_dispatch_confirmed_event_on_failed_confirmation()
168+
{
169+
Event::fake();
170+
171+
$response = $this->get('/register/confirm/foo');
172+
173+
Event::assertNotDispatched(Confirmed::class);
174+
175+
$response->assertStatus(404);
176+
}
142177
}

0 commit comments

Comments
 (0)