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:
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user