~27 ad-hoc error codes (SLOT_TAKEN, USER_NOT_FOUND, VALIDATION, …) were raw strings, so ErrorCodes::message() returned the "unknown" fallback for them. Register all 14 distinct codes as constants with their messages and replace the raw usages across AdminApiController, MyAppointmentsController, CategoryController, PreRegistrationController and ClinicInvitationController. Wire values are kept identical (verified no consumer — admin SPA, nobat724_front, tauri — switches on these strings), so this is backward compatible. Regression: tests/Shared/ErrorCodesTest (wire values preserved + message resolves). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1.5 KiB
PHP
39 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Shared;
|
|
|
|
use App\Shared\Constant\ErrorCodes;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* The legacy domain string codes are now centralised in ErrorCodes. Their wire
|
|
* values must stay identical (clients may read them) and message() must resolve
|
|
* them rather than returning the "unknown" fallback.
|
|
*/
|
|
class ErrorCodesTest extends TestCase
|
|
{
|
|
public function testWireValuesArePreserved(): void
|
|
{
|
|
$this->assertSame('SLOT_TAKEN', ErrorCodes::SLOT_TAKEN);
|
|
$this->assertSame('VALIDATION', ErrorCodes::VALIDATION);
|
|
$this->assertSame('USER_NOT_FOUND', ErrorCodes::USER_NOT_FOUND);
|
|
$this->assertSame('DOCTOR_NOT_FOUND', ErrorCodes::DOCTOR_NOT_FOUND);
|
|
$this->assertSame('FORBIDDEN', ErrorCodes::FORBIDDEN);
|
|
$this->assertSame('ERR_ACCESS_DENIED', ErrorCodes::ERR_ACCESS_DENIED);
|
|
}
|
|
|
|
public function testMessagesResolve(): void
|
|
{
|
|
$codes = [
|
|
ErrorCodes::VALIDATION, ErrorCodes::FORBIDDEN, ErrorCodes::NOT_FOUND,
|
|
ErrorCodes::USER_NOT_FOUND, ErrorCodes::DOCTOR_NOT_FOUND, ErrorCodes::DOCTOR_EXISTS,
|
|
ErrorCodes::CLINIC_NOT_FOUND, ErrorCodes::SLOT_TAKEN, ErrorCodes::SLOT_PAST,
|
|
ErrorCodes::INVALID_ROLE, ErrorCodes::DUPLICATE_REQUEST, ErrorCodes::ERR_GONE,
|
|
ErrorCodes::ERR_MOVED, ErrorCodes::ERR_ACCESS_DENIED,
|
|
];
|
|
foreach ($codes as $code) {
|
|
$this->assertNotSame('خطای ناشناخته', ErrorCodes::message($code), "message() did not resolve $code");
|
|
}
|
|
}
|
|
}
|