From 2a23f18ea49979d874ee15b5b206fa7d01b5a44c Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Thu, 23 Apr 2026 16:47:15 +0700 Subject: [PATCH] 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 --- app/Controllers/Test/TestsController.php | 2 +- app/Models/Test/TestDefSiteModel.php | 6 +-- public/api-docs.bundled.yaml | 4 +- public/paths/tests.yaml | 4 +- tests/feature/Test/TestIndexFilterTest.php | 55 ++++++++++++++++++++++ 5 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 tests/feature/Test/TestIndexFilterTest.php diff --git a/app/Controllers/Test/TestsController.php b/app/Controllers/Test/TestsController.php index 4b9e5a0..b4e5f83 100755 --- a/app/Controllers/Test/TestsController.php +++ b/app/Controllers/Test/TestsController.php @@ -50,7 +50,7 @@ class TestsController extends BaseController 'isVisibleRpt' => $this->request->getGet('isVisibleRpt'), 'TestSiteName' => $this->request->getGet('TestSiteName'), 'TestSiteCode' => $this->request->getGet('TestSiteCode'), - 'DepartmentID' => $this->request->getGet('DepartmentID'), + 'DisciplineID' => $this->request->getGet('DisciplineID'), 'search' => $search, ]; diff --git a/app/Models/Test/TestDefSiteModel.php b/app/Models/Test/TestDefSiteModel.php index 69f8407..9f049dd 100755 --- a/app/Models/Test/TestDefSiteModel.php +++ b/app/Models/Test/TestDefSiteModel.php @@ -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 = []) { $builder = $this->db->table('testdefsite') @@ -120,8 +120,8 @@ class TestDefSiteModel extends BaseModel { $builder->like('testdefsite.TestSiteCode', $filters['TestSiteCode']); } - if (!empty($filters['DepartmentID'])) { - $builder->where('COALESCE(testdefsite.DepartmentID, cal.DepartmentID)', $filters['DepartmentID']); + if (!empty($filters['DisciplineID'])) { + $builder->where('COALESCE(testdefsite.DisciplineID, cal.DisciplineID)', $filters['DisciplineID']); } if (!empty($filters['search'])) { diff --git a/public/api-docs.bundled.yaml b/public/api-docs.bundled.yaml index 23a0a1f..e42cbac 100755 --- a/public/api-docs.bundled.yaml +++ b/public/api-docs.bundled.yaml @@ -4696,11 +4696,11 @@ paths: schema: type: integer description: Filter by site ID - - name: DepartmentID + - name: DisciplineID in: query schema: type: integer - description: Filter by department ID + description: Filter by discipline ID - name: TestType in: query schema: diff --git a/public/paths/tests.yaml b/public/paths/tests.yaml index 950c395..a8673f7 100755 --- a/public/paths/tests.yaml +++ b/public/paths/tests.yaml @@ -22,11 +22,11 @@ schema: type: integer description: Filter by site ID - - name: DepartmentID + - name: DisciplineID in: query schema: type: integer - description: Filter by department ID + description: Filter by discipline ID - name: TestType in: query schema: diff --git a/tests/feature/Test/TestIndexFilterTest.php b/tests/feature/Test/TestIndexFilterTest.php new file mode 100644 index 0000000..3435075 --- /dev/null +++ b/tests/feature/Test/TestIndexFilterTest.php @@ -0,0 +1,55 @@ +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']; + } +}