- Introduced `ApiErrorTranslator` to normalize and translate API error messages, providing clearer feedback in French. - Updated all Filament pages (Articles, Documents, Divers, Journaux, Tiers, TablesExplorer) to utilize the new error translation mechanism, improving user experience during API interactions. - Added validation for required fields before API calls, ensuring users receive immediate feedback when mandatory inputs are missing. - Implemented tracking properties to distinguish between "never searched" and "searched without results," enhancing the user interface. - Removed the obsolete `$results` property from the Articles page and added a new `$barcode` property to align with API requirements. - Updated documentation to reflect changes in API behavior and error handling, including new metadata returned by the `art_list` endpoint. - Added new tests to verify the functionality of the barcode handling and validation logic.
60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Support\ApiErrorTranslator;
|
|
|
|
it('returns null for null error', function () {
|
|
expect(ApiErrorTranslator::translate(null))->toBeNull();
|
|
});
|
|
|
|
it('returns null for empty string error', function () {
|
|
expect(ApiErrorTranslator::translate(''))->toBeNull();
|
|
});
|
|
|
|
it('normalizes array error to string', function () {
|
|
$result = ApiErrorTranslator::translate(['Error one', 'Error two']);
|
|
|
|
expect($result)->toContain('Error one');
|
|
expect($result)->toContain('Error two');
|
|
});
|
|
|
|
it('returns string error as-is when no explanation found', function () {
|
|
expect(ApiErrorTranslator::translate('Some unknown error'))->toBe('Some unknown error');
|
|
});
|
|
|
|
it('adds explanation for known search terms error', function () {
|
|
$result = ApiErrorTranslator::translate('Search terms are required. Please provide search criteria.');
|
|
|
|
expect($result)->toContain('Search terms are required');
|
|
expect($result)->toContain('Explication');
|
|
expect($result)->toContain('Le champ de recherche est obligatoire.');
|
|
});
|
|
|
|
it('adds explanation for invalid api key error', function () {
|
|
$result = ApiErrorTranslator::translate('Invalid API key provided');
|
|
|
|
expect($result)->toContain('Invalid API key');
|
|
expect($result)->toContain('Explication');
|
|
expect($result)->toContain('cle API');
|
|
});
|
|
|
|
it('adds explanation for unknown stkid error', function () {
|
|
$result = ApiErrorTranslator::translate('Unknown STKID');
|
|
|
|
expect($result)->toContain('Unknown STKID');
|
|
expect($result)->toContain('Explication');
|
|
expect($result)->toContain('STKID');
|
|
});
|
|
|
|
it('adds explanation for array error with known pattern', function () {
|
|
$result = ApiErrorTranslator::translate(['Search terms are required. Please provide search criteria.']);
|
|
|
|
expect($result)->toContain('Explication');
|
|
expect($result)->toContain('Le champ de recherche est obligatoire.');
|
|
});
|
|
|
|
it('normalizes mixed array values', function () {
|
|
$result = ApiErrorTranslator::normalize([123, 'text', null]);
|
|
|
|
expect($result)->toBe('123 text ');
|
|
});
|