|
2 | 2 |
|
3 | 3 | namespace BeyondCode\EmailConfirmation\Tests;
|
4 | 4 |
|
| 5 | +use BeyondCode\EmailConfirmation\Events\Confirmed; |
5 | 6 | use Illuminate\Auth\Notifications\ResetPassword;
|
| 7 | +use Illuminate\Support\Facades\Event; |
6 | 8 | use Illuminate\Support\Facades\Notification;
|
7 | 9 | use BeyondCode\EmailConfirmation\Tests\Models\User;
|
8 | 10 | use BeyondCode\EmailConfirmation\Notifications\ConfirmEmail;
|
@@ -139,4 +141,37 @@ public function it_does_not_allow_reset_password_request_for_unconfirmed_users()
|
139 | 141 |
|
140 | 142 | Notification::assertNotSentTo($user, ResetPassword::class);
|
141 | 143 | }
|
| 144 | + |
| 145 | + /** @test */ |
| 146 | + public function it_dispatches_confirmed_event_on_successful_confirmation() |
| 147 | + { |
| 148 | + Event::fake(); |
| 149 | + |
| 150 | + $user = User::create([ |
| 151 | + |
| 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 | + } |
142 | 177 | }
|
0 commit comments