Add AttDocFirstName, AttDocLastName, and AttDocContactCode to showByPatient via joins to contact and site-scoped contactdetail. Keep existing AttDoc ID field unchanged for backward compatibility. Update PatientVisit OpenAPI schema, regenerate bundled docs, and extend PatVisitByPatientTest assertions for new fields.
68 lines
1.8 KiB
PHP
Executable File
68 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Tests\Feature\PatVisit;
|
|
|
|
use CodeIgniter\Test\FeatureTestTrait;
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
|
|
|
class PatVisitByPatientTest extends CIUnitTestCase
|
|
{
|
|
use FeatureTestTrait;
|
|
|
|
protected $endpoint = 'api/patvisit/patient';
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
}
|
|
|
|
/**
|
|
* Test: Show all visits by valid InternalPID
|
|
*/
|
|
public function testShowByPatientSuccess()
|
|
{
|
|
$InternalPID = 1;
|
|
|
|
$response = $this->get($this->endpoint . '/' . $InternalPID);
|
|
$response->assertStatus(200);
|
|
|
|
// Pastikan JSON berisi struktur dasar
|
|
$response->assertJSONFragment([
|
|
'status' => 'success',
|
|
// 'message' => 'data not found',
|
|
]);
|
|
|
|
$json = json_decode($response->getJSON(), true);
|
|
|
|
// Pastikan 'data' ada
|
|
$this->assertArrayHasKey('data', $json);
|
|
$this->assertIsArray($json['data']);
|
|
|
|
if (!empty($json['data'])) {
|
|
$this->assertArrayHasKey('AttDoc', $json['data'][0]);
|
|
$this->assertArrayHasKey('AttDocFirstName', $json['data'][0]);
|
|
$this->assertArrayHasKey('AttDocLastName', $json['data'][0]);
|
|
$this->assertArrayHasKey('AttDocContactCode', $json['data'][0]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test: Show by patient with invalid / nonexistent InternalPID
|
|
*/
|
|
public function testShowByPatientNotFound()
|
|
{
|
|
$invalidPID = 9999999; // diasumsikan tidak ada
|
|
|
|
$response = $this->get($this->endpoint . '/' . $invalidPID);
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$json = json_decode($response->getJSON(), true);
|
|
|
|
$this->assertArrayHasKey('data', $json);
|
|
$this->assertIsArray($json['data']);
|
|
$this->assertCount(0, $json['data']); // Data kosong
|
|
}
|
|
|
|
}
|