168 lines
5.3 KiB
PHP
168 lines
5.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Api\V1\IncoSheets;
|
|
|
|
use Database\ArcadiaReplicate\Factories\Refp\ArticleRefFactory;
|
|
use Database\ArcadiaReplicate\Factories\Refp\IncoFactory;
|
|
use Database\ArcadiaReplicate\Factories\Refp\MarqueFactory;
|
|
use Domain\Models\ValueObjects\Brand\ArcadiaId;
|
|
use Domain\Services\BrandResolver;
|
|
|
|
describe('IncoSheets Search Feature API', function (): void {
|
|
beforeEach(function (): void {
|
|
ArticleRefFactory::deleteAll();
|
|
IncoFactory::deleteAll();
|
|
MarqueFactory::deleteAll();
|
|
|
|
ArticleRefFactory::new()->create([
|
|
'NO_ART' => 1000101,
|
|
'COD_SOC' => 1,
|
|
'COD_MARQUE' => 1,
|
|
]);
|
|
|
|
ArticleRefFactory::new()->create([
|
|
'NO_ART' => 1000102,
|
|
'COD_SOC' => 1,
|
|
'COD_MARQUE' => 2,
|
|
]);
|
|
|
|
IncoFactory::new()->create([
|
|
'NO_ART' => 1000101,
|
|
'DENOM_LEG' => 'Poulet Rôti 1kg',
|
|
]);
|
|
|
|
IncoFactory::new()->create([
|
|
'NO_ART' => 1000102,
|
|
'DENOM_LEG' => 'Poulet Fermier',
|
|
]);
|
|
});
|
|
|
|
it('returns 200 OK for valid inco-sheets search request with incoIdLike pattern', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $test */
|
|
$test = $this;
|
|
$query = urlencode('%1000101%');
|
|
|
|
// WHEN
|
|
$response = $test->getJson("/api/v1/inco-sheets/search?incoIdLike={$query}");
|
|
|
|
// THEN
|
|
$response->assertStatus(200);
|
|
$response->assertJsonStructure([
|
|
'incoSheets',
|
|
'pagination' => [
|
|
'page',
|
|
'pageSize',
|
|
'totalItems',
|
|
'totalPages',
|
|
'links' => [
|
|
'self',
|
|
'first',
|
|
'prev',
|
|
'next',
|
|
'last',
|
|
],
|
|
],
|
|
]);
|
|
$response->assertJsonCount(1, 'incoSheets');
|
|
});
|
|
|
|
it('returns 200 OK with matching sheets filtered by BrandCode', 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 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 */
|
|
$test = $this;
|
|
$query = urlencode('%10001%');
|
|
|
|
// WHEN
|
|
$response = $test->getJson("/api/v1/inco-sheets/search?incoIdLike={$query}&brands[]=invalid");
|
|
|
|
// THEN
|
|
$response->assertStatus(422);
|
|
});
|
|
|
|
it('returns 200 OK with short form inco sheets structure on search', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $test */
|
|
$test = $this;
|
|
$query = urlencode('%1000101%');
|
|
|
|
// WHEN
|
|
$response = $test->getJson("/api/v1/inco-sheets/search?incoIdLike={$query}");
|
|
|
|
// THEN
|
|
$response->assertStatus(200);
|
|
$response->assertJsonStructure([
|
|
'incoSheets' => [
|
|
'*' => [
|
|
'incoId',
|
|
'name',
|
|
'label',
|
|
'description',
|
|
'createdAt',
|
|
'updatedAt',
|
|
],
|
|
],
|
|
'pagination',
|
|
]);
|
|
|
|
$firstItem = $response->json('incoSheets.0');
|
|
expect($firstItem)
|
|
->toHaveKeys(['incoId', 'name', 'label', 'description', 'createdAt', 'updatedAt'])
|
|
->and($firstItem)->not->toHaveKey('allegations')
|
|
->and($firstItem)->not->toHaveKey('ingredients')
|
|
->and($firstItem)->not->toHaveKey('brand');
|
|
});
|
|
|
|
it('returns 200 OK with empty incoSheets list when no matching inco sheets found', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $test */
|
|
$test = $this;
|
|
$query = urlencode('%9999999%');
|
|
|
|
// WHEN
|
|
$response = $test->getJson("/api/v1/inco-sheets/search?incoIdLike={$query}");
|
|
|
|
// THEN
|
|
$response->assertStatus(200);
|
|
$response->assertJsonCount(0, 'incoSheets');
|
|
$response->assertJsonPath('pagination.totalItems', 0);
|
|
});
|
|
});
|