feat(tests): rename index filter to DisciplineID
- switch TestsController and TestDefSiteModel to DisciplineID filter handling - update OpenAPI path docs and bundled spec for query param rename - add feature test covering api/test filtering by DisciplineID
This commit is contained in:
parent
796dc94286
commit
2a23f18ea4
@ -50,7 +50,7 @@ class TestsController extends BaseController
|
|||||||
'isVisibleRpt' => $this->request->getGet('isVisibleRpt'),
|
'isVisibleRpt' => $this->request->getGet('isVisibleRpt'),
|
||||||
'TestSiteName' => $this->request->getGet('TestSiteName'),
|
'TestSiteName' => $this->request->getGet('TestSiteName'),
|
||||||
'TestSiteCode' => $this->request->getGet('TestSiteCode'),
|
'TestSiteCode' => $this->request->getGet('TestSiteCode'),
|
||||||
'DepartmentID' => $this->request->getGet('DepartmentID'),
|
'DisciplineID' => $this->request->getGet('DisciplineID'),
|
||||||
'search' => $search,
|
'search' => $search,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,7 @@ class TestDefSiteModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get tests list with discipline and department info
|
* Get tests list with discipline info
|
||||||
*/
|
*/
|
||||||
public function getTestsWithRelations($filters = []) {
|
public function getTestsWithRelations($filters = []) {
|
||||||
$builder = $this->db->table('testdefsite')
|
$builder = $this->db->table('testdefsite')
|
||||||
@ -120,8 +120,8 @@ class TestDefSiteModel extends BaseModel {
|
|||||||
$builder->like('testdefsite.TestSiteCode', $filters['TestSiteCode']);
|
$builder->like('testdefsite.TestSiteCode', $filters['TestSiteCode']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($filters['DepartmentID'])) {
|
if (!empty($filters['DisciplineID'])) {
|
||||||
$builder->where('COALESCE(testdefsite.DepartmentID, cal.DepartmentID)', $filters['DepartmentID']);
|
$builder->where('COALESCE(testdefsite.DisciplineID, cal.DisciplineID)', $filters['DisciplineID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($filters['search'])) {
|
if (!empty($filters['search'])) {
|
||||||
|
|||||||
@ -4696,11 +4696,11 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
description: Filter by site ID
|
description: Filter by site ID
|
||||||
- name: DepartmentID
|
- name: DisciplineID
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
description: Filter by department ID
|
description: Filter by discipline ID
|
||||||
- name: TestType
|
- name: TestType
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
|
|||||||
@ -22,11 +22,11 @@
|
|||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
description: Filter by site ID
|
description: Filter by site ID
|
||||||
- name: DepartmentID
|
- name: DisciplineID
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
description: Filter by department ID
|
description: Filter by discipline ID
|
||||||
- name: TestType
|
- name: TestType
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
|
|||||||
55
tests/feature/Test/TestIndexFilterTest.php
Normal file
55
tests/feature/Test/TestIndexFilterTest.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Feature\Test;
|
||||||
|
|
||||||
|
use App\Models\Test\TestDefSiteModel;
|
||||||
|
use CodeIgniter\Test\CIUnitTestCase;
|
||||||
|
use CodeIgniter\Test\FeatureTestTrait;
|
||||||
|
|
||||||
|
class TestIndexFilterTest extends CIUnitTestCase
|
||||||
|
{
|
||||||
|
use FeatureTestTrait;
|
||||||
|
|
||||||
|
public function testIndexFiltersByDisciplineId(): void
|
||||||
|
{
|
||||||
|
$disciplineId = $this->findActiveDisciplineId();
|
||||||
|
if ($disciplineId === null) {
|
||||||
|
$this->markTestSkipped('No active test record with discipline found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $this->call('get', 'api/test?DisciplineID=' . $disciplineId);
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$json = json_decode($response->getJSON(), true);
|
||||||
|
$rows = $json['data'] ?? [];
|
||||||
|
|
||||||
|
$this->assertNotEmpty($rows);
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$rowDisciplineId = (int) ($row['DisciplineID'] ?? 0);
|
||||||
|
$this->assertSame($disciplineId, $rowDisciplineId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function findActiveDisciplineId(): ?int
|
||||||
|
{
|
||||||
|
$model = new TestDefSiteModel();
|
||||||
|
|
||||||
|
$row = $model->db->table('testdefsite')
|
||||||
|
->select('COALESCE(testdefsite.DisciplineID, cal.DisciplineID) AS DisciplineID')
|
||||||
|
->join('testdefcal cal', 'cal.TestSiteID = testdefsite.TestSiteID AND cal.EndDate IS NULL', 'left')
|
||||||
|
->where('testdefsite.EndDate IS NULL')
|
||||||
|
->where('COALESCE(testdefsite.DisciplineID, cal.DisciplineID) IS NOT NULL', null, false)
|
||||||
|
->orderBy('testdefsite.TestSiteID', 'ASC')
|
||||||
|
->get()
|
||||||
|
->getRowArray();
|
||||||
|
|
||||||
|
if (!$row || !isset($row['DisciplineID'])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) $row['DisciplineID'];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user