Files
SkinbaseNova/tests/Feature/Community/LatestCommentsTest.php

48 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Artwork;
use App\Models\ArtworkComment;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('renders the latest comments page', function (): void {
$author = User::factory()->create();
$artwork = Artwork::factory()->for($author)->create();
ArtworkComment::factory()->for($artwork)->for($author)->create([
'content' => 'Latest comments page regression comment',
'raw_content' => 'Latest comments page regression comment',
'rendered_content' => '<p>Latest comments page regression comment</p>',
'created_at' => now()->subMinutes(5),
]);
$this->get(route('legacy.latest_comments'))
->assertOk()
->assertSee('Latest Comments');
});
it('returns latest comments api data', function (): void {
$author = User::factory()->create();
$artwork = Artwork::factory()->for($author)->create([
'title' => 'Latest Comments Artwork',
'slug' => 'latest-comments-artwork',
]);
$comment = ArtworkComment::factory()->for($artwork)->for($author)->create([
'content' => 'Latest comments api regression comment',
'raw_content' => 'Latest comments api regression comment',
'rendered_content' => '<p>Latest comments api regression comment</p>',
'created_at' => now()->subMinutes(10),
]);
$this->getJson(route('api.comments.latest'))
->assertOk()
->assertJsonPath('data.0.comment_id', $comment->id)
->assertJsonPath('data.0.commenter.id', $author->id)
->assertJsonPath('data.0.artwork.id', $artwork->id)
->assertJsonPath('meta.total', 1);
});