- Return compact test list from order show endpoint - Add compact order/test OpenAPI schema refs - Add feature test for compact order show payload - Remove tracked composer.phar binary
119 lines
3.7 KiB
PHP
119 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\OrderTest;
|
|
|
|
use App\Models\OrderTest\OrderTestModel;
|
|
use App\Models\Patient\PatientModel;
|
|
use App\Models\Test\TestDefSiteModel;
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
|
use CodeIgniter\Test\FeatureTestTrait;
|
|
use Firebase\JWT\JWT;
|
|
|
|
class OrderTestShowCompactTest extends CIUnitTestCase
|
|
{
|
|
use FeatureTestTrait;
|
|
|
|
protected string $token;
|
|
protected string $endpoint = 'api/ordertest';
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$key = getenv('JWT_SECRET') ?: 'my-secret-key';
|
|
$payload = [
|
|
'iss' => 'localhost',
|
|
'aud' => 'localhost',
|
|
'iat' => time(),
|
|
'nbf' => time(),
|
|
'exp' => time() + 3600,
|
|
'uid' => 1,
|
|
'email' => 'admin@admin.com',
|
|
];
|
|
$this->token = JWT::encode($payload, $key, 'HS256');
|
|
}
|
|
|
|
private function authHeaders(): array
|
|
{
|
|
return ['Cookie' => 'token=' . $this->token];
|
|
}
|
|
|
|
private function createOrderWithTest(): array
|
|
{
|
|
$patientModel = new PatientModel();
|
|
$patient = $patientModel->where('DelDate', null)->first();
|
|
$this->assertNotEmpty($patient, 'No active patient found for order show test.');
|
|
|
|
$testModel = new TestDefSiteModel();
|
|
$test = $testModel->where('EndDate', null)
|
|
->where('TestType', 'TEST')
|
|
->first();
|
|
|
|
if (!$test) {
|
|
$test = $testModel->where('EndDate', null)->first();
|
|
}
|
|
|
|
$this->assertNotEmpty($test, 'No active test definition found for order show test.');
|
|
|
|
$orderModel = new OrderTestModel();
|
|
$orderID = $orderModel->createOrder([
|
|
'InternalPID' => (int) $patient['InternalPID'],
|
|
'SiteID' => (int) ($test['SiteID'] ?? 1),
|
|
'Tests' => [
|
|
[
|
|
'TestSiteID' => (int) $test['TestSiteID'],
|
|
],
|
|
],
|
|
]);
|
|
|
|
$this->assertNotEmpty($orderID, 'Failed to create order for show test.');
|
|
|
|
return [$orderID, $test];
|
|
}
|
|
|
|
public function testShowReturnsCompactTestsOnly(): void
|
|
{
|
|
[$orderID, $test] = $this->createOrderWithTest();
|
|
|
|
$response = $this->withHeaders($this->authHeaders())
|
|
->call('get', $this->endpoint . '/' . $orderID);
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$json = json_decode($response->getJSON(), true);
|
|
|
|
$this->assertSame('success', $json['status'] ?? null);
|
|
$this->assertArrayHasKey('data', $json);
|
|
$this->assertArrayHasKey('Tests', $json['data']);
|
|
$this->assertArrayNotHasKey('Specimens', $json['data']);
|
|
|
|
$tests = $json['data']['Tests'];
|
|
$this->assertNotEmpty($tests, 'Compact tests list is empty.');
|
|
|
|
$firstTest = $tests[0];
|
|
$this->assertSame((int) $test['TestSiteID'], (int) $firstTest['TestSiteID']);
|
|
$this->assertArrayHasKey('TestSiteCode', $firstTest);
|
|
$this->assertArrayHasKey('TestSiteName', $firstTest);
|
|
$this->assertArrayNotHasKey('Result', $firstTest);
|
|
$this->assertArrayNotHasKey('Discipline', $firstTest);
|
|
$this->assertArrayNotHasKey('OrderID', $firstTest);
|
|
$this->assertArrayNotHasKey('InternalSID', $firstTest);
|
|
$this->assertArrayNotHasKey('SID', $firstTest);
|
|
$this->assertArrayNotHasKey('SampleID', $firstTest);
|
|
}
|
|
|
|
public function testShowNotFound(): void
|
|
{
|
|
$response = $this->withHeaders($this->authHeaders())
|
|
->call('get', $this->endpoint . '/999999999');
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$json = json_decode($response->getJSON(), true);
|
|
$this->assertSame('success', $json['status'] ?? null);
|
|
$this->assertNull($json['data'] ?? null);
|
|
}
|
|
}
|