<?php

use App\Services\Sitemaps\Builders\CategoriesSitemapBuilder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;

uses(Tests\TestCase::class, RefreshDatabase::class);

it('builds category sitemap entries from dynamic content types', function () {
    $contentTypeId = DB::table('content_types')->insertGetId([
        'name' => 'Pixel Art',
        'slug' => 'pixel-art',
        'description' => 'Pixel art uploads',
        'order' => 1,
        'created_at' => now(),
        'updated_at' => now(),
    ]);

    DB::table('categories')->insert([
        'content_type_id' => $contentTypeId,
        'parent_id' => null,
        'name' => 'Characters',
        'slug' => 'characters',
        'description' => null,
        'image' => null,
        'is_active' => true,
        'sort_order' => 1,
        'created_at' => now(),
        'updated_at' => now(),
    ]);

    $items = app(CategoriesSitemapBuilder::class)->items();
    $locations = array_map(static fn ($item) => $item->loc, $items);

    expect($locations)->toContain(url('/pixel-art'))
        ->and($locations)->toContain(url('/pixel-art/characters'));
});