- Added a toggle for switching between read and write modes on the Articles, Documents, Journaux, Tiers, and Divers pages, allowing users to access both data retrieval and data submission endpoints. - Updated the Documents page to cover all 9 documented endpoints, including 7 for reading and 2 for writing, with appropriate error handling. - Created a new Divers page to handle three endpoints: getserialnumber, codes_list, and custom_geninv_updatestock (the latter being non-functional). - Introduced new methods in LogisticsService for handling PDF generation and stock updates, with corresponding updates in the API documentation. - Improved form field components for better visual spacing in input fields.
130 lines
3.5 KiB
PHP
130 lines
3.5 KiB
PHP
<?php
|
|
|
|
use App\Filament\Pages\Divers;
|
|
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(Divers::class)
|
|
->assertSet('mode', 'read');
|
|
});
|
|
|
|
it('can switch between read and write modes', function () {
|
|
Livewire::test(Divers::class)
|
|
->set('mode', 'write')
|
|
->assertSet('mode', 'write')
|
|
->set('mode', 'read')
|
|
->assertSet('mode', 'read');
|
|
});
|
|
|
|
it('gets the serial number', function () {
|
|
Http::fake([
|
|
'*/getserialnumber' => Http::response([
|
|
'data' => 'SN-12345',
|
|
'metadata' => ['rowcount' => 1, 'issuccess' => true],
|
|
'error' => null,
|
|
]),
|
|
]);
|
|
|
|
Livewire::test(Divers::class)
|
|
->call('getSerialNumber')
|
|
->assertSet('serialData', ['value' => 'SN-12345']);
|
|
});
|
|
|
|
it('searches codes by prefix', function () {
|
|
Http::fake([
|
|
'*/codes_list' => Http::response([
|
|
'data' => [['code' => 'PAY01', 'vala1' => 'Comptant']],
|
|
'metadata' => ['rowcount' => 1, 'issuccess' => true],
|
|
'error' => null,
|
|
]),
|
|
]);
|
|
|
|
Livewire::test(Divers::class)
|
|
->set('code', 'PAY')
|
|
->call('searchCodes')
|
|
->assertSet('codesData', [['code' => 'PAY01', 'vala1' => 'Comptant']]);
|
|
|
|
Http::assertSent(function ($request) {
|
|
return str_contains($request->url(), 'codes_list')
|
|
&& $request->data()['code'] === 'PAY';
|
|
});
|
|
});
|
|
|
|
it('does not call searchCodes when code is empty', function () {
|
|
Http::fake();
|
|
|
|
Livewire::test(Divers::class)
|
|
->call('searchCodes')
|
|
->assertSet('codesData', []);
|
|
|
|
Http::assertNothingSent();
|
|
});
|
|
|
|
it('calls custom_geninv_updatestock endpoint', function () {
|
|
Http::fake([
|
|
'*/custom_geninv_updatestock' => Http::response([
|
|
'data' => null,
|
|
'metadata' => ['rowcount' => 0, 'issuccess' => false],
|
|
'error' => 'Unknown STKID',
|
|
]),
|
|
]);
|
|
|
|
Livewire::test(Divers::class)
|
|
->set('mode', 'write')
|
|
->set('stkArtId', 'ART001')
|
|
->set('stkId', 'STK1')
|
|
->set('stkQty', '10')
|
|
->call('updateStock')
|
|
->assertSet('errorMessage', 'Unknown STKID');
|
|
|
|
Http::assertSent(function ($request) {
|
|
$body = $request->data();
|
|
|
|
return str_contains($request->url(), 'custom_geninv_updatestock')
|
|
&& $body['ARTID'] === 'ART001'
|
|
&& $body['STKID'] === 'STK1';
|
|
});
|
|
});
|
|
|
|
it('does not call updateStock when required fields are empty', function () {
|
|
Http::fake();
|
|
|
|
Livewire::test(Divers::class)
|
|
->set('mode', 'write')
|
|
->call('updateStock')
|
|
->assertSet('updateStockResult', []);
|
|
|
|
Http::assertNothingSent();
|
|
});
|
|
|
|
it('displays error message on API failure', function () {
|
|
Http::fake([
|
|
'*/codes_list' => Http::response([
|
|
'data' => null,
|
|
'metadata' => ['rowcount' => 0, 'issuccess' => false],
|
|
'error' => 'Invalid API key',
|
|
]),
|
|
]);
|
|
|
|
Livewire::test(Divers::class)
|
|
->set('code', 'TEST')
|
|
->call('searchCodes')
|
|
->assertSet('errorMessage', 'Invalid API key');
|
|
});
|