Update Unit Testing Patient
This commit is contained in:
parent
4daf1789db
commit
6287785b73
@ -13,15 +13,15 @@ class PatientCreateTest extends CIUnitTestCase
|
||||
|
||||
// 400 - Passed
|
||||
public function testCreatePatientValidationFail() {
|
||||
|
||||
// Test dengan payload yg tidak lengkap
|
||||
// error 400 yg diharapkan
|
||||
$payload = ['Name' => 'Ngawur'];
|
||||
$result = $this->withBodyFormat('json')
|
||||
->call('post', 'api/patient', $payload);
|
||||
$result->assertStatus(400);
|
||||
$result->assertJSONFragment([
|
||||
'status' => 'error'
|
||||
]);
|
||||
|
||||
// Test dengan PatiD yg sudah ada
|
||||
// Kondisi Jika PatiD Sama
|
||||
$payload = [
|
||||
"PatientID"=> "SMAJ1",
|
||||
@ -38,20 +38,16 @@ class PatientCreateTest extends CIUnitTestCase
|
||||
$result = $this->withBodyFormat('json')
|
||||
->call('post', 'api/patient', $payload);
|
||||
$result->assertStatus(400);
|
||||
$result->assertJSONFragment([
|
||||
'status' => 'error',
|
||||
"message" => "Validation failed (patient)",
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
// 201 - Passed
|
||||
// Test dengan user dummy
|
||||
public function testCreatePatientSuccess() {
|
||||
|
||||
$faker = Factory::create('id_ID');
|
||||
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
|
||||
$payload = [
|
||||
"PatientID" => "DUM" . $faker->numberBetween(1, 1000). $faker->numberBetween(1, 1000).$faker->numberBetween(1, 1000),
|
||||
"AlternatePID" => "DMY" . $faker->numberBetween(1, 1000). $faker->numberBetween(1, 1000).$faker->numberBetween(1, 1000),
|
||||
@ -106,17 +102,7 @@ class PatientCreateTest extends CIUnitTestCase
|
||||
}
|
||||
|
||||
// Error - Passed
|
||||
public function testCreatePatientValidationError() {
|
||||
$payload = [
|
||||
"NameFirst" => "Jane" // PatientID kosong
|
||||
];
|
||||
|
||||
$result = $this->withBodyFormat('json')->post($this->endpoint, $payload);
|
||||
// dd($result);
|
||||
$result->assertArrayHasKey("errors", $result);
|
||||
}
|
||||
|
||||
// Error - Passed
|
||||
// Test dengan user dummy dan harus error
|
||||
public function testCreatePatidtValidationError() {
|
||||
|
||||
$faker = Factory::create('id_ID');
|
||||
@ -171,11 +157,14 @@ class PatientCreateTest extends CIUnitTestCase
|
||||
}
|
||||
|
||||
$result = $this->withBodyFormat('json')->post($this->endpoint, $payload);
|
||||
|
||||
$result->assertArrayHasKey("errors", $result);
|
||||
$json = $result->getJSON();
|
||||
$data = json_decode($json, true);
|
||||
|
||||
$result->assertArrayHasKey("error", $data);
|
||||
}
|
||||
|
||||
// 201 - Passed
|
||||
// Test dengan user dummy dan harus berhasil - Attachment kosong
|
||||
public function testCreateWithoutAttachments() {
|
||||
$faker = Factory::create('id_ID');
|
||||
|
||||
@ -231,6 +220,7 @@ class PatientCreateTest extends CIUnitTestCase
|
||||
}
|
||||
|
||||
// 201 - Passed
|
||||
// Test dengan user dummy dan harus berhasil - PatCom kosong
|
||||
public function testCreateWithoutPatComments() {
|
||||
$faker = Factory::create('id_ID');
|
||||
|
||||
@ -271,9 +261,9 @@ class PatientCreateTest extends CIUnitTestCase
|
||||
"Identifier" => $faker->nik() ?? $faker->numerify('################')
|
||||
],
|
||||
"PatAtt" => [
|
||||
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ],
|
||||
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ],
|
||||
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ]
|
||||
[ "Address" => "/api/upload/awghghghgef" . $faker->word.$faker->word . ".jpg" ],
|
||||
[ "Address" => "/api/upload/df6ghghg4" . $faker->word .$faker->word.".jpg" ],
|
||||
[ "Address" => "/api/upload/ldjghggsf" . $faker->word . $faker->word. ".jpg" ]
|
||||
],
|
||||
"PatCom" => null,
|
||||
];
|
||||
@ -290,10 +280,10 @@ class PatientCreateTest extends CIUnitTestCase
|
||||
}
|
||||
|
||||
// 500 - Passed
|
||||
// Test dengan user dummy dan harus gagal - identifier tidak valid
|
||||
public function testCreateDatabaseError() {
|
||||
$faker = Factory::create('id_ID');
|
||||
|
||||
// Insert patient pertama
|
||||
$payload = [
|
||||
"PatientID" => "DaUALU" . $faker->numberBetween(1, 1000).$faker->numberBetween(1, 1000),
|
||||
"AlternatePID" => "DaMALU" . $faker->numberBetween(5, 1000).$faker->numberBetween(1, 1000),
|
||||
@ -327,15 +317,15 @@ class PatientCreateTest extends CIUnitTestCase
|
||||
"LinkTo" => (string) $faker->numberBetween(2, 3),
|
||||
"Custodian" => 1,
|
||||
"PatIdt" => [
|
||||
"IdentifierType" => "KTP",
|
||||
"IdentifierType" => [], // Ini Salah
|
||||
"Identifier" => $faker->nik() ?? $faker->numerify('################')
|
||||
],
|
||||
"PatAtt" => [
|
||||
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ],
|
||||
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ],
|
||||
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ]
|
||||
[ "Address" => "/api/upload/asasd" . $faker->word . ".jpg" ],
|
||||
[ "Address" => "/api/upload/adsds" . $faker->word . ".jpg" ],
|
||||
[ "Address" => "/api/upload/sdjs" . $faker->word . ".jpg" ]
|
||||
],
|
||||
"PatCom" => [], // Ini Salah
|
||||
"PatCom" => [],
|
||||
];
|
||||
|
||||
if($payload['DeathIndicator'] == '16') {
|
||||
@ -345,31 +335,10 @@ class PatientCreateTest extends CIUnitTestCase
|
||||
}
|
||||
|
||||
$result = $this->withBodyFormat('json')->post($this->endpoint, $payload);
|
||||
|
||||
$result->assertStatus(500);
|
||||
$json = $result->getJSON();
|
||||
$data = json_decode($json, true);
|
||||
|
||||
$result->assertArrayHasKey("error", $data);
|
||||
}
|
||||
|
||||
// public function testCreateDuplicateIdentifier() {
|
||||
// $payload = [
|
||||
// "PatientID" => "PX006",
|
||||
// "NameFirst" => "Alpha",
|
||||
// "Identity" => [
|
||||
// "IdentifierType" => "KTP",
|
||||
// "Identifier" => "DUP123"
|
||||
// ]
|
||||
// ];
|
||||
// $this->withBodyFormat('json')->post($this->endpoint, $payload);
|
||||
|
||||
// $payload2 = [
|
||||
// "PatientID" => "PX007",
|
||||
// "NameFirst" => "Beta",
|
||||
// "Identity" => [
|
||||
// "IdentifierType" => "KTP",
|
||||
// "Identifier" => "DUP123" // Sama
|
||||
// ]
|
||||
// ];
|
||||
// $result = $this->withBodyFormat('json')->post($this->endpoint, $payload2);
|
||||
|
||||
// $result->assertStatus(422);
|
||||
// }
|
||||
}
|
||||
|
||||
@ -32,8 +32,6 @@ class PatientShowTest extends CIUnitTestCase
|
||||
$result->assertStatus(200);
|
||||
$result->assertArrayHasKey('data', $data);
|
||||
$result->assertIsArray($data['data']);
|
||||
|
||||
// $this->assertEquals('success', $data['status']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ class PatientUpdateTest extends CIUnitTestCase
|
||||
}
|
||||
|
||||
// /**
|
||||
// * ❌ Test gagal karena InternalPID kosong (validasi)
|
||||
// * Test gagal karena InternalPID kosong (validasi)
|
||||
// */
|
||||
public function testUpdatePatientValidationError()
|
||||
{
|
||||
@ -66,11 +66,11 @@ class PatientUpdateTest extends CIUnitTestCase
|
||||
$data = json_decode($json, true);
|
||||
|
||||
$result->assertStatus(400);
|
||||
$this->assertArrayHasKey('errors', $data);
|
||||
$this->assertArrayHasKey('error', $data);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * ✅ Test update dengan address baru & hapus address lama
|
||||
// * Test update dengan address baru & hapus address lama
|
||||
// */
|
||||
public function testUpdatePatientWithAddressChange()
|
||||
{
|
||||
@ -116,7 +116,7 @@ class PatientUpdateTest extends CIUnitTestCase
|
||||
}
|
||||
|
||||
// /**
|
||||
// * ⚠️ Test update kosong → semua pattat address dihapus (soft delete)
|
||||
// * Test update kosong → semua pattat address dihapus (soft delete)
|
||||
// */
|
||||
public function testUpdatePatientEmptyAddress()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user