clqms-be/tests/UniformShowTest_README.md
root 2bcdf09b55 chore: repo-wide normalization + rules test coverage
Normalize formatting/line endings across configs, controllers, models, tests, and OpenAPI specs.

Update rule expression/rule engine implementation and remove obsolete RuleAction controller/model.

Add unit tests for rule expression syntax and multi-action behavior, and include docs updates.
2026-03-16 07:24:50 +07:00

34 lines
1.4 KiB
Markdown

# Uniform Show Endpoints Testing
This document describes the testing strategy and execution for ensuring all API `show` endpoints follow a uniform response structure.
## Requirement
All `show` endpoints (e.g., `/api/location/1`, `/api/patient/1`, etc.) must return:
1. **A single Object** (associative array) in the `data` field when a record is found.
2. **Null** in the `data` field when a record is not found.
Previously, some endpoints returned a sequential array with one item, which was inconsistent for frontend development.
## Test Suite
The test suite is located at: `tests/feature/UniformShowTest.php`
### What it tests:
- **`testShowEndpointsReturnObjectWhenFound`**: Iterates through a list of known endpoints and verifies that if data is returned, it is an associative array (object) and not a sequential array.
- **`testShowEndpointsReturnNullWhenNotFound`**: Iterates through endpoints with non-existent IDs and verifies that the `data` field is strictly `null`.
## How to Run
Ensure your test database is configured in `phpunit.xml` or `.env`.
Run the following command from the project root:
```bash
vendor/bin/phpunit tests/feature/UniformShowTest.php
```
## Maintenance
If you add a new resource with a `show` method, add its endpoint to the `$endpoints` array in `tests/feature/UniformShowTest.php` to ensure it remains compliant with the uniformity requirement.