clqms-be/tests/feature/Patients/PatientCheckTest.php
root 30c4e47304 chore(repo): normalize EOL and harden contact patch flow
- handle contact PATCH failures by checking model save result and returning HTTP 400 with the model error message
- update ContactDetailModel nested updates to enforce active-detail checks and use model update() with explicit failure propagation
- extend contact patch assertions and align test-create variants expectations to status=success for POST responses
- refresh composer lock metadata/dependency constraints and include generated docs/data/test files updated during normalization
- impact: API contract unchanged except clearer 400 error responses on invalid contact detail updates
2026-04-17 05:38:11 +07:00

120 lines
3.7 KiB
PHP
Executable File

<?php
namespace Tests\Feature\Patients;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\FeatureTestTrait;
use Faker\Factory;
class PatientCheckTest extends CIUnitTestCase
{
use FeatureTestTrait;
protected $endpoint = 'api/patient/check';
public function testCheckPatientIDExists()
{
$result = $this->withHeaders(['Accept' => 'application/json'])->call('get', $this->endpoint, [
'PatientID' => 'SMAJ1',
]);
$result->assertStatus(200);
$data = json_decode($result->getJSON(), true);
$this->assertSame('success', $data['status']);
$this->assertSame(false, $data['data']);
}
public function testCheckPatientIDWithHyphenExists()
{
$result = $this->withHeaders(['Accept' => 'application/json'])->call('get', $this->endpoint, [
'PatientID' => 'SMAJ-1',
]);
$result->assertStatus(200);
$data = json_decode($result->getJSON(), true);
$this->assertSame('success', $data['status']);
$this->assertIsBool($data['data']);
}
public function testCheckPatientIDNotExists()
{
$faker = Factory::create();
$result = $this->withHeaders(['Accept' => 'application/json'])->call('get', $this->endpoint, [
'PatientID' => 'NONEXISTENT-' . $faker->numberBetween(100000, 999999),
]);
$result->assertStatus(200);
$data = json_decode($result->getJSON(), true);
$this->assertSame('success', $data['status']);
$this->assertTrue($data['data']);
}
public function testCheckEmailAddressExists()
{
$result = $this->withHeaders(['Accept' => 'application/json'])->call('get', $this->endpoint, [
'EmailAddress' => 'dummy1@test.com',
]);
$result->assertStatus(200);
$data = json_decode($result->getJSON(), true);
$this->assertSame('success', $data['status']);
$this->assertIsBool($data['data']);
}
public function testCheckEmailAddressMatchesSecondaryColumn()
{
$result = $this->withHeaders(['Accept' => 'application/json'])->call('get', $this->endpoint, [
'EmailAddress' => 'dummy1@test.com',
]);
$result->assertStatus(200);
$data = json_decode($result->getJSON(), true);
$this->assertSame('success', $data['status']);
$this->assertIsBool($data['data']);
}
public function testCheckPhoneExists()
{
$result = $this->withHeaders(['Accept' => 'application/json'])->call('get', $this->endpoint, [
'Phone' => '092029',
]);
$result->assertStatus(200);
$data = json_decode($result->getJSON(), true);
$this->assertSame('success', $data['status']);
$this->assertIsBool($data['data']);
}
public function testCheckWithoutParams()
{
$result = $this->withHeaders(['Accept' => 'application/json'])->call('get', $this->endpoint);
$result->assertStatus(400);
$data = json_decode($result->getJSON(), true);
$this->assertSame('error', $data['status']);
$this->assertSame('PatientID, EmailAddress, or Phone parameter is required.', $data['message']);
}
public function testCheckResponseStructure()
{
$result = $this->withHeaders(['Accept' => 'application/json'])->call('get', $this->endpoint, [
'PatientID' => 'TEST123',
]);
$result->assertStatus(200);
$data = json_decode($result->getJSON(), true);
$this->assertArrayHasKey('status', $data);
$this->assertArrayHasKey('message', $data);
$this->assertArrayHasKey('data', $data);
}
}