Implement CRUD functionality for Articles and Tiers with enhanced API documentation

- Introduced new endpoints for creating and modifying articles (`art_add`, `art_mod`) and tiers (`third_add`, `third_mod`), allowing users to manage these entities effectively.
- Updated the Articles and Tiers pages to include forms for adding and modifying records, complete with parameter tables for clear guidance on required inputs.
- Enhanced the API documentation to include detailed descriptions, examples, and metadata for the new endpoints, improving usability and understanding for developers.
- Created a new rule for writing conventions with French accents to ensure consistency across the project.
- Updated existing documentation to reflect structural changes and added a summary table for CRUD operations.
- Added tests to verify the functionality of the new features and ensure robust error handling.
This commit is contained in:
2026-02-23 15:55:09 +01:00
parent b95ee46b1c
commit 714bdc3dd7
15 changed files with 1479 additions and 145 deletions

View File

@@ -169,3 +169,147 @@ it('displays error message on API failure', function () {
expect(true)->toBeTrue();
});
// --- art_add ---
it('adds an article via art_add', function () {
Http::fake([
'*/art_add' => Http::response([
'data' => ['artid' => 'ART001'],
'metadata' => ['rowcount' => 1, 'issuccess' => true],
'error' => null,
]),
]);
Livewire::test(Articles::class)
->set('mode', 'write')
->set('addArtId', 'ART001')
->set('addName', 'Test Article')
->set('addSalePrice', '49.99')
->call('addArticle')
->assertSet('hasAdded', true)
->assertSet('addResult', ['artid' => 'ART001'])
->assertSet('errorMessage', null);
Http::assertSent(function ($request) {
$body = $request->data();
return str_contains($request->url(), 'art_add')
&& $body['ARTID'] === 'ART001'
&& $body['NAME1'] === 'Test Article'
&& $body['SALEPRICE'] === '49.99';
});
});
it('shows validation error when addArtId is empty', function () {
Http::fake();
Livewire::test(Articles::class)
->set('mode', 'write')
->call('addArticle')
->assertSet('hasAdded', false)
->assertSet('errorMessage', 'Le champ identifiant article (ARTID) est obligatoire.');
Http::assertNothingSent();
});
it('omits optional params when empty on art_add', function () {
Http::fake([
'*/art_add' => Http::response([
'data' => ['artid' => 'ART001'],
'metadata' => ['rowcount' => 1, 'issuccess' => true],
'error' => null,
]),
]);
Livewire::test(Articles::class)
->set('mode', 'write')
->set('addArtId', 'ART001')
->set('addName', '')
->set('addSalePrice', '')
->call('addArticle');
Http::assertSent(function ($request) {
$body = $request->data();
return $body['ARTID'] === 'ART001'
&& ! array_key_exists('NAME1', $body)
&& ! array_key_exists('SALEPRICE', $body);
});
});
it('handles API error on art_add (duplicate)', function () {
Http::fake([
'*/art_add' => Http::response([
'data' => ['xml' => '<VFPData><headererror><errorcode>001</errorcode><description>Artid already exist</description></headererror></VFPData>'],
'metadata' => ['rowcount' => 1, 'issuccess' => false],
'error' => ['Code: 001, Description: Artid already exist'],
]),
]);
$component = Livewire::test(Articles::class)
->set('mode', 'write')
->set('addArtId', 'ART001')
->call('addArticle');
expect($component->get('errorMessage'))->toContain('Artid already exist');
});
// --- art_mod ---
it('modifies an article via art_mod', function () {
Http::fake([
'*/art_mod' => Http::response([
'data' => ['artid' => 'ART001'],
'metadata' => ['rowcount' => 1, 'issuccess' => true],
'error' => null,
]),
]);
Livewire::test(Articles::class)
->set('mode', 'write')
->set('modArtId', 'ART001')
->set('modName', 'Updated Name')
->set('modSalePrice', '59.99')
->call('modArticle')
->assertSet('hasModified', true)
->assertSet('modResult', ['artid' => 'ART001'])
->assertSet('errorMessage', null);
Http::assertSent(function ($request) {
$body = $request->data();
return str_contains($request->url(), 'art_mod')
&& $body['ARTID'] === 'ART001'
&& $body['NAME1'] === 'Updated Name';
});
});
it('shows validation error when modArtId is empty', function () {
Http::fake();
Livewire::test(Articles::class)
->set('mode', 'write')
->call('modArticle')
->assertSet('hasModified', false)
->assertSet('errorMessage', 'Le champ identifiant article (ARTID) est obligatoire.');
Http::assertNothingSent();
});
it('handles API error on art_mod (not found)', function () {
Http::fake([
'*/art_mod' => Http::response([
'data' => ['xml' => '<VFPData><headererror><errorcode>001</errorcode><description>Artid does not exist</description></headererror></VFPData>'],
'metadata' => ['rowcount' => 1, 'issuccess' => false],
'error' => ['Code: 001, Description: Artid does not exist'],
]),
]);
$component = Livewire::test(Articles::class)
->set('mode', 'write')
->set('modArtId', 'INEXISTANT')
->call('modArticle');
expect($component->get('errorMessage'))->toContain('Artid does not exist');
});