<?php

declare(strict_types=1);

use App\Models\Artwork;
use App\Models\ArtworkComment;
use App\Models\User;

it('redirects legacy received comments urls to the canonical dashboard page', function () {
    $owner = User::factory()->create();

    $this->actingAs($owner)
        ->get('/recieved-comments')
        ->assertRedirect('/dashboard/comments/received')
        ->assertStatus(301);

    $this->actingAs($owner)
        ->get('/received-comments')
        ->assertRedirect('/dashboard/comments/received')
        ->assertStatus(301);
});

it('renders the canonical received comments dashboard page for an authenticated user', function () {
    $owner = User::factory()->create();
    $commenter = User::factory()->create();

    $artwork = Artwork::factory()->create([
        'user_id' => $owner->id,
        'is_approved' => true,
        'is_public' => true,
        'published_at' => now()->subDay(),
    ]);

    ArtworkComment::factory()->create([
        'artwork_id' => $artwork->id,
        'user_id' => $commenter->id,
        'content' => 'Legacy comment regression test',
        'raw_content' => 'Legacy comment regression test',
        'rendered_content' => '<p>Legacy comment regression test</p>',
        'is_approved' => true,
    ]);

    $response = $this->actingAs($owner)->get('/dashboard/comments/received');

    $response
        ->assertOk()
        ->assertSee('Received Comments', false)
        ->assertSee('Total comments', false)
        ->assertSee('Legacy comment regression test', false);
});
