159 lines
5.7 KiB
PHP
159 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Patients;
|
|
|
|
use CodeIgniter\Test\FeatureTestTrait;
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
|
use Faker\Factory;
|
|
|
|
class PatientUpdateTest extends CIUnitTestCase
|
|
{
|
|
use FeatureTestTrait;
|
|
protected $endpoint = 'api/patient';
|
|
|
|
public function testUpdatePatientSuccess()
|
|
{
|
|
$faker = Factory::create('id_ID');
|
|
|
|
$payload = [
|
|
"InternalPID" => 1,
|
|
"PatientID" => "UPDT" . $faker->numberBetween(100, 999),
|
|
"NameFirst" => $faker->firstName,
|
|
"NameLast" => $faker->lastName,
|
|
"Gender" => (string) $faker->numberBetween(5, 6),
|
|
"Birthdate" => $faker->date('Y-m-d'),
|
|
"DeathDateTime" => null,
|
|
"EmailAddress1" => "asasa@gmail.com",
|
|
"PlaceOfBirth" => $faker->city,
|
|
"Race" => (string) $faker->numberBetween(175, 205),
|
|
"Religion" => (string) $faker->numberBetween(206, 212),
|
|
"Country" => (string) $faker->numberBetween(221, 469),
|
|
"MaritalStatus" => (string) $faker->numberBetween(8, 15),
|
|
"Citizenship" => "WNI",
|
|
"LinkTo" => null,
|
|
"PatIdt" => [
|
|
"IdentifierType" => "KTP",
|
|
"Identifier" => $faker->nik(),
|
|
],
|
|
"PatCom" => $faker->sentence(5),
|
|
"PatAtt" => [
|
|
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ],
|
|
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ]
|
|
]
|
|
];
|
|
|
|
$result = $this->withBodyFormat('json')->patch($this->endpoint, $payload);
|
|
|
|
$result->assertStatus(201);
|
|
}
|
|
|
|
// /**
|
|
// * ❌ Test gagal karena InternalPID kosong (validasi)
|
|
// */
|
|
public function testUpdatePatientValidationError()
|
|
{
|
|
$faker = Factory::create('id_ID');
|
|
|
|
$payload = [
|
|
"NameFirst" => $faker->firstName,
|
|
"Gender" => (string) $faker->numberBetween(5, 6),
|
|
"Birthdate" => $faker->date('Y-m-d'),
|
|
// Tidak kirim InternalPID
|
|
];
|
|
|
|
$result = $this->withBodyFormat('json')->patch($this->endpoint, $payload);
|
|
$json = $result->getJSON();
|
|
$data = json_decode($json, true);
|
|
|
|
$result->assertStatus(400);
|
|
$this->assertArrayHasKey('errors', $data);
|
|
}
|
|
|
|
// /**
|
|
// * ✅ Test update dengan address baru & hapus address lama
|
|
// */
|
|
public function testUpdatePatientWithAddressChange()
|
|
{
|
|
$faker = Factory::create('id_ID');
|
|
|
|
$payload = [
|
|
"InternalPID" => 1,
|
|
"PatientID" => "UPDT" . $faker->numberBetween(100, 999),
|
|
"NameFirst" => $faker->firstName,
|
|
"NameLast" => $faker->lastName,
|
|
"Gender" => (string) $faker->numberBetween(5, 6),
|
|
"Birthdate" => $faker->date('Y-m-d'),
|
|
"DeathDateTime" => null,
|
|
"EmailAddress1" => "asasa@gmail.com",
|
|
"PlaceOfBirth" => $faker->city,
|
|
"Race" => (string) $faker->numberBetween(175, 205),
|
|
"Religion" => (string) $faker->numberBetween(206, 212),
|
|
"Country" => (string) $faker->numberBetween(221, 469),
|
|
"MaritalStatus" => (string) $faker->numberBetween(8, 15),
|
|
"Citizenship" => "WNI",
|
|
"LinkTo" => null,
|
|
"PatIdt" => [
|
|
"IdentifierType" => "KTP",
|
|
"Identifier" => $faker->nik(),
|
|
],
|
|
"PatCom" => $faker->sentence(5),
|
|
"PatAtt" => [
|
|
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ],
|
|
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ],
|
|
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ],
|
|
[ "Address" => "/api/upload/" . $faker->word . ".jpg" ]
|
|
]
|
|
];
|
|
|
|
$result = $this->withBodyFormat('json')->patch($this->endpoint, $payload);
|
|
|
|
$result->assertStatus(201);
|
|
|
|
$json = $result->getJSON();
|
|
$data = json_decode($json, true);
|
|
|
|
$this->assertEquals('success', $data['status']);
|
|
}
|
|
|
|
// /**
|
|
// * ⚠️ Test update kosong → semua pattat address dihapus (soft delete)
|
|
// */
|
|
public function testUpdatePatientEmptyAddress()
|
|
{
|
|
$faker = Factory::create('id_ID');
|
|
|
|
$payload = [
|
|
"InternalPID" => 1,
|
|
"PatientID" => "UPDT" . $faker->numberBetween(100, 999),
|
|
"NameFirst" => $faker->firstName,
|
|
"NameLast" => $faker->lastName,
|
|
"Gender" => (string) $faker->numberBetween(5, 6),
|
|
"Birthdate" => $faker->date('Y-m-d'),
|
|
"DeathDateTime" => null,
|
|
"EmailAddress1" => "asasa@gmail.com",
|
|
"PlaceOfBirth" => $faker->city,
|
|
"Race" => (string) $faker->numberBetween(175, 205),
|
|
"Religion" => (string) $faker->numberBetween(206, 212),
|
|
"Country" => (string) $faker->numberBetween(221, 469),
|
|
"MaritalStatus" => (string) $faker->numberBetween(8, 15),
|
|
"Citizenship" => "WNI",
|
|
"LinkTo" => null,
|
|
"PatIdt" => [
|
|
"IdentifierType" => "KTP",
|
|
"Identifier" => $faker->nik(),
|
|
],
|
|
"PatCom" => $faker->sentence(5),
|
|
"PatAtt" => []
|
|
];
|
|
|
|
$result = $this->withBodyFormat('json')->patch($this->endpoint, $payload);
|
|
|
|
$json = $result->getJSON();
|
|
$data = json_decode($json, true);
|
|
|
|
$result->assertStatus(201);
|
|
$this->assertEquals('success', $data['status']);
|
|
}
|
|
|
|
}
|