Skip to content

Commit 6f54482

Browse files
committed
Fix tests
1 parent 462632c commit 6f54482

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

app/Jobs/LikeReply.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public function __construct(Reply $reply, User $user)
3939
*/
4040
public function handle()
4141
{
42-
try {
43-
$this->reply->likedBy($this->user);
44-
} catch (QueryException $exception) {
42+
if($this->reply->isLikedBy($this->user)) {
4543
throw new CannotLikeReplyMultipleTimes();
4644
}
45+
46+
$this->reply->likedBy($this->user);
4747
}
4848
}

tests/Components/Jobs/LikeReplyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function we_cannot_like_a_reply_twice()
3434

3535
$this->assertTrue($reply->fresh()->isLikedBy($user));
3636

37-
$this->expectException(CannotLikeReplyTwice::class);
37+
$this->expectException(CannotLikeReplyMultipleTimes::class);
3838

3939
$this->dispatch(new LikeReply($reply, $user));
4040
}

tests/Components/Jobs/DislikeReplyTest.php renamed to tests/Components/Jobs/UnlikeReplyTest.php

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

33
namespace Tests\Components\Jobs;
44

5-
use App\User;
6-
use Tests\TestCase;
5+
use App\Jobs\UnlikeReply;
76
use App\Models\Reply;
8-
use App\Jobs\DislikeReply;
7+
use App\User;
98
use Illuminate\Foundation\Testing\DatabaseMigrations;
9+
use Tests\TestCase;
1010

11-
class DislikeReplyTest extends TestCase
11+
class UnlikeReplyTest extends TestCase
1212
{
1313
use DatabaseMigrations;
1414

@@ -21,7 +21,7 @@ public function we_can_dislike_a_reply()
2121
$reply->likedBy($user);
2222
$this->assertTrue($reply->fresh()->isLikedBy($user));
2323

24-
$this->dispatch(new DislikeReply($reply, $user));
24+
$this->dispatch(new UnlikeReply($reply, $user));
2525

2626
$this->assertFalse($reply->fresh()->isLikedBy($user));
2727
}
@@ -35,9 +35,9 @@ public function we_cannot_dislike_a_reply()
3535
$reply->likedBy($user);
3636
$this->assertTrue($reply->fresh()->isLikedBy($user));
3737

38-
$this->dispatch(new DislikeReply($reply, $user));
38+
$this->dispatch(new UnlikeReply($reply, $user));
3939

40-
$this->dispatch(new DislikeReply($reply, $user));
40+
$this->dispatch(new UnlikeReply($reply, $user));
4141

4242
//$this->assertFalse($reply->fresh()->isLikedBy($user));
4343
}

tests/Feature/ReplyTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,15 @@ public function unconfirmed_users_cannot_see_the_reply_input()
117117
);
118118
}
119119

120+
/** @test */
120121
public function user_can_like_a_reply()
121122
{
122123
$user = factory(User::class)->create();
123124

124125
$thread = factory(Thread::class)->create(['author_id' => $user->id(), 'slug' => 'the-first-thread']);
125126
$reply = factory(Reply::class)->create(['replyable_id' => $thread->id()]);
126127

127-
$this->put('/forum/the-first-thread/'.$reply->id().'/like');
128-
//->assertForbidden();
128+
$this->put('/forum/the-first-thread/'.$reply->id().'/like')
129+
->assertOk();
129130
}
130131
}

0 commit comments

Comments
 (0)