|
2 | 2 |
|
3 | 3 | namespace Tests\Feature; |
4 | 4 |
|
| 5 | +use App\Models\Like; |
5 | 6 | use App\Models\Reply; |
6 | 7 | use App\Models\Tag; |
7 | 8 | use App\Models\Thread; |
| 9 | +use App\User; |
8 | 10 | use Illuminate\Foundation\Testing\DatabaseMigrations; |
9 | 11 | use Tests\BrowserKitTestCase; |
10 | 12 |
|
@@ -170,4 +172,39 @@ public function users_cannot_edit_a_thread_with_a_subject_that_is_too_long() |
170 | 172 | $response->assertSessionHas('error', 'Something went wrong. Please review the fields below.'); |
171 | 173 | $response->assertSessionHasErrors(['subject' => 'The subject may not be greater than 60 characters.']); |
172 | 174 | } |
| 175 | + |
| 176 | + /** @test */ |
| 177 | + public function users_can_like_a_thread() |
| 178 | + { |
| 179 | + $user = factory(User::class)->create(); |
| 180 | + $thread = factory(Thread::class)->create(['author_id' => $user->id(), 'slug' => 'the-first-thread']); |
| 181 | + |
| 182 | + $this->loginAs($user); |
| 183 | + $this->put("/forum/{$thread->slug}/like") |
| 184 | + ->assertRedirectedTo("/forum/the-first-thread"); |
| 185 | + |
| 186 | + $this->seeInDatabase('likes', [ |
| 187 | + 'user_id' => $user->id, |
| 188 | + 'likeable_id' => $thread->id, |
| 189 | + 'likeable_type' => 'threads' |
| 190 | + ]); |
| 191 | + } |
| 192 | + |
| 193 | + /** @test */ |
| 194 | + public function users_can_unlike_a_thread() |
| 195 | + { |
| 196 | + $user = factory(User::class)->create(); |
| 197 | + $thread = factory(Thread::class)->create(['author_id' => $user->id(), 'slug' => 'the-first-thread']); |
| 198 | + factory(Like::class)->states('thread')->create(['user_id' => $user->id, 'likeable_id' => $thread->id]); |
| 199 | + |
| 200 | + $this->loginAs($user); |
| 201 | + $this->delete("/forum/{$thread->slug}/unlike") |
| 202 | + ->assertRedirectedTo("/forum/the-first-thread"); |
| 203 | + |
| 204 | + $this->notSeeInDatabase('likes', [ |
| 205 | + 'user_id' => $user->id, |
| 206 | + 'likeable_id' => $thread->id, |
| 207 | + 'likeable_type' => 'threads' |
| 208 | + ]); |
| 209 | + } |
173 | 210 | } |
0 commit comments