fix: add testmap search filters
Allow the test map list endpoint to filter by host and client, and include container labels in detail responses. Update the API contract and feature coverage to match.
This commit is contained in:
parent
577ceb3d54
commit
7fd3dfddd8
@ -48,6 +48,7 @@ class TestMapController extends BaseController {
|
||||
|
||||
public function index() {
|
||||
$rows = $this->model->getUniqueGroupings();
|
||||
$rows = $this->applyIndexFilters($rows);
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); }
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
@ -223,6 +224,47 @@ class TestMapController extends BaseController {
|
||||
return $row;
|
||||
}
|
||||
|
||||
private function applyIndexFilters(array $rows): array
|
||||
{
|
||||
$hostFilter = trim((string) $this->request->getGet('host'));
|
||||
$clientFilter = trim((string) $this->request->getGet('client'));
|
||||
|
||||
if ($hostFilter === '' && $clientFilter === '') {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
return array_values(array_filter($rows, function (array $row) use ($hostFilter, $clientFilter): bool {
|
||||
if ($hostFilter !== '' && !$this->matchesSearch($row, 'Host', $hostFilter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($clientFilter !== '' && !$this->matchesSearch($row, 'Client', $clientFilter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
private function matchesSearch(array $row, string $prefix, string $filter): bool
|
||||
{
|
||||
$haystacks = [
|
||||
(string) ($row[$prefix . 'Name'] ?? ''),
|
||||
(string) ($row[$prefix . 'ID'] ?? ''),
|
||||
(string) ($row[$prefix . 'Type'] ?? ''),
|
||||
];
|
||||
|
||||
$needle = strtolower($filter);
|
||||
|
||||
foreach ($haystacks as $value) {
|
||||
if ($value !== '' && str_contains(strtolower($value), $needle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function resolveDetailOperations(mixed $detailsPayload): ?array
|
||||
{
|
||||
if ($detailsPayload === null) {
|
||||
|
||||
@ -28,8 +28,10 @@ class TestMapDetailModel extends BaseModel {
|
||||
* Get all details for a test map
|
||||
*/
|
||||
public function getDetailsByTestMap($testMapID) {
|
||||
return $this->where('TestMapID', $testMapID)
|
||||
->where('EndDate IS NULL')
|
||||
return $this->select('testmapdetail.*, containerdef.ConName AS ContainerLabel')
|
||||
->join('containerdef', 'containerdef.ConDefID = testmapdetail.ConDefID', 'left')
|
||||
->where('testmapdetail.TestMapID', $testMapID)
|
||||
->where('testmapdetail.EndDate IS NULL')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
|
||||
@ -4045,6 +4045,19 @@ paths:
|
||||
summary: List all test mappings
|
||||
security:
|
||||
- bearerAuth: []
|
||||
parameters:
|
||||
- name: host
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
description: Filter by host name, type, or ID
|
||||
- name: client
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
description: Filter by client name, type, or ID
|
||||
responses:
|
||||
'200':
|
||||
description: List of test mappings
|
||||
@ -8713,6 +8726,9 @@ components:
|
||||
ConDefID:
|
||||
type: integer
|
||||
description: Container definition ID
|
||||
ContainerLabel:
|
||||
type: string
|
||||
description: Container definition name
|
||||
ClientTestCode:
|
||||
type: string
|
||||
description: Test code in client system
|
||||
|
||||
@ -598,6 +598,9 @@ TestMapDetail:
|
||||
ConDefID:
|
||||
type: integer
|
||||
description: Container definition ID
|
||||
ContainerLabel:
|
||||
type: string
|
||||
description: Container definition name
|
||||
ClientTestCode:
|
||||
type: string
|
||||
description: Test code in client system
|
||||
|
||||
@ -4,6 +4,19 @@
|
||||
summary: List all test mappings
|
||||
security:
|
||||
- bearerAuth: []
|
||||
parameters:
|
||||
- name: host
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
description: Filter by host name, type, or ID
|
||||
- name: client
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
description: Filter by client name, type, or ID
|
||||
responses:
|
||||
'200':
|
||||
description: List of test mappings
|
||||
|
||||
@ -60,6 +60,58 @@ class TestMapPatchTest extends CIUnitTestCase
|
||||
return $showData;
|
||||
}
|
||||
|
||||
public function testIndexFiltersByHost(): void
|
||||
{
|
||||
$testMap = $this->createTestMap([
|
||||
'HostType' => 'SITE',
|
||||
'HostID' => 2,
|
||||
'ClientType' => 'SITE',
|
||||
'ClientID' => 1,
|
||||
]);
|
||||
|
||||
$response = $this->withHeaders($this->authHeaders())
|
||||
->call('get', $this->endpoint . '?host=2');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$rows = json_decode($response->getJSON(), true)['data'];
|
||||
|
||||
$this->assertNotEmpty(array_values(array_filter($rows, static fn (array $row): bool => (int) $row['TestMapID'] === (int) $testMap['TestMapID'])));
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$this->assertTrue(
|
||||
str_contains(strtolower((string) ($row['HostID'] ?? '')), '2')
|
||||
|| str_contains(strtolower((string) ($row['HostName'] ?? '')), '2')
|
||||
|| str_contains(strtolower((string) ($row['HostType'] ?? '')), '2')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testIndexFiltersByClient(): void
|
||||
{
|
||||
$testMap = $this->createTestMap([
|
||||
'HostType' => 'SITE',
|
||||
'HostID' => 1,
|
||||
'ClientType' => 'SITE',
|
||||
'ClientID' => 3,
|
||||
]);
|
||||
|
||||
$response = $this->withHeaders($this->authHeaders())
|
||||
->call('get', $this->endpoint . '?client=3');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$rows = json_decode($response->getJSON(), true)['data'];
|
||||
|
||||
$this->assertNotEmpty(array_values(array_filter($rows, static fn (array $row): bool => (int) $row['TestMapID'] === (int) $testMap['TestMapID'])));
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$this->assertTrue(
|
||||
str_contains(strtolower((string) ($row['ClientID'] ?? '')), '3')
|
||||
|| str_contains(strtolower((string) ($row['ClientName'] ?? '')), '3')
|
||||
|| str_contains(strtolower((string) ($row['ClientType'] ?? '')), '3')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testPartialUpdateTestMapSuccess()
|
||||
{
|
||||
$testMap = $this->createTestMap();
|
||||
@ -229,6 +281,33 @@ class TestMapPatchTest extends CIUnitTestCase
|
||||
$this->assertEquals('Hemoglobin Updated', $updatedDetails[0]['ClientTestName']);
|
||||
}
|
||||
|
||||
public function testShowTestMapIncludesContainerLabel(): void
|
||||
{
|
||||
$testMap = $this->createTestMap([
|
||||
'HostType' => 'SITE',
|
||||
'HostID' => 1,
|
||||
'ClientType' => 'SITE',
|
||||
'ClientID' => 2,
|
||||
'details' => [
|
||||
[
|
||||
'HostTestCode' => 'HB',
|
||||
'HostTestName' => 'Hemoglobin',
|
||||
'ConDefID' => 1,
|
||||
'ClientTestCode' => '2',
|
||||
'ClientTestName' => 'Hemoglobin',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$show = $this->withHeaders($this->authHeaders())->call('get', "{$this->endpoint}/{$testMap['TestMapID']}");
|
||||
$show->assertStatus(200);
|
||||
|
||||
$showData = json_decode($show->getJSON(), true)['data'];
|
||||
$this->assertNotEmpty($showData['details']);
|
||||
$this->assertArrayHasKey('ContainerLabel', $showData['details'][0]);
|
||||
$this->assertNotEmpty($showData['details'][0]['ContainerLabel']);
|
||||
}
|
||||
|
||||
public function testDeleteTestMapRemovesDetails()
|
||||
{
|
||||
$testMap = $this->createTestMap([
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user