'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); } }