<?php

namespace Tests\App\Controllers\Api;

use App\Controllers\Api\DocsController;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Test\CIUnitTestCase;

class TestableDocsController extends DocsController
{
    protected function success($data = null, string $message = 'Success', int $code = ResponseInterface::HTTP_OK)
    {
        return ['data' => $data, 'message' => $message, 'code' => $code];
    }
}

class DocsControllerTest extends CIUnitTestCase
{
    public function testSwaggerReturnsTwoSpecs()
    {
        $controller = new TestableDocsController();
        $response = $controller->swagger();

        $this->assertSame(ResponseInterface::HTTP_OK, $response['code']);
        $this->assertSame('Available OpenAPI specifications', $response['message']);
        $this->assertIsArray($response['data']);
        $this->assertCount(2, $response['data']);
        $this->assertSame('/docs/openapi_administrator_controller.yaml', $response['data'][0]['url']);
    }
}
