'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 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" => "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', ]); } // public function testCreatePatientValidationError() { // $payload = [ // "NameFirst" => "Jane" // PatientID kosong // ]; // $result = $this->withBodyFormat('json')->post($this->endpoint, $payload); // $result->assertStatus(422); // $result->assertJSONFragment(["field" => "patient"]); // } // public function testCreatePatidtValidationError() { // $payload = [ // "PatientID" => "PX002", // "NameFirst" => "Jane", // "Identity" => [ // "IdentifierType" => null, // "Identifier" => null // ] // ]; // $result = $this->withBodyFormat('json')->post($this->endpoint, $payload); // $result->assertStatus(422); // $result->assertJSONFragment(["field" => "patidt"]); // } // public function testCreateWithoutAttachments() { // $payload = [ // "PatientID" => "PX003", // "NameFirst" => "NoAttach", // "Identity" => [ // "IdentifierType" => "KTP", // "Identifier" => "99999" // ] // ]; // $result = $this->withBodyFormat('json')->post($this->endpoint, $payload); // $result->assertStatus(201); // } // public function testCreateWithoutComment() { // $payload = [ // "PatientID" => "PX004", // "NameFirst" => "NoComment", // "Identity" => [ // "IdentifierType" => "SIM", // "Identifier" => "A12345" // ], // "Attachments" => [ // ["Address" => "Jl. Melati No.2"] // ] // ]; // $result = $this->withBodyFormat('json')->post($this->endpoint, $payload); // $result->assertStatus(201); // } // public function testCreateDatabaseError() { // // Insert patient pertama // $payload = [ // "InternalPID" => 999, // Force ID // "PatientID" => "PX005", // "NameFirst" => "First", // "Identity" => [ // "IdentifierType" => "KTP", // "Identifier" => "DBERR1" // ] // ]; // $this->withBodyFormat('json')->post($this->endpoint, $payload); // // Insert kedua dengan InternalPID sama → trigger error // $payload["NameFirst"] = "Second"; // $payload["Identity"]["Identifier"] = "DBERR2"; // $result = $this->withBodyFormat('json')->post($this->endpoint, $payload); // $result->assertStatus(500); // } // 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); // } // public function testCreateWithLinkTo() { // $payload = [ // "PatientID" => "PX008", // "NameFirst" => "LinkTo", // "Identity" => [ // "IdentifierType" => "KTP", // "Identifier" => "LINK123" // ], // "LinkTo" => [ // ["InternalPID" => 1], // ["InternalPID" => 2] // ] // ]; // $result = $this->withBodyFormat('json')->post($this->endpoint, $payload); // $result->assertStatus(201); // $data = json_decode($result->getBody(), true); // $this->assertIsInt($data["data"]); // } // public function testCreateWithNumericAndNullFields() { // $payload = [ // "PatientID" => "PX009", // "NameFirst" => "Numeric", // "Gender" => null, // "RaceID" => "3", // "DeathIndicator" => 0, // "Identity" => [ // "IdentifierType" => "SIM", // "Identifier" => "NUM123" // ] // ]; // $result = $this->withBodyFormat('json')->post($this->endpoint, $payload); // $result->assertStatus(201); // } }