2026-01-12 16:53:41 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Feature\ValueSet;
|
|
|
|
|
|
|
|
|
|
use CodeIgniter\Test\FeatureTestTrait;
|
|
|
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
|
|
|
|
use App\Libraries\ValueSet;
|
|
|
|
|
|
2026-01-13 16:48:43 +07:00
|
|
|
class ValueSetControllerTest extends CIUnitTestCase
|
2026-01-12 16:53:41 +07:00
|
|
|
{
|
|
|
|
|
use FeatureTestTrait;
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
ValueSet::clearCache();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-13 16:48:43 +07:00
|
|
|
public function testIndexReturnsAllLookupsWithCounts()
|
2026-01-12 16:53:41 +07:00
|
|
|
{
|
|
|
|
|
$result = $this->call('get', 'api/valueset');
|
|
|
|
|
|
|
|
|
|
$result->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
$json = $result->getJSON();
|
|
|
|
|
$data = json_decode($json, true);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('success', $data['status']);
|
2026-01-13 16:48:43 +07:00
|
|
|
$this->assertIsArray($data['data']);
|
|
|
|
|
$this->assertArrayHasKey('sex', $data['data']);
|
2026-01-12 16:53:41 +07:00
|
|
|
$this->assertArrayHasKey('specimen_type', $data['data']);
|
|
|
|
|
$this->assertArrayHasKey('order_priority', $data['data']);
|
|
|
|
|
$this->assertArrayHasKey('specimen_status', $data['data']);
|
2026-01-13 16:48:43 +07:00
|
|
|
$this->assertIsInt($data['data']['sex']);
|
|
|
|
|
$this->assertGreaterThan(0, $data['data']['sex']);
|
2026-01-12 16:53:41 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testShowByNameReturnsSingleLookup()
|
|
|
|
|
{
|
2026-01-13 16:48:43 +07:00
|
|
|
$result = $this->call('get', 'api/valueset/sex');
|
2026-01-12 16:53:41 +07:00
|
|
|
|
|
|
|
|
$result->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
$json = $result->getJSON();
|
|
|
|
|
$data = json_decode($json, true);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('success', $data['status']);
|
|
|
|
|
$this->assertIsArray($data['data']);
|
|
|
|
|
$this->assertNotEmpty($data['data']);
|
|
|
|
|
$this->assertArrayHasKey('value', $data['data'][0]);
|
|
|
|
|
$this->assertArrayHasKey('label', $data['data'][0]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-13 16:48:43 +07:00
|
|
|
public function testShowByNameSexReturnsCorrectValues()
|
2026-01-12 16:53:41 +07:00
|
|
|
{
|
2026-01-13 16:48:43 +07:00
|
|
|
$result = $this->call('get', 'api/valueset/sex');
|
2026-01-12 16:53:41 +07:00
|
|
|
|
|
|
|
|
$result->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
$json = $result->getJSON();
|
|
|
|
|
$data = json_decode($json, true);
|
|
|
|
|
|
|
|
|
|
$values = array_column($data['data'], 'value');
|
|
|
|
|
$labels = array_column($data['data'], 'label');
|
|
|
|
|
|
|
|
|
|
$this->assertContains('1', $values);
|
|
|
|
|
$this->assertContains('2', $values);
|
|
|
|
|
$this->assertContains('Female', $labels);
|
|
|
|
|
$this->assertContains('Male', $labels);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testShowByNameInvalidLookupReturns404()
|
|
|
|
|
{
|
|
|
|
|
$result = $this->call('get', 'api/valueset/nonexistent_lookup');
|
|
|
|
|
|
|
|
|
|
$result->assertStatus(404);
|
|
|
|
|
|
|
|
|
|
$json = $result->getJSON();
|
|
|
|
|
$data = json_decode($json, true);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('error', $data['status']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testShowByNameOrderPriority()
|
|
|
|
|
{
|
|
|
|
|
$result = $this->call('get', 'api/valueset/order_priority');
|
|
|
|
|
|
|
|
|
|
$result->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
$json = $result->getJSON();
|
|
|
|
|
$data = json_decode($json, true);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('success', $data['status']);
|
|
|
|
|
$this->assertIsArray($data['data']);
|
|
|
|
|
|
|
|
|
|
$labels = array_column($data['data'], 'label');
|
|
|
|
|
$this->assertContains('Stat', $labels);
|
|
|
|
|
$this->assertContains('ASAP', $labels);
|
|
|
|
|
$this->assertContains('Routine', $labels);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-13 16:48:43 +07:00
|
|
|
public function testRefreshClearsCache()
|
2026-01-12 16:53:41 +07:00
|
|
|
{
|
2026-01-13 16:48:43 +07:00
|
|
|
ValueSet::getAll();
|
2026-01-12 16:53:41 +07:00
|
|
|
|
2026-01-13 16:48:43 +07:00
|
|
|
$result = $this->call('post', 'api/valueset/refresh');
|
2026-01-12 16:53:41 +07:00
|
|
|
|
|
|
|
|
$result->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
$json = $result->getJSON();
|
|
|
|
|
$data = json_decode($json, true);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('success', $data['status']);
|
2026-01-13 16:48:43 +07:00
|
|
|
$this->assertEquals('Cache cleared', $data['message']);
|
2026-01-12 16:53:41 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testShowByNameSpecimenStatus()
|
|
|
|
|
{
|
|
|
|
|
$result = $this->call('get', 'api/valueset/specimen_status');
|
|
|
|
|
|
|
|
|
|
$result->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
$json = $result->getJSON();
|
|
|
|
|
$data = json_decode($json, true);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('success', $data['status']);
|
|
|
|
|
$this->assertIsArray($data['data']);
|
|
|
|
|
|
|
|
|
|
$values = array_column($data['data'], 'value');
|
|
|
|
|
$labels = array_column($data['data'], 'label');
|
|
|
|
|
|
|
|
|
|
$this->assertContains('STC', $values);
|
|
|
|
|
$this->assertContains('SCtd', $values);
|
|
|
|
|
$this->assertContains('To be collected', $labels);
|
|
|
|
|
$this->assertContains('Collected', $labels);
|
|
|
|
|
}
|
|
|
|
|
}
|