<?php

/*
|--------------------------------------------------------------------------
| Topic API Tests
|--------------------------------------------------------------------------
|
| Feature tests for the /api/v1/topics endpoint
|
*/

it('returns a successful response for topics index', function () {
    $response = $this->getJson('/api/v1/topics');

    $response->assertStatus(200);
});

it('returns topics with correct structure', function () {
    $response = $this->getJson('/api/v1/topics');

    $response->assertStatus(200)
        ->assertJsonStructure([
            'data',
        ]);
});

it('returns topics as array', function () {
    $response = $this->getJson('/api/v1/topics');

    $response->assertStatus(200);

    $data = $response->json();
    expect($data)->toHaveKey('data');
    expect($data['data'])->toBeArray();
});

it('can filter subtopics by parent topic', function () {
    // Get a valid topic ID from the database
    $topic = \App\Models\Topic::full()
        ->where('status', 'published')
        ->first();

    if (!$topic) {
        $this->markTestSkipped('No published topics in the database');
    }

    $response = $this->getJson("/api/v1/topics?topic={$topic->id}");

    $response->assertStatus(200);
});
