<?php

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Inertia\Testing\AssertableInertia;

uses(RefreshDatabase::class);

it('exposes mascot and cover art urls for upload content types', function () {
    $contentTypeId = DB::table('content_types')->insertGetId([
        'name' => 'Digital Art',
        'slug' => 'digital-art',
        'description' => 'Digital art uploads',
        'order' => 1,
        'mascot_path' => 'content-types/digital-art/mascot.webp',
        'cover_art_path' => 'content-types/digital-art/cover.webp',
        'created_at' => now(),
        'updated_at' => now(),
    ]);

    expect($contentTypeId)->toBeInt();

    $user = User::factory()->create();

    $this->actingAs($user)
        ->get('/upload')
        ->assertOk()
        ->assertInertia(fn (AssertableInertia $page) => $page
            ->component('Upload/Index')
            ->has('content_types', 1)
            ->where('content_types.0.slug', 'digital-art')
            ->where('content_types.0.mascot_url', rtrim((string) config('cdn.files_url'), '/') . '/content-types/digital-art/mascot.webp')
            ->where('content_types.0.cover_art_url', rtrim((string) config('cdn.files_url'), '/') . '/content-types/digital-art/cover.webp')
        );
});