- 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.
129 lines
3.7 KiB
PHP
129 lines
3.7 KiB
PHP
<?php
|
|
|
|
use App\Filament\Pages\Tiers;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Livewire\Livewire;
|
|
|
|
beforeEach(function () {
|
|
config([
|
|
'logistics.base_url' => 'http://test-server.local',
|
|
'logistics.api_key' => 'test-api-key',
|
|
'logistics.folder' => 'testfolder',
|
|
'logistics.timeout' => 30,
|
|
'logistics.connect_timeout' => 10,
|
|
'logistics.retry.times' => 1,
|
|
'logistics.retry.sleep_ms' => 0,
|
|
]);
|
|
|
|
$this->actingAs(User::factory()->create());
|
|
});
|
|
|
|
it('defaults to read mode', function () {
|
|
Livewire::test(Tiers::class)
|
|
->assertSet('mode', 'read');
|
|
});
|
|
|
|
it('can switch between read and write modes', function () {
|
|
Livewire::test(Tiers::class)
|
|
->set('mode', 'write')
|
|
->assertSet('mode', 'write')
|
|
->set('mode', 'read')
|
|
->assertSet('mode', 'read');
|
|
});
|
|
|
|
it('shows validation error when search is empty', function () {
|
|
Http::fake();
|
|
|
|
Livewire::test(Tiers::class)
|
|
->call('searchTiers')
|
|
->assertSet('hasSearched', false)
|
|
->assertSet('errorMessage', 'Le champ de recherche (search) est obligatoire.');
|
|
|
|
Http::assertNothingSent();
|
|
});
|
|
|
|
it('searches tiers via third_list', function () {
|
|
Http::fake([
|
|
'*/third_list' => Http::response([
|
|
'data' => [['custid' => 'CUST001', 'custname' => 'Client Test']],
|
|
'metadata' => ['rowcount' => 1, 'issuccess' => true],
|
|
'error' => null,
|
|
]),
|
|
]);
|
|
|
|
Livewire::test(Tiers::class)
|
|
->set('search', 'test')
|
|
->set('select', 'custid,custname')
|
|
->call('searchTiers')
|
|
->assertSet('hasSearched', true)
|
|
->assertSet('data', [['custid' => 'CUST001', 'custname' => 'Client Test']])
|
|
->assertSet('errorMessage', null);
|
|
|
|
Http::assertSent(function ($request) {
|
|
return str_contains($request->url(), 'third_list')
|
|
&& $request->data()['search'] === 'test';
|
|
});
|
|
});
|
|
|
|
it('sets hasSearched even when no results', function () {
|
|
Http::fake([
|
|
'*/third_list' => Http::response([
|
|
'data' => [],
|
|
'metadata' => ['rowcount' => 0, 'issuccess' => true],
|
|
'error' => null,
|
|
]),
|
|
]);
|
|
|
|
Livewire::test(Tiers::class)
|
|
->set('search', 'nonexistent')
|
|
->call('searchTiers')
|
|
->assertSet('hasSearched', true)
|
|
->assertSet('data', []);
|
|
});
|
|
|
|
it('shows validation error when historyThirdId is empty', function () {
|
|
Http::fake();
|
|
|
|
Livewire::test(Tiers::class)
|
|
->call('getArtHistory')
|
|
->assertSet('hasHistory', false)
|
|
->assertSet('errorMessage', 'Le champ identifiant tiers (thirdid) est obligatoire.');
|
|
|
|
Http::assertNothingSent();
|
|
});
|
|
|
|
it('gets art history for a third party', function () {
|
|
Http::fake([
|
|
'*/third_GetArtHistory' => Http::response([
|
|
'data' => [['artid' => 'ART001', 'qty' => 5]],
|
|
'metadata' => ['rowcount' => 1, 'issuccess' => true],
|
|
'error' => null,
|
|
]),
|
|
]);
|
|
|
|
Livewire::test(Tiers::class)
|
|
->set('historyThirdId', 'CUST001')
|
|
->call('getArtHistory')
|
|
->assertSet('hasHistory', true)
|
|
->assertSet('historyData', [['artid' => 'ART001', 'qty' => 5]])
|
|
->assertSet('errorMessage', null);
|
|
});
|
|
|
|
it('displays error message on API failure', function () {
|
|
Http::fake([
|
|
'*/third_list' => Http::response([
|
|
'data' => null,
|
|
'metadata' => ['rowcount' => 0, 'issuccess' => false],
|
|
'error' => 'Invalid API key',
|
|
]),
|
|
]);
|
|
|
|
Livewire::test(Tiers::class)
|
|
->set('search', 'test')
|
|
->call('searchTiers')
|
|
->assertSet('hasSearched', true);
|
|
|
|
expect(true)->toBeTrue();
|
|
});
|