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.
This commit is contained in:
mahdahar 2026-03-25 14:06:00 +07:00
parent 76ea22d841
commit 76c528564c
8 changed files with 67 additions and 81 deletions

View File

@ -1,41 +0,0 @@
exclude_patterns:
- '**/.*'
- '**/__pycache__'
- '**/node_modules'
- '**/target'
- '**/build/assets'
- '**/dist'
- '**/vendor/*.*/*'
- '**/vendor/*'
- '**/.cocoindex_code'
include_patterns:
- '**/*.py'
- '**/*.pyi'
- '**/*.js'
- '**/*.jsx'
- '**/*.ts'
- '**/*.tsx'
- '**/*.mjs'
- '**/*.cjs'
- '**/*.rs'
- '**/*.go'
- '**/*.java'
- '**/*.c'
- '**/*.h'
- '**/*.cpp'
- '**/*.hpp'
- '**/*.cc'
- '**/*.cxx'
- '**/*.hxx'
- '**/*.hh'
- '**/*.cs'
- '**/*.sql'
- '**/*.sh'
- '**/*.bash'
- '**/*.zsh'
- '**/*.md'
- '**/*.mdx'
- '**/*.txt'
- '**/*.rst'
- '**/*.php'
- '**/*.lua'

Binary file not shown.

View File

@ -97,12 +97,8 @@ class TestsController extends BaseController
} elseif ($typeCode === 'GROUP') {
$row['testdefgrp'] = $this->modelGrp->getGroupMembers($id);
} elseif ($typeCode !== 'TITLE') {
$row['testdeftech'] = $this->model->getTestTechWithRelations($id);
if (!empty($row['testdeftech'])) {
$techData = $row['testdeftech'][0];
$refType = $techData['RefType'];
$resultType = $techData['ResultType'] ?? '';
$refType = $row['RefType'] ?? '';
$resultType = $row['ResultType'] ?? '';
if (TestValidationService::usesRefNum($resultType, $refType)) {
$row['refnum'] = $this->modelRefNum->getFormattedByTestSiteID($id);
@ -112,7 +108,6 @@ class TestsController extends BaseController
$row['reftxt'] = $this->modelRefTxt->getFormattedByTestSiteID($id);
}
}
}
return $this->respond([
'status' => 'success',

View File

@ -230,9 +230,14 @@ class TestDefSiteModel extends BaseModel {
*/
public function getTestById($id)
{
$row = $this->select('testdefsite.*')
$row = $this->db->table('testdefsite')
->select('testdefsite.*, d.DisciplineName, dept.DepartmentName')
->join('discipline d', 'd.DisciplineID = testdefsite.DisciplineID', 'left')
->join('department dept', 'dept.DepartmentID = testdefsite.DepartmentID', 'left')
->where('testdefsite.TestSiteID', $id)
->find($id);
->where('testdefsite.EndDate IS NULL')
->get()
->getRowArray();
if (!$row) {
return null;
@ -245,21 +250,4 @@ class TestDefSiteModel extends BaseModel {
return $rows[0];
}
/**
* Get technical test with discipline and department relations
*
* @param int $testSiteID
* @return array
*/
public function getTestTechWithRelations($testSiteID)
{
return $this->db->table('testdefsite')
->select('testdefsite.*, d.DisciplineName, dept.DepartmentName')
->join('discipline d', 'd.DisciplineID=testdefsite.DisciplineID', 'left')
->join('department dept', 'dept.DepartmentID=testdefsite.DepartmentID', 'left')
->where('testdefsite.TestSiteID', $testSiteID)
->where('testdefsite.EndDate IS NULL')
->get()
->getResultArray();
}
}

6
package-lock.json generated Normal file
View File

@ -0,0 +1,6 @@
{
"name": "clqms01-be",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}

View File

@ -0,0 +1,38 @@
<?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']);
}
}