<?php

use Modules\Cms\Models\CmsPage;

test('lists active cms pages', function () {
    $active = CmsPage::factory()->create(['is_active' => true]);
    CmsPage::factory()->create(['is_active' => false]);

    $this->getJson('/api/v1/cms-pages')
        ->assertSuccessful()
        ->assertJsonCount(1, 'data')
        ->assertJsonFragment(['id' => $active->id]);
});

test('does not require authentication', function () {
    CmsPage::factory()->create(['is_active' => true]);

    $this->getJson('/api/v1/cms-pages')->assertSuccessful();
});

test('shows an active cms page by its page slug', function () {
    $page = CmsPage::factory()->create(['page' => 'miniapp_faq', 'is_active' => true]);

    $this->getJson('/api/v1/cms-pages/miniapp_faq')
        ->assertSuccessful()
        ->assertJsonFragment(['id' => $page->id, 'page' => 'miniapp_faq']);
});

test('returns not found for an inactive page', function () {
    CmsPage::factory()->create(['page' => 'miniapp_faq', 'is_active' => false]);

    $this->getJson('/api/v1/cms-pages/miniapp_faq')->assertNotFound();
});

test('returns not found for an unknown page slug', function () {
    $this->getJson('/api/v1/cms-pages/unknown-page')->assertNotFound();
});
