GetCommentTest.php 1.74 KB
<?php

namespace FootyRoom\Tests;

class GetCommentTest extends TestCase
{
    use SetsUpFixtures;

    public function testGuestCanGetComment()
    {
        $response = $this->json('GET', '/comments/1');
        $this->assertEquals(200, $response->status());
        $this->assertObjectHaveAttributes(
            ['id', 'author', 'content', 'html', 'date', 'approved', 'userId', 'karma', 'parentId', 'teamname', 'meta', 'userInfo', 'replies', 'discussionId'],
            $response->original['comment']
        );
        $this->assertEmpty($response->original['comment']->meta);
    }

    public function testLoggedInCanGetComment()
    {
        $user = factory('FootyRoom\User\User')->make(['user_id' => 2]);
        $response = $this->actingAs($user)->json('GET', '/comments/1');
        $this->assertEquals(200, $response->status());
        $this->assertObjectHaveAttributes(
            ['id', 'author', 'content', 'html', 'date', 'approved', 'userId', 'karma', 'parentId', 'teamname', 'meta', 'userInfo', 'replies', 'discussionId'],
            $response->original['comment']
        );
    }

    public function testCommentNotFoundShouldBeNull()
    {
        $response = $this->json('GET', '/comments/9999');
        $this->assertEquals(200, $response->status());
        $this->assertNull($response->original['comment']);
    }

    public function testCommentFoundHaveCorrectFormat()
    {
        $response = $this->json('GET', '/comments/1');
        $this->assertEquals(200, $response->status());
        $this->assertObjectHaveAttributes(
            ['id', 'author', 'content', 'html', 'date', 'approved', 'userId', 'karma', 'parentId', 'teamname', 'meta', 'userInfo', 'replies', 'discussionId'],
            $response->original['comment']
        );
    }
}