clqms-be/tests/feature/Test/TestShowResponseTest.php
mahdahar 76c528564c fix: simplify test detail retrieval and clean tracked index artifacts
Use the base test row's RefType and ResultType to decide refnum/reftxt loading, and fetch discipline/department joins directly in getTestById to avoid redundant relation queries. Add feature coverage for show response behavior and include the related workspace cleanup changes so the branch state is consistent.
2026-03-25 14:06:00 +07:00

39 lines
1.2 KiB
PHP

<?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']);
}
}