clqms-be/tests/feature/Patients/PatientDeleteTest.php

97 lines
3.0 KiB
PHP
Raw Normal View History

2025-09-23 10:18:48 +07:00
<?php
2025-09-25 14:01:33 +07:00
namespace Tests\Feature\Patients;
2025-09-23 10:18:48 +07:00
use CodeIgniter\Test\FeatureTestTrait;
use CodeIgniter\Test\CIUnitTestCase;
class PatientDeleteTest extends CIUnitTestCase
{
use FeatureTestTrait;
2025-09-25 14:01:33 +07:00
protected $endpoint = 'api/patient';
2025-09-23 10:18:48 +07:00
2025-10-14 15:50:22 +07:00
// // 500 error catch
// public function testDeleteWithoutInternalPID() {
// $result = $this->withBodyFormat('json')
// ->delete($this->endpoint, []);
2025-09-25 14:01:33 +07:00
2025-10-14 15:50:22 +07:00
// $result->assertStatus(500);
// $result->assertJSONFragment([
// 'status' => 500,
// 'messages' => [
// 'error' => 'Internal server error: Undefined array key "InternalPID"'
// ]
// ]);
// }
2025-09-25 14:01:33 +07:00
2025-10-14 15:50:22 +07:00
// // 400
// public function testDeleteWitWrongInternalPID() {
// $result = $this->withBodyFormat('json')
// ->delete($this->endpoint, [
// // Pilih salah satu
// // 'InternalPID' => [],
// // 'InternalPID' => 0,
// // 'InternalPID' => '0',
// // 'InternalPID' => '',
// 'InternalPID' => null,
// ]);
2025-09-25 14:01:33 +07:00
2025-10-14 15:50:22 +07:00
// $result->assertStatus(400);
// $result->assertJSONFragment([
// 'status' => 'error',
// 'message' => 'Patient ID must be a valid integer.'
// ]);
// }
2025-09-25 14:01:33 +07:00
2025-10-14 15:50:22 +07:00
// // 404 not found
// public function testDeleteNotFound() {
// $testId = 9999;
2025-09-25 14:01:33 +07:00
2025-10-14 15:50:22 +07:00
// $result = $this->withBodyFormat('json')
// ->delete($this->endpoint, [
// 'InternalPID' => $testId
// ]);
2025-09-25 14:01:33 +07:00
2025-10-14 15:50:22 +07:00
// $result->assertStatus(404);
// $result->assertJSONFragment([
// 'status' => 404,
// 'error' => 404,
// 'messages' => [
// 'error' => 'Patient ID with '.$testId.' not found.'
// ]
// ]);
// }
2025-09-25 14:01:33 +07:00
2025-10-14 15:50:22 +07:00
// // 200 ok
// public function testDeleteSuccess() {
2025-09-25 14:01:33 +07:00
2025-10-14 15:50:22 +07:00
// $testId = 3;
// // Anggap patient 1 2 3 ada di seed DB
// $result = $this->withBodyFormat('json')
// ->delete($this->endpoint, [
// 'InternalPID' => $testId
// ]);
2025-09-25 14:01:33 +07:00
2025-10-14 15:50:22 +07:00
// $result->assertStatus(200);
// $result->assertJSONFragment([
// 'status' => 'success',
// 'message' => 'Patient ID with '.$testId.' deleted successfully.'
// ]);
// }
2025-09-25 14:01:33 +07:00
2025-10-14 15:50:22 +07:00
// // 400 - SQL Inject
// public function testDeleteServerError() {
// // Simulasi: kirim input aneh yang trigger exception
// $result = $this->withBodyFormat('json')
// ->delete($this->endpoint, [
// 'InternalPID' => "' OR 1=1 --"
// ]);
// $result->assertStatus(400);
// $result->assertJSONFragment([
// 'status' => 'error',
// 'message' => 'Patient ID must be a valid integer.'
// ]);
// }
2025-09-23 10:18:48 +07:00
}