From 3e151583df26256fb0f97c3732687b14cf88e92e Mon Sep 17 00:00:00 2001 From: mikael-zakaria Date: Fri, 26 Sep 2025 14:11:25 +0700 Subject: [PATCH] Update Unit Testing Patients --- tests/feature/Patients/PatientCreateTest.php | 143 +++++++------------ tests/feature/Patients/PatientUpdateTest.php | 1 + 2 files changed, 55 insertions(+), 89 deletions(-) diff --git a/tests/feature/Patients/PatientCreateTest.php b/tests/feature/Patients/PatientCreateTest.php index 7430535..637dced 100644 --- a/tests/feature/Patients/PatientCreateTest.php +++ b/tests/feature/Patients/PatientCreateTest.php @@ -10,103 +10,69 @@ class PatientCreateTest extends CIUnitTestCase use FeatureTestTrait; protected $endpoint = 'api/patient'; - // public function testCreatePatientValidationFail() - // { - // // error 400 yg diharapkan - // $payload = ['Name' => 'Ngawur']; - // $result = $this->withBodyFormat('json') - // ->call('post', 'api/patient', $payload); - // $result->assertStatus(400); - // $result->assertJSONFragment([ - // 'status' => 'error' - // ]); + public function testCreatePatientValidationFail() + { + // error 400 yg diharapkan + $payload = ['Name' => 'Ngawur']; + $result = $this->withBodyFormat('json') + ->call('post', 'api/patient', $payload); + $result->assertStatus(400); + $result->assertJSONFragment([ + 'status' => 'error' + ]); - // // Kondisi Jika PatiD Sama - // $payload = [ - // "PatientID"=> "SMAJ1", - // "AlternatePID"=> "ALT001234", - // "Prefix"=> "Mr.", - // "NameFirst"=> "Budi", - // "NameMiddle"=> "Santoso", - // "NameMaiden"=> "Kiki", - // "NameLast"=> "Wijaya", - // "Suffix"=> "S.kom", - // "NameAlias"=> "Bud", - // "Gender"=> "1", - // ]; - // $result = $this->withBodyFormat('json') - // ->call('post', 'api/patient', $payload); - // $result->assertStatus(400); - // $result->assertJSONFragment([ - // 'status' => 'error', - // "message" => "Validation failed (patient)", - // ]); - - // } - - // // Wajib Diganti ya payloadnya kalau mau dijalankan - // public function testCreateSuccess() - // { - // $payload = [ - // "PatientID"=> "SMAJ6", //Wajib Ganti - // "AlternatePID"=> "P0234", - // "Prefix"=> "Mr.", - // "NameFirst"=> "Budi", - // "NameMiddle"=> "Santoso", - // "NameMaiden"=> "Kiki", - // "NameLast"=> "Wijaya", - // "Suffix"=> "S.kom", - // "NameAlias"=> "Bud", - // "Gender"=> "1", - // 'EmailAddress1' => 'kaka@gmail.a1com', //Wajib Ganti - // 'Identity' => [ - // "IdentifierType" => "KTP", - // "Identifier" => "317409050590100" //Wajib Ganti - // ] - // ]; - - // // $result = $this->call('post', 'api/patient', $payload); - // $result = $this->withBodyFormat('json') - // ->call('post', 'api/patient', $payload); - - // $result->assertStatus(201); - // $result->assertJSONFragment([ - // 'status' => 'success', - // ]); - // } - - // dd($result); - - public function testCreatePatientSuccess() { + // Kondisi Jika PatiD Sama $payload = [ - "PatientID" => "PX004", - "NameFirst" => "Johan", - "NameLast" => "Doe", - "Gender" => 1, - "Birthdate" => "1990-01-01", - "EmailAddress1" => "johnaa@examaple.com", - "Identity" => [ + "PatientID"=> "SMAJ1", + "AlternatePID"=> "ALT001234", + "Prefix"=> "Mr.", + "NameFirst"=> "Budi", + "NameMiddle"=> "Santoso", + "NameMaiden"=> "Kiki", + "NameLast"=> "Wijaya", + "Suffix"=> "S.kom", + "NameAlias"=> "Bud", + "Gender"=> "1", + ]; + $result = $this->withBodyFormat('json') + ->call('post', 'api/patient', $payload); + $result->assertStatus(400); + $result->assertJSONFragment([ + 'status' => 'error', + "message" => "Validation failed (patient)", + ]); + + } + + // Wajib Diganti ya payloadnya kalau mau dijalankan + public function testCreatePatientSuccess() + { + $payload = [ + "PatientID"=> "SMAJ6", //Wajib Ganti + "AlternatePID"=> "P0234", + "Prefix"=> "Mr.", + "NameFirst"=> "Budi", + "NameMiddle"=> "Santoso", + "NameMaiden"=> "Kiki", + "NameLast"=> "Wijaya", + "Suffix"=> "S.kom", + "NameAlias"=> "Bud", + "Gender"=> "1", + 'EmailAddress1' => 'kaka@gmail.a1com', //Wajib Ganti + 'Identity' => [ "IdentifierType" => "KTP", - "Identifier" => "1232457893", - ], - "Attachments" => [ - ["Address" => "Jl. Mawar No.1"] - ], - "Comment" => "Pasien test" + "Identifier" => "317409050590100" //Wajib Ganti + ] ]; - $result = $this->withBodyFormat('json')->post($this->endpoint, $payload); + // $result = $this->call('post', 'api/patient', $payload); + $result = $this->withBodyFormat('json') + ->call('post', 'api/patient', $payload); $result->assertStatus(201); $result->assertJSONFragment([ - "status" => "success", - "message" => "Patient created successfully" + 'status' => 'success', ]); - - - // $data = json_decode($result->getBody(), true); - // $this->assertArrayHasKey("data", $data); - // $this->assertIsInt($data["data"]); // InternalPID } // public function testCreatePatientValidationError() { @@ -254,5 +220,4 @@ class PatientCreateTest extends CIUnitTestCase // $result->assertStatus(201); // } - } diff --git a/tests/feature/Patients/PatientUpdateTest.php b/tests/feature/Patients/PatientUpdateTest.php index 141207c..b128557 100644 --- a/tests/feature/Patients/PatientUpdateTest.php +++ b/tests/feature/Patients/PatientUpdateTest.php @@ -9,6 +9,7 @@ class PatientUpdateTest extends CIUnitTestCase { use FeatureTestTrait; + // Belon // public function testUpdateFail() // {