Blame view
tests/integration/Comment/Vote/CommentKarmaShouldBeUpdatedOnVoteTest.php
1.54 KB
e77200db5 Initial commit |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<?php namespace FootyRoom\Tests; use Illuminate\Database\Connection; class CommentKarmaShouldBeUpdatedOnVoteTest extends TestCase { use SetsUpFixtures; public function setup() { parent::setup(); $this->mysql = $this->app->make(Connection::class); } public function testVoteUpShouldSeeCommentKarmaIncremented() { $commentId = 1; $commentBefore = $this->mysql->table('comments')->where('id', '=', $commentId)->first(); $user = factory('FootyRoom\User\User')->make(['user_id' => 2]); $response = $this->actingAs($user)->json('POST', "/comments/$commentId/vote", ['vote' => 1]); $commentAfter = $this->mysql->table('comments')->where('id', '=', $commentId)->first(); $this->assertEquals(200, $response->status()); $this->assertEquals($commentBefore->karma + 1, $commentAfter->karma); } public function testVoteDownShouldSeeCommentKarmaDecremented() { $commentId = 1; $commentBefore = $this->mysql->table('comments')->where('id', '=', $commentId)->first(); // We will use different user , so we don't get already voted exception $user = factory('FootyRoom\User\User')->make(['user_id' => 3]); $response = $this->actingAs($user)->json('POST', "/comments/$commentId/vote", ['vote' => -1]); $commentAfter = $this->mysql->table('comments')->where('id', '=', $commentId)->first(); $this->assertEquals(200, $response->status()); $this->assertEquals($commentBefore->karma - 1, $commentAfter->karma); } } |