create([ 'id' => '1000101', 'name' => 'Poulet RĂ´ti 1kg', 'brand' => ['code' => 'M01', 'label' => 'Standard'], ]); IncoSheet::factory()->create([ 'id' => '1000102', 'name' => 'Poulet Fermier', 'brand' => ['code' => 'M02', 'label' => 'Bio'], ]); }); 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 brand', function (): void { // GIVEN /** @var \Tests\TestCase $test */ $test = $this; $query = urlencode('%10001%'); // WHEN $response = $test->getJson("/api/v1/inco-sheets/search?incoIdLike={$query}&brands[]=M01"); // THEN $response->assertStatus(200); $response->assertJsonCount(1, 'incoSheets'); $response->assertJsonPath('incoSheets.0.id', '1000101'); }); it('returns 200 OK with short form inco sheets when short parameter is true', function (): void { // GIVEN /** @var \Tests\TestCase $test */ $test = $this; $query = urlencode('%1000101%'); // WHEN $response = $test->getJson("/api/v1/inco-sheets/search?incoIdLike={$query}&short=true"); // THEN $response->assertStatus(200); $response->assertJsonStructure([ 'incoSheets' => [ '*' => [ 'id', 'name', 'label', 'createdAt', 'updatedAt', ], ], 'pagination', ]); $firstItem = $response->json('incoSheets.0'); expect($firstItem) ->toHaveKeys(['id', 'name', 'label', 'createdAt', 'updatedAt']) ->and($firstItem)->not->toHaveKey('description') ->and($firstItem)->not->toHaveKey('allegations') ->and($firstItem)->not->toHaveKey('ingredients') ->and($firstItem)->not->toHaveKey('brand'); }); it('returns 200 OK with short form inco sheets when short parameter is numeric 1', function (): void { // GIVEN /** @var \Tests\TestCase $test */ $test = $this; $query = urlencode('%10001%'); // WHEN $response = $test->getJson("/api/v1/inco-sheets/search?incoIdLike={$query}&short=1"); // THEN $response->assertStatus(200); $response->assertJsonStructure([ 'incoSheets' => [ '*' => [ 'id', 'name', 'label', 'createdAt', 'updatedAt', ], ], 'pagination', ]); $firstItem = $response->json('incoSheets.0'); expect($firstItem) ->toHaveKeys(['id', 'name', 'label', 'createdAt', 'updatedAt']) ->and($firstItem)->not->toHaveKey('description') ->and($firstItem)->not->toHaveKey('ingredients'); }); 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); }); });