<?php

use App\Models\Artwork;
use App\Models\User;
use App\Services\Artworks\ArtworkDraftService;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

it('allows duplicate artwork slugs when creating drafts', function () {
    $user = User::factory()->create();
    $drafts = app(ArtworkDraftService::class);

    $first = $drafts->createDraft($user->id, 'Silent', null);
    $second = $drafts->createDraft($user->id, 'Silent', null);

    expect(Artwork::query()->findOrFail($first->artworkId)->slug)->toBe('silent')
        ->and(Artwork::query()->findOrFail($second->artworkId)->slug)->toBe('silent');
});

it('resolves public artwork pages by id even when slugs are duplicated', function () {
    $first = Artwork::factory()->create([
        'title' => 'Silent',
        'slug' => 'silent',
        'description' => 'First silent artwork.',
    ]);

    $second = Artwork::factory()->create([
        'title' => 'Silent',
        'slug' => 'silent',
        'description' => 'Second silent artwork.',
    ]);

    $this->get(route('art.show', ['id' => $first->id, 'slug' => 'silent']))
        ->assertOk()
        ->assertSee('First silent artwork.', false);

    $this->get(route('art.show', ['id' => $second->id, 'slug' => 'silent']))
        ->assertOk()
        ->assertSee('Second silent artwork.', false);
});