<?php

declare(strict_types=1);

namespace Tests\Feature\Test;

use App\Models\Test\TestDefSiteModel;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\FeatureTestTrait;

class TestShowResponseTest extends CIUnitTestCase
{
    use FeatureTestTrait;

    public function testShowTechnicalDoesNotReturnNestedTestDefTech(): void
    {
        $model = new TestDefSiteModel();

        $test = $model->where('TestSiteCode', 'GLU')->where('EndDate IS NULL')->first();
        if (!$test) {
            $test = $model->where('TestType', 'TEST')->where('EndDate IS NULL')->first();
        }

        $this->assertNotEmpty($test, 'No active technical test record found for show endpoint test.');

        $response = $this->call('get', 'api/test/' . $test['TestSiteID']);

        $response->assertStatus(200);

        $json = json_decode($response->getJSON(), true);

        $this->assertSame('success', $json['status'] ?? null);
        $this->assertArrayHasKey('data', $json);
        $this->assertArrayNotHasKey('testdeftech', $json['data']);
        $this->assertArrayHasKey('TestSiteID', $json['data']);
        $this->assertArrayHasKey('ResultType', $json['data']);
    }
}
