import Image from ‘next/image’;
status.test.js Test Suite Documentation
Overview
This Jest test suite validates the health and status endpoints across all microservices (PHPR, Config, Ticket, Account). It ensures that:
- API routing and version control are correctly configured.
- OAuth authentication is working properly.
- Log entries endpoint reports database activity.
- User information endpoints return correct user data for admin testing.
Test Scope
For each API (PHPR, Config, Ticket, Account):
- Authenticates using CAS/OAuth login to obtain a JWT token.
- Tests system-level endpoints that do not require authentication or use the bearer token.
- Tests admin-level endpoints that verify logged-in user information and roles.
Test source
The test files are API-specific (tests/<API>/status.test.js) with identical patterns adapted per service:
- PHPR uses
/open-api/v3/versioning - Config, Ticket use
/api/v1/versioning - Account follows similar pattern (see below)
Key Functionalities Tested
1. System Tests
a. Status Endpoint Check
- Makes an unauthenticated GET request to the status endpoint:
- PHPR:
GET /open-api/v3/status - Config/Ticket/Account:
GET /api/v1/status
- PHPR:
- Asserts HTTP 200 response status (routing and version control working).
- Captures JSON response body.
- Compares against snapshot for version control purposes.
b. Connection Endpoint Check
- Makes a GET request with Bearer token authorization:
GET /open-api/v3/statusor/api/v1/status. - Asserts HTTP 200 to confirm OAuth authentication is functional and the connection works correctly.
c. Log Entries Endpoint Check
- Fetches recent log entries from
log_entries:- PHPR/Config/Ticket:
GET /open-api/v3/statusor/api/v1/status/log-entries-lists/last?count=50
- PHPR/Config/Ticket:
- Verifies database logging is operational by checking logged activities.
2. Admin Tests (Require Bearer Token)
a. Logged User Information (users/logged_user/get)
- Fetches current authenticated user’s information.
- Asserts HTTP 200 response.
- Compares against snapshot for user changes monitoring.
⚠️ Note: Snapshot updates may affect permission or test integrity due to potential schema/user data changes.
b. Logged User KVS (users/logged_user_kvs/get)
- Retrieves user Key-Value Store entries for the logged-in user.
- Asserts HTTP 200 response.
- Compares against snapshot for monitoring user custom properties/attributes.
⚠️ Note: Snapshot updates may affect permission or test integrity due to potential schema/user data changes.
c. Logged User Roles (users/logged_user_roles/get)
- Fetches roles assigned to the currently authenticated user.
- Asserts HTTP 200 response.
- Compares against snapshot for monitoring role assignments and permissions.
⚠️ Note: Snapshot updates may affect permission or test integrity due to potential schema/user data changes.
d. PHPR-specific Admin Test
PHPR also includes an additional admin endpoint check that other APIs do not yet have:
Logged User Corporations (users/logged_user_corporations/get)
- Fetches corporation associations for the logged-in user (available on open-api/v3 version).
- Asserts HTTP 200 response.
- Compares against snapshot for monitoring corporate affiliations of users.
⚠️ Note: Snapshot updates may affect permission or test integrity due to potential schema/user data changes.
Environmental Setup
Each API has its own .env configuration values required:
| Environment Variable | Description |
|---|---|
<API>_BASE_URL | Base URL for the respective API (e.g., PHPR_BASE_URL, CONFIG_BASE_URL) |
<API>_LOGIN_URL | OAuth login endpoint to fetch token (via scripts/login-cas.js) |
<API>_USERNAME | Username credentials for testing |
<API>_PASSWORD | Password credentials for testing |
Authentication Flow
All tests use the CAS/OAuth authentication flow via scripts/login-cas.js:
const { getOAuthToken } = require("../../scripts/login-cas.js");
// Before all tests, acquire token once:
token = await getOAuthToken(
process.env.<API>_LOGIN_URL,
process.env.<API>_USERNAME,
process.env.<API>_PASSWORD
);The token is cached in a variable and reused across all test cases within the same suite. This avoids redundant authentication requests and ensures consistent authorization state during testing.
Notes
- Tests are designed as simple health checks for infrastructure monitoring.
- Snapshots serve version control purposes to detect unexpected API response structure changes.
- The skipped “diagnostic endpoint” test is intentionally disabled (pending future implementation).
- Each status suite runs independently per API with a timeout of 60 seconds (
beforeAll(..., 60000)).