fix(inco): normalize scalar brands query parameter to array in prepareForValidation
This commit is contained in:
parent
d55178407f
commit
6497b109a2
4 changed files with 77 additions and 0 deletions
|
|
@ -38,6 +38,22 @@ final class IncoSheetsIndexRequest extends FormRequest
|
|||
];
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->has('brands')) {
|
||||
$brands = $this->input('brands');
|
||||
if (is_string($brands)) {
|
||||
$trimmed = trim($brands);
|
||||
$this->merge([
|
||||
'brands' => $trimmed === ''
|
||||
? []
|
||||
: (str_contains($trimmed, ',') ? array_map('trim', explode(',', $trimmed)) : [$trimmed]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function sorter(): IncoSheetSorter
|
||||
{
|
||||
return new IncoSheetSorter($this->sortBy(), $this->direction());
|
||||
|
|
|
|||
|
|
@ -24,6 +24,22 @@ final class IncoSheetsSearchRequest extends FormRequest
|
|||
];
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->has('brands')) {
|
||||
$brands = $this->input('brands');
|
||||
if (is_string($brands)) {
|
||||
$trimmed = trim($brands);
|
||||
$this->merge([
|
||||
'brands' => $trimmed === ''
|
||||
? []
|
||||
: (str_contains($trimmed, ',') ? array_map('trim', explode(',', $trimmed)) : [$trimmed]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function incoIdSearch(): IncoIdQuery
|
||||
{
|
||||
return new IncoIdQuery($this->string('incoIdLike')->value());
|
||||
|
|
|
|||
|
|
@ -109,6 +109,33 @@ describe('IncoSheets Index Feature API', function (): void {
|
|||
$response->assertJsonPath('incoSheets.0.incoId', '9999001');
|
||||
});
|
||||
|
||||
it('returns 200 OK with matching sheets filtered by BrandCode passed as scalar query parameter without brackets', function (): void {
|
||||
// GIVEN
|
||||
/** @var \Tests\TestCase $test */
|
||||
$test = $this;
|
||||
|
||||
MarqueFactory::new()->create(['COD_MARQ' => 504, 'LIB_MARQ' => 'LE GAULOIS PROFESSIONNEL']);
|
||||
$brand = app(BrandResolver::class)->resolve(new ArcadiaId('504'));
|
||||
|
||||
ArticleRefFactory::new()->create([
|
||||
'NO_ART' => 9999001,
|
||||
'COD_SOC' => 1,
|
||||
'COD_MARQUE' => 504,
|
||||
]);
|
||||
|
||||
IncoFactory::new()->create([
|
||||
'NO_ART' => 9999001,
|
||||
'DENOM_LEG' => 'Produit Gaulois Pro',
|
||||
]);
|
||||
|
||||
// WHEN
|
||||
$response = $test->getJson("/api/v1/inco-sheets?brands={$brand->code->value}");
|
||||
|
||||
// THEN
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('incoSheets.0.incoId', '9999001');
|
||||
});
|
||||
|
||||
it('returns 422 Unprocessable Entity when brand code format is invalid', function (): void {
|
||||
// GIVEN
|
||||
/** @var \Tests\TestCase $test */
|
||||
|
|
|
|||
|
|
@ -87,6 +87,24 @@ describe('IncoSheets Search Feature API', function (): void {
|
|||
$response->assertJsonPath('incoSheets.0.incoId', '1000101');
|
||||
});
|
||||
|
||||
it('returns 200 OK with matching sheets filtered by BrandCode without brackets', function (): void {
|
||||
// GIVEN
|
||||
/** @var \Tests\TestCase $test */
|
||||
$test = $this;
|
||||
$query = urlencode('%10001%');
|
||||
|
||||
MarqueFactory::new()->create(['COD_MARQ' => 1, 'LIB_MARQ' => 'Standard']);
|
||||
$brand = app(BrandResolver::class)->resolve(new ArcadiaId('1'));
|
||||
|
||||
// WHEN
|
||||
$response = $test->getJson("/api/v1/inco-sheets/search?incoIdLike={$query}&brands={$brand->code->value}");
|
||||
|
||||
// THEN
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(1, 'incoSheets');
|
||||
$response->assertJsonPath('incoSheets.0.incoId', '1000101');
|
||||
});
|
||||
|
||||
it('returns 422 Unprocessable Entity when brand code format is invalid', function (): void {
|
||||
// GIVEN
|
||||
/** @var \Tests\TestCase $test */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue