Files
logisticsAPI/tests/Feature/JournauxPageTest.php
Marvin 0ab94fdb91 Update Journaux page to increase default results limit and ensure results are sent as strings
- Changed the default results limit from 10 to 30 in the Journaux page.
- Updated the `searchJournaux` method to cast the results parameter to a string to prevent HTTP 400 errors.
- Modified related tests to reflect the new results format and updated expected data structure in API responses.
- Enhanced documentation for the `jnl_list` endpoint to clarify the requirement for the results parameter to be a string.
2026-02-23 10:34:42 +01:00

121 lines
3.4 KiB
PHP

<?php
use App\Filament\Pages\Journaux;
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(Journaux::class)
->assertSet('mode', 'read');
});
it('can switch between read and write modes', function () {
Livewire::test(Journaux::class)
->set('mode', 'write')
->assertSet('mode', 'write')
->set('mode', 'read')
->assertSet('mode', 'read');
});
it('shows validation error when TYPE is empty', function () {
Http::fake();
Livewire::test(Journaux::class)
->call('searchJournaux')
->assertSet('hasSearched', false)
->assertSet('errorMessage', 'Le champ type de journal (TYPE) est obligatoire.');
Http::assertNothingSent();
});
it('searches journaux via jnl_list', function () {
Http::fake([
'*/jnl_list' => Http::response([
'data' => [['jnl' => '03VEN', 'name' => 'FACTURE CLIENT', 'type' => 'CI']],
'metadata' => ['rowCount' => 1, 'source' => 'DBF', 'unlimited' => false],
'error' => null,
]),
]);
Livewire::test(Journaux::class)
->set('type', 'I')
->set('select', 'jnl,name,type')
->call('searchJournaux')
->assertSet('hasSearched', true)
->assertSet('data', [['jnl' => '03VEN', 'name' => 'FACTURE CLIENT', 'type' => 'CI']])
->assertSet('errorMessage', null);
Http::assertSent(function ($request) {
return str_contains($request->url(), 'jnl_list')
&& $request->data()['TYPE'] === 'I';
});
});
it('sends results as string to avoid HTTP 400', function () {
Http::fake([
'*/jnl_list' => Http::response([
'data' => [],
'metadata' => ['rowCount' => 0, 'source' => 'DBF', 'unlimited' => false],
'error' => null,
]),
]);
Livewire::test(Journaux::class)
->set('type', 'C')
->set('results', 50)
->call('searchJournaux');
Http::assertSent(function ($request) {
return str_contains($request->url(), 'jnl_list')
&& $request->data()['results'] === '50';
});
});
it('sets hasSearched even when no results', function () {
Http::fake([
'*/jnl_list' => Http::response([
'data' => [],
'metadata' => ['rowcount' => 0, 'issuccess' => true],
'error' => null,
]),
]);
Livewire::test(Journaux::class)
->set('type', 'Z')
->call('searchJournaux')
->assertSet('hasSearched', true)
->assertSet('data', []);
});
it('displays error message on API failure', function () {
Http::fake([
'*/jnl_list' => Http::response([
'data' => null,
'metadata' => ['rowcount' => 0, 'issuccess' => false],
'error' => 'Invalid API key',
]),
]);
Livewire::test(Journaux::class)
->set('type', 'V')
->call('searchJournaux')
->assertSet('hasSearched', true);
expect(true)->toBeTrue();
});