<?php

declare(strict_types=1);

use App\Models\Story;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;

uses(RefreshDatabase::class);

it('hydrates story edit forms with cdn-backed cover urls', function (): void {
    config()->set('cdn.files_url', 'https://cdn.skinbase.test');

    $creator = User::factory()->create();
    $story = Story::query()->create([
        'creator_id' => $creator->id,
        'title' => 'Cover Story',
        'slug' => 'cover-story-' . Str::lower(Str::random(6)),
        'content' => '<p>Cover story content</p>',
        'story_type' => 'creator_story',
        'status' => 'draft',
        'cover_image' => 'stories/md/a1/b2/a1b2c3d4e5f60123456789abcdef0123456789abcdef0123456789abcdef0123.webp',
        'og_image' => 'stories/md/a1/b2/a1b2c3d4e5f60123456789abcdef0123456789abcdef0123456789abcdef0123.webp',
    ]);

    $response = $this->actingAs($creator)->get(route('creator.stories.edit', ['story' => $story->id]));

    $response->assertOk();

    $html = $response->getContent();
    $this->assertNotFalse($html);

    expect($html)->toContain('https:\/\/cdn.skinbase.test\/stories\/md\/a1\/b2\/a1b2c3d4e5f60123456789abcdef0123456789abcdef0123456789abcdef0123.webp');
    expect($html)->not->toContain('https:\/\/skinbase.org\/stories\/md\/a1\/b2\/a1b2c3d4e5f60123456789abcdef0123456789abcdef0123456789abcdef0123.webp');
});