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');
});

View File

@@ -35,10 +35,9 @@ it('generates heading IDs matching the table of contents anchors', function () {
'5-tables-et-colonnes-disponibles',
'6-récupération-de-données',
'7-envoi-de-données',
'8-endpoints-non-fonctionnels',
'9-relations-entre-entités',
'10-remarques-et-points-dattention',
'11-ressources-externes',
'8-relations-entre-entités',
'9-remarques-et-points-dattention',
'10-ressources-externes',
];
foreach ($anchors as $anchor) {
@@ -81,5 +80,10 @@ it('documents all service endpoints', function () {
->assertSee('third_list')
->assertSee('third_GetArtHistory')
->assertSee('getserialnumber')
->assertSee('codes_list');
->assertSee('codes_list')
->assertSee('custom_geninv_updatestock')
->assertSee('art_add')
->assertSee('art_mod')
->assertSee('third_add')
->assertSee('third_mod');
});

View File

@@ -205,6 +205,128 @@ it('sends correct parameters for custom_geninv_updatestock', function () {
});
});
it('sends correct parameters for document_add', function () {
Http::fake([
'*' => Http::response(['data' => ['number' => '2026/0001'], 'metadata' => ['rowcount' => 1, 'issuccess' => true], 'error' => null]),
]);
$service = app(LogisticsService::class);
$params = [
'ThirdId' => 'CUST001',
'Date' => '2026-02-20',
'Artid' => ['ART001', 'ART002'],
'Qty' => ['2', '5'],
'Saleprice' => ['10.00', '25.50'],
'JNL' => 'VEN',
];
$service->documentAdd($params);
Http::assertSent(function ($request) {
$body = $request->data();
return str_contains($request->url(), 'document_add')
&& $body['ThirdId'] === 'CUST001'
&& $body['JNL'] === 'VEN'
&& $body['Artid'] === ['ART001', 'ART002'];
});
});
it('sends correct parameters for document_mod', function () {
Http::fake([
'*' => Http::response(['data' => ['updated' => true], 'metadata' => ['rowcount' => 1, 'issuccess' => true], 'error' => null]),
]);
$service = app(LogisticsService::class);
$params = [
'number' => '2026/0001',
'JNL' => 'VEN',
'Thirdid' => 'CUST002',
];
$service->documentMod($params);
Http::assertSent(function ($request) {
$body = $request->data();
return str_contains($request->url(), 'document_mod')
&& $body['number'] === '2026/0001'
&& $body['JNL'] === 'VEN'
&& $body['Thirdid'] === 'CUST002';
});
});
it('sends correct parameters for art_add', function () {
Http::fake([
'*' => Http::response(['data' => ['artid' => 'ART001'], 'metadata' => ['rowcount' => 1, 'issuccess' => true], 'error' => null]),
]);
$service = app(LogisticsService::class);
$params = ['ARTID' => 'ART001', 'NAME1' => 'Test Article', 'SALEPRICE' => '49.99'];
$service->artAdd($params);
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('sends correct parameters for art_mod', function () {
Http::fake([
'*' => Http::response(['data' => ['artid' => 'ART001'], 'metadata' => ['rowcount' => 1, 'issuccess' => true], 'error' => null]),
]);
$service = app(LogisticsService::class);
$params = ['ARTID' => 'ART001', 'NAME1' => 'Updated Article'];
$service->artMod($params);
Http::assertSent(function ($request) {
$body = $request->data();
return str_contains($request->url(), 'art_mod')
&& $body['ARTID'] === 'ART001'
&& $body['NAME1'] === 'Updated Article';
});
});
it('sends correct parameters for third_add', function () {
Http::fake([
'*' => Http::response(['data' => ['thirdid' => '_@00036051'], 'metadata' => ['rowcount' => 1, 'issuccess' => true], 'error' => null]),
]);
$service = app(LogisticsService::class);
$params = ['NAME' => 'Test Company', 'VAT' => 'BE0123456789', 'EMAIL' => 'test@example.com'];
$service->thirdAdd($params);
Http::assertSent(function ($request) {
$body = $request->data();
return str_contains($request->url(), 'third_add')
&& $body['NAME'] === 'Test Company'
&& $body['VAT'] === 'BE0123456789';
});
});
it('sends correct parameters for third_mod', function () {
Http::fake([
'*' => Http::response(['data' => ['thirdid' => 'CUST001'], 'metadata' => ['rowcount' => 1, 'issuccess' => true], 'error' => null]),
]);
$service = app(LogisticsService::class);
$params = ['CUSTID' => 'CUST001', 'NAME' => 'Updated Company'];
$service->thirdMod($params);
Http::assertSent(function ($request) {
$body = $request->data();
return str_contains($request->url(), 'third_mod')
&& $body['CUSTID'] === 'CUST001'
&& $body['NAME'] === 'Updated Company';
});
});
it('includes endpoint info in LogisticsApiException', function () {
Http::fake(fn () => throw new ConnectionException('Connection timed out'));

View File

@@ -261,3 +261,133 @@ it('filters out empty select parameter', function () {
&& ! array_key_exists('select', $data);
});
});
// --- third_add ---
it('adds a third party via third_add', function () {
Http::fake([
'*/third_add' => Http::response([
'data' => ['thirdid' => '_@00036051'],
'metadata' => ['rowcount' => 1, 'issuccess' => true],
'error' => null,
]),
]);
Livewire::test(Tiers::class)
->set('mode', 'write')
->set('addName', 'Test Company')
->set('addVat', 'BE0123456789')
->set('addEmail', 'test@example.com')
->call('addTiers')
->assertSet('hasAdded', true)
->assertSet('addResult', ['thirdid' => '_@00036051'])
->assertSet('errorMessage', null);
Http::assertSent(function ($request) {
$body = $request->data();
return str_contains($request->url(), 'third_add')
&& $body['NAME'] === 'Test Company'
&& $body['VAT'] === 'BE0123456789'
&& $body['EMAIL'] === 'test@example.com';
});
});
it('omits optional params when empty on third_add', function () {
Http::fake([
'*/third_add' => Http::response([
'data' => ['thirdid' => '_@00036052'],
'metadata' => ['rowcount' => 1, 'issuccess' => true],
'error' => null,
]),
]);
Livewire::test(Tiers::class)
->set('mode', 'write')
->set('addName', '')
->set('addVat', '')
->set('addEmail', '')
->call('addTiers');
Http::assertSent(function ($request) {
$body = $request->data();
return str_contains($request->url(), 'third_add')
&& ! array_key_exists('NAME', $body)
&& ! array_key_exists('VAT', $body)
&& ! array_key_exists('EMAIL', $body);
});
});
it('handles exception on addTiers', function () {
Http::fake([
'*/third_add' => Http::response('Server Error', 500),
]);
$component = Livewire::test(Tiers::class)
->set('mode', 'write')
->set('addName', 'Test')
->call('addTiers');
expect($component->get('errorMessage'))->not->toBeNull();
expect($component->get('addResult'))->toBe([]);
});
// --- third_mod ---
it('modifies a third party via third_mod', function () {
Http::fake([
'*/third_mod' => Http::response([
'data' => ['thirdid' => 'CUST001'],
'metadata' => ['rowcount' => 1, 'issuccess' => true],
'error' => null,
]),
]);
Livewire::test(Tiers::class)
->set('mode', 'write')
->set('modCustId', 'CUST001')
->set('modName', 'Updated Company')
->set('modVat', 'BE0987654321')
->call('modTiers')
->assertSet('hasModified', true)
->assertSet('modResult', ['thirdid' => 'CUST001'])
->assertSet('errorMessage', null);
Http::assertSent(function ($request) {
$body = $request->data();
return str_contains($request->url(), 'third_mod')
&& $body['CUSTID'] === 'CUST001'
&& $body['NAME'] === 'Updated Company';
});
});
it('shows validation error when modCustId is empty', function () {
Http::fake();
Livewire::test(Tiers::class)
->set('mode', 'write')
->call('modTiers')
->assertSet('hasModified', false)
->assertSet('errorMessage', 'Le champ identifiant tiers (CUSTID) est obligatoire.');
Http::assertNothingSent();
});
it('handles API error on third_mod (not found)', function () {
Http::fake([
'*/third_mod' => Http::response([
'data' => ['xml' => '<VFPData><headererror><errorcode>001</errorcode><description>Custid not exist</description></headererror></VFPData>'],
'metadata' => ['rowcount' => 1, 'issuccess' => false],
'error' => ['Code: 001, Description: Custid not exist'],
]),
]);
$component = Livewire::test(Tiers::class)
->set('mode', 'write')
->set('modCustId', 'INEXISTANT')
->call('modTiers');
expect($component->get('errorMessage'))->toContain('Custid not exist');
});