From 7383c3e01f2681c54f365ff2e1e4c6b845d72da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 14 Aug 2026 15:57:58 +0200 Subject: [PATCH] test(IncoSheets): update tests for short form inco sheets response Enhance tests to verify the structure of inco sheets when the short parameter is true or numeric 1. --- .../Api/V1/IncoSheets/IncoSheetsIndexTest.php | 43 ++++++++++++++++++- .../V1/IncoSheets/IncoSheetsSearchTest.php | 41 +++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Api/V1/IncoSheets/IncoSheetsIndexTest.php b/tests/Feature/Api/V1/IncoSheets/IncoSheetsIndexTest.php index aee93b7..a926559 100644 --- a/tests/Feature/Api/V1/IncoSheets/IncoSheetsIndexTest.php +++ b/tests/Feature/Api/V1/IncoSheets/IncoSheetsIndexTest.php @@ -75,7 +75,7 @@ describe('IncoSheets Index Feature API', function (): void { ['updatedAt', 'Ascending'], ]); - it('returns 200 OK for short projection query', function (): void { + it('returns 200 OK with short form inco sheets when short parameter is true', function (): void { // GIVEN /** @var \Tests\TestCase $test */ $test = $this; @@ -91,8 +91,49 @@ describe('IncoSheets Index Feature API', function (): void { '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; + + // WHEN + $response = $test->getJson('/api/v1/inco-sheets?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'); }); }); diff --git a/tests/Feature/Api/V1/IncoSheets/IncoSheetsSearchTest.php b/tests/Feature/Api/V1/IncoSheets/IncoSheetsSearchTest.php index ed72420..cb0f00f 100644 --- a/tests/Feature/Api/V1/IncoSheets/IncoSheetsSearchTest.php +++ b/tests/Feature/Api/V1/IncoSheets/IncoSheetsSearchTest.php @@ -66,7 +66,7 @@ describe('IncoSheets Search Feature API', function (): void { $response->assertJsonPath('incoSheets.0.id', '1000101'); }); - it('returns 200 OK with short projection when short is true', function (): void { + it('returns 200 OK with short form inco sheets when short parameter is true', function (): void { // GIVEN /** @var \Tests\TestCase $test */ $test = $this; @@ -89,6 +89,45 @@ describe('IncoSheets Search Feature API', function (): void { ], '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 {