clqms-be/tests/feature/PatVisit/PatVisitCreateTest.php
root 2bcdf09b55 chore: repo-wide normalization + rules test coverage
Normalize formatting/line endings across configs, controllers, models, tests, and OpenAPI specs.

Update rule expression/rule engine implementation and remove obsolete RuleAction controller/model.

Add unit tests for rule expression syntax and multi-action behavior, and include docs updates.
2026-03-16 07:24:50 +07:00

111 lines
3.2 KiB
PHP

<?php
namespace Tests\Feature\PatVisit;
use CodeIgniter\Test\FeatureTestTrait;
use CodeIgniter\Test\CIUnitTestCase;
class PatVisitCreateTest extends CIUnitTestCase
{
use FeatureTestTrait;
protected $endpoint = 'api/patvisit';
/**
* Test: Create patient visit with valid data
*/
public function testCreatePatientVisitSuccess()
{
$payload = [
"InternalPID"=> "1",
"EpisodeID"=> null,
"PatDiag"=> [
"DiagCode"=> null,
"Diagnosis"=> null
],
"PatVisitADT"=> [
"ADTCode"=> "A01",
"LocationID"=> "1",
"AttDoc"=> "1",
"RefDoc"=> "1",
"AdmDoc"=> "1",
"CnsDoc"=> "1"
],
"PatAtt"=> []
];
$response = $this->withBodyFormat('json')->call('post', $this->endpoint, $payload);
// Pastikan status 201 (created)
$response->assertStatus(201);
// Pastikan JSON mengandung status success dan message yang benar
$response->assertJSONFragment([
'status' => 'success',
'message' => 'Data created successfully'
]);
$json = json_decode($response->getJSON(), true);
// Pastikan struktur data yang dikembalikan benar
$this->assertArrayHasKey('data', $json);
$this->assertArrayHasKey('PVID', $json['data']);
$this->assertArrayHasKey('InternalPVID', $json['data']);
}
/**
* Test: Create patient visit with invalid (empty) data - missing InternalPID
*/
public function testCreatePatientVisitInvalidInput()
{
$payload = [];
// Kirim data kosong
$response = $this->withBodyFormat('json')->call('post', $this->endpoint, $payload);
$response->assertStatus(400);
$response->assertJSONFragment([
'status' => 'error',
'message' => 'InternalPID is required and must be numeric'
]);
}
/**
* Test: Create patient visit with non-existent patient
*/
public function testCreatePatientVisitPatientNotFound()
{
$payload = [
'InternalPID' => 999999, // Non-existent patient
'EpisodeID' => 'EPI001'
];
$response = $this->withBodyFormat('json')->call('post', $this->endpoint, $payload);
$response->assertStatus(404);
$response->assertJSONFragment([
'status' => 'error',
'message' => 'Patient not found'
]);
}
/**
* Test: Create patient visit with invalid InternalPID (non-numeric)
*/
public function testCreatePatientVisitInvalidInternalPID()
{
$payload = [
'InternalPID' => 'invalid',
'EpisodeID' => 'EPI001'
];
$response = $this->withBodyFormat('json')->call('post', $this->endpoint, $payload);
$response->assertStatus(400);
$response->assertJSONFragment([
'status' => 'error',
'message' => 'InternalPID is required and must be numeric'
]);
}
}