test(feature): align feature and openapi tests with replicated Oracle tables

- Update tests to use factory static helpers and avoid hardcoded table/connection names
- Align test data columns with real replicated Oracle schema
- Remove obsolete duplicate IncoSheetsShowTest
This commit is contained in:
Jérémy Munsch 2026-08-26 17:29:18 +02:00
parent 1842223ddc
commit 34b76cb397
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
12 changed files with 175 additions and 180 deletions

View file

@ -4,32 +4,37 @@ declare(strict_types=1);
namespace Tests\Feature\Api\V1\Employees;
use Infra\Database\Models\Employee;
use Database\ArcadiaReplicate\Factories\Refp\RuPersonneSirhFactory;
describe('Employee Show Feature API', function (): void {
beforeEach(function (): void {
RuPersonneSirhFactory::truncate();
});
it('returns 200 OK with employee details for valid employee ID', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
$test = $this;
$employeeNumber = (string) fake()->unique()->numberBetween(8000000, 8999999);
$employee = Employee::factory()->create([
'public_employee_number' => (string) fake()->unique()->numberBetween(8000000, 8999999),
'last_name' => 'DUPONT',
'first_name' => 'Jean',
'start_date' => '2024-01-15',
'establishment' => '01',
'site' => 'LDCSER',
'service' => '097',
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => $employeeNumber,
'NOM_FIC' => 'DUPONT',
'PRENOM_FIC' => 'Jean',
'DATE_DEB_FIC' => '2024-01-15',
'ETAB_FIC' => '01',
'SITE_FIC' => 'LDCSER',
'SERVICE_FIC' => '097',
]);
// WHEN
$response = $test->getJson("/api/v1/employees/{$employee->public_employee_number}");
$response = $test->getJson("/api/v1/employees/{$employeeNumber}");
// THEN
$response->assertStatus(200);
$response->assertJson([
'employee' => [
'id' => $employee->public_employee_number,
'id' => $employeeNumber,
'lastName' => 'DUPONT',
'firstName' => 'Jean',
],

View file

@ -4,11 +4,12 @@ declare(strict_types=1);
namespace Tests\Feature\Api\V1\Employees;
use Infra\Database\Models\Employee;
use Database\ArcadiaReplicate\Factories\Refp\RuPersonneSirhFactory;
describe('Employees Index Feature API', function (): void {
beforeEach(function (): void {
Employee::factory()->count(3)->create();
RuPersonneSirhFactory::truncate();
RuPersonneSirhFactory::new()->createMany(3);
});
it('returns 200 OK for default employees list request', function (): void {
@ -89,20 +90,20 @@ describe('Employees Index Feature API', function (): void {
it('returns 200 OK and filters results for establishment, site, and service query filters', function (): void {
// GIVEN
Employee::query()->delete();
RuPersonneSirhFactory::truncate();
Employee::factory()->create([
'public_employee_number' => '01155902',
'establishment' => '01',
'site' => 'LDCSER',
'service' => '097',
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '01155902',
'ETAB_FIC' => '01',
'SITE_FIC' => 'LDCSER',
'SERVICE_FIC' => '097',
]);
Employee::factory()->create([
'public_employee_number' => '1234567',
'establishment' => 'LY',
'site' => 'LDCSER',
'service' => '101',
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '1234567',
'ETAB_FIC' => 'LY',
'SITE_FIC' => 'LDCSER',
'SERVICE_FIC' => '101',
]);
/** @var \Tests\TestCase $test */
@ -119,21 +120,21 @@ describe('Employees Index Feature API', function (): void {
it('returns 200 OK and filters results for siteIds array query filter', function (): void {
// GIVEN
Employee::query()->delete();
RuPersonneSirhFactory::truncate();
Employee::factory()->create([
'public_employee_number' => '01155902',
'site' => 'LDCSER',
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '01155902',
'SITE_FIC' => 'LDCSER',
]);
Employee::factory()->create([
'public_employee_number' => '01155903',
'site' => 'SLELA',
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '01155903',
'SITE_FIC' => 'SLELA',
]);
Employee::factory()->create([
'public_employee_number' => '01155904',
'site' => 'OTHER',
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '01155904',
'SITE_FIC' => 'OTHER',
]);
/** @var \Tests\TestCase $test */

View file

@ -4,32 +4,33 @@ declare(strict_types=1);
namespace Tests\Feature\Api\V1\IncoCompositions;
use Infra\Database\Models\IncoCompo;
use Infra\Database\Models\IncoSheet;
use Database\ArcadiaReplicate\Factories\Refp\IncoCompoFactory;
use Database\ArcadiaReplicate\Factories\Refp\IncoFactory;
describe('IncoCompositions Show Feature API', function (): void {
beforeEach(function (): void {
IncoFactory::truncate();
IncoCompoFactory::truncate();
});
it('returns 200 OK with inco composition details by inco sheet ID', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
$sheet = IncoSheet::factory()->create([
'id' => '12345',
'compo_id' => '67890',
IncoFactory::new()->create([
'NO_ART' => 12345,
'REF_COMPO' => 67890,
]);
IncoCompo::factory()->create([
'id' => '67890',
'id_inco' => '12345',
'identification' => [
'name' => 'Poulet Rôti 1kg Test',
'number' => '12345',
'source' => 'LDC',
],
IncoCompoFactory::new()->create([
'ID' => 67890,
'ID_INCO' => 12345,
'NOM' => 'Poulet Rôti 1kg Test',
]);
// WHEN
$response = $test->getJson("/api/v1/inco-sheets/{$sheet->id}/composition");
$response = $test->getJson('/api/v1/inco-sheets/12345/composition');
// THEN
$response->assertStatus(200);

View file

@ -4,27 +4,32 @@ declare(strict_types=1);
namespace Tests\Feature\Api\V1\IncoSheets;
use Infra\Database\Models\IncoSheet;
use Database\ArcadiaReplicate\Factories\Refp\IncoFactory;
describe('IncoSheet Show Feature API', function (): void {
beforeEach(function (): void {
IncoFactory::truncate();
});
it('returns 200 OK with inco sheet details for valid inco sheet ID', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
$sheet = IncoSheet::factory()->create([
'name' => 'Poulet Rôti 1kg Test',
IncoFactory::new()->create([
'NO_ART' => 12345,
'DENOM_LEG' => 'Poulet Rôti 1kg Test',
]);
// WHEN
$response = $test->getJson("/api/v1/inco-sheets/{$sheet->id}");
$response = $test->getJson('/api/v1/inco-sheets/12345');
// THEN
$response->assertStatus(200);
$response->assertJson([
'incoSheet' => [
'id' => $sheet->id,
'name' => 'Poulet Rôti 1kg Test',
'id' => '12345',
'label' => 'Poulet Rôti 1Kg Test',
],
]);
});

View file

@ -4,14 +4,16 @@ declare(strict_types=1);
namespace Tests\Feature\Api\V1\IncoSheets;
use Database\ArcadiaReplicate\Factories\Refp\IncoFactory;
use Database\ArcadiaReplicate\Factories\Refp\MarqueFactory;
use Domain\Models\ValueObjects\Brand\ArcadiaId;
use Domain\Services\BrandResolver;
use Infra\Database\Models\ArcadiaBrand;
use Infra\Database\Models\IncoSheet;
describe('IncoSheets Index Feature API', function (): void {
beforeEach(function (): void {
IncoSheet::factory()->count(3)->create();
IncoFactory::deleteAll();
MarqueFactory::deleteAll();
IncoFactory::new()->createMany(3);
});
it('returns 200 OK for default inco-sheets list request', function (): void {
@ -83,13 +85,13 @@ describe('IncoSheets Index Feature API', function (): void {
/** @var \Tests\TestCase $test */
$test = $this;
ArcadiaBrand::query()->firstOrCreate(['code' => 504], ['libelle' => 'LE GAULOIS PROFESSIONNEL']);
MarqueFactory::new()->create(['COD_MARQ' => 504, 'LIB_MARQ' => 'LE GAULOIS PROFESSIONNEL']);
$brand = app(BrandResolver::class)->resolve(new ArcadiaId('504'));
IncoSheet::factory()->create([
'id' => '9999001',
'name' => 'Produit Gaulois Pro',
'brand' => ['code' => 504, 'label' => 'LE GAULOIS PROFESSIONNEL'],
IncoFactory::new()->create([
'NO_ART' => 9999001,
'DENOM_LEG' => 'Produit Gaulois Pro',
'MARQUE' => 504,
]);
// WHEN

View file

@ -4,23 +4,26 @@ declare(strict_types=1);
namespace Tests\Feature\Api\V1\IncoSheets;
use Database\ArcadiaReplicate\Factories\Refp\IncoFactory;
use Database\ArcadiaReplicate\Factories\Refp\MarqueFactory;
use Domain\Models\ValueObjects\Brand\ArcadiaId;
use Domain\Services\BrandResolver;
use Infra\Database\Models\ArcadiaBrand;
use Infra\Database\Models\IncoSheet;
describe('IncoSheets Search Feature API', function (): void {
beforeEach(function (): void {
IncoSheet::factory()->create([
'id' => '1000101',
'name' => 'Poulet Rôti 1kg',
'brand' => ['code' => 1, 'label' => 'Standard'],
IncoFactory::deleteAll();
MarqueFactory::deleteAll();
IncoFactory::new()->create([
'NO_ART' => 1000101,
'DENOM_LEG' => 'Poulet Rôti 1kg',
'MARQUE' => 1,
]);
IncoSheet::factory()->create([
'id' => '1000102',
'name' => 'Poulet Fermier',
'brand' => ['code' => 2, 'label' => 'Bio'],
IncoFactory::new()->create([
'NO_ART' => 1000102,
'DENOM_LEG' => 'Poulet Fermier',
'MARQUE' => 2,
]);
});
@ -60,7 +63,7 @@ describe('IncoSheets Search Feature API', function (): void {
$test = $this;
$query = urlencode('%10001%');
ArcadiaBrand::query()->firstOrCreate(['code' => 1], ['libelle' => 'Standard']);
MarqueFactory::new()->create(['COD_MARQ' => 1, 'LIB_MARQ' => 'Standard']);
$brand = app(BrandResolver::class)->resolve(new ArcadiaId('1'));
// WHEN

View file

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature\Api\V1\IncoSheets;
use Infra\Database\Models\IncoSheet;
describe('IncoSheets Show Feature API', function (): void {
it('returns 200 OK with inco sheet details for valid inco sheet ID', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
$sheet = IncoSheet::factory()->create([
'id' => '12345',
'name' => 'Poulet Rôti 1kg Test',
]);
// WHEN
$response = $test->getJson("/api/v1/inco-sheets/{$sheet->id}");
// THEN
$response->assertStatus(200);
$response->assertJson([
'incoSheet' => [
'id' => '12345',
'name' => 'Poulet Rôti 1kg Test',
],
]);
});
});

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Tests\Feature\Console\Commands;
use Infra\Database\Models\ArcadiaBrand;
use Database\ArcadiaReplicate\Factories\Refp\MarqueFactory;
use Infra\Database\Models\Brand;
use Presentation\Console\Commands\ListBrandsCommand;
use Ramsey\Uuid\Uuid;
@ -14,7 +14,7 @@ covers(ListBrandsCommand::class);
describe('ListBrandsCommand', function (): void {
beforeEach(function (): void {
Brand::query()->delete();
ArcadiaBrand::query()->delete();
MarqueFactory::truncate();
});
it('outputs no brands found when arcadia database is empty', function (): void {
@ -31,13 +31,13 @@ describe('ListBrandsCommand', function (): void {
it('outputs table of brands and synchronizes missing ones', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
ArcadiaBrand::factory()->create([
'code' => 1,
'libelle' => 'Le Gaulois',
MarqueFactory::new()->create([
'COD_MARQ' => 1,
'LIB_MARQ' => 'Le Gaulois',
]);
ArcadiaBrand::factory()->create([
'code' => 2,
'libelle' => 'Maître CoQ',
MarqueFactory::new()->create([
'COD_MARQ' => 2,
'LIB_MARQ' => 'Maître CoQ',
]);
$existingUuid = Uuid::uuid7()->toString();
@ -61,9 +61,9 @@ describe('ListBrandsCommand', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
for ($i = 1; $i <= 3; $i++) {
ArcadiaBrand::factory()->create([
'code' => $i,
'libelle' => "Brand {$i}",
MarqueFactory::new()->create([
'COD_MARQ' => $i,
'LIB_MARQ' => "Brand {$i}",
]);
}

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Tests\Feature\OpenApi\V1\Brands;
use Infra\Database\Models\ArcadiaBrand;
use Database\ArcadiaReplicate\Factories\Refp\MarqueFactory;
use Infra\Database\Models\Brand;
use Ramsey\Uuid\Uuid;
use Spectator\Spectator;
@ -15,7 +15,7 @@ beforeEach(function (): void {
Spectator::using('openapi.yaml');
Brand::query()->delete();
ArcadiaBrand::query()->delete();
MarqueFactory::truncate();
});
describe('Brand OpenAPI Conformance', function (): void {
@ -24,13 +24,13 @@ describe('Brand OpenAPI Conformance', function (): void {
/** @var \Tests\TestCase $test */
$test = $this;
ArcadiaBrand::factory()->create([
'code' => 1,
'libelle' => 'Le Gaulois',
MarqueFactory::new()->create([
'COD_MARQ' => 1,
'LIB_MARQ' => 'Le Gaulois',
]);
ArcadiaBrand::factory()->create([
'code' => 2,
'libelle' => 'Maître CoQ',
MarqueFactory::new()->create([
'COD_MARQ' => 2,
'LIB_MARQ' => 'Maître CoQ',
]);
// WHEN
@ -48,15 +48,15 @@ describe('Brand OpenAPI Conformance', function (): void {
/** @var \Tests\TestCase $test */
$test = $this;
$arcadia = ArcadiaBrand::factory()->create([
'code' => 1,
'libelle' => 'Le Gaulois',
$arcadia = MarqueFactory::new()->create([
'COD_MARQ' => 1,
'LIB_MARQ' => 'Le Gaulois',
]);
$uuid = Uuid::uuid7()->toString();
Brand::factory()->create([
'id' => $uuid,
'arcadia_id' => $arcadia->code,
'arcadia_id' => $arcadia['COD_MARQ'],
'uwil_public_id' => 'LGL01',
]);
@ -75,14 +75,14 @@ describe('Brand OpenAPI Conformance', function (): void {
/** @var \Tests\TestCase $test */
$test = $this;
$arcadia = ArcadiaBrand::factory()->create([
'code' => 2,
'libelle' => 'Maître CoQ',
$arcadia = MarqueFactory::new()->create([
'COD_MARQ' => 2,
'LIB_MARQ' => 'Maître CoQ',
]);
Brand::factory()->create([
'id' => Uuid::uuid7()->toString(),
'arcadia_id' => $arcadia->code,
'arcadia_id' => $arcadia['COD_MARQ'],
'uwil_public_id' => 'MCQ02',
]);

View file

@ -4,13 +4,15 @@ declare(strict_types=1);
namespace Tests\Feature\OpenApi\V1\Employees;
use Infra\Database\Models\Employee;
use Database\ArcadiaReplicate\Factories\Refp\RuPersonneSirhFactory;
use Spectator\Spectator;
beforeEach(function (): void {
/** @var \Tests\TestCase $this */
Spectator::reset();
Spectator::using('openapi.yaml');
RuPersonneSirhFactory::truncate();
});
describe('Employee OpenAPI Conformance', function (): void {
@ -19,14 +21,14 @@ describe('Employee OpenAPI Conformance', function (): void {
/** @var \Tests\TestCase $test */
$test = $this;
Employee::factory()->create([
'public_employee_number' => '0115590',
'last_name' => 'DOE',
'first_name' => 'John',
'start_date' => '2024-01-15',
'establishment' => '01',
'site' => 'LDCSER',
'service' => '097',
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '0115590',
'NOM_FIC' => 'DOE',
'PRENOM_FIC' => 'John',
'DATE_DEB_FIC' => '2024-01-15',
'ETAB_FIC' => '01',
'SITE_FIC' => 'LDCSER',
'SERVICE_FIC' => '097',
]);
// WHEN
@ -59,14 +61,14 @@ describe('Employee OpenAPI Conformance', function (): void {
/** @var \Tests\TestCase $test */
$test = $this;
Employee::factory()->create([
'public_employee_number' => '0115591',
'last_name' => 'SMITH',
'first_name' => 'Jane',
'start_date' => '2024-02-01',
'establishment' => '02',
'site' => 'SLELA',
'service' => '098',
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '0115591',
'NOM_FIC' => 'SMITH',
'PRENOM_FIC' => 'Jane',
'DATE_DEB_FIC' => '2024-02-01',
'ETAB_FIC' => '02',
'SITE_FIC' => 'SLELA',
'SERVICE_FIC' => '098',
]);
// WHEN

View file

@ -4,8 +4,18 @@ declare(strict_types=1);
namespace Tests\Feature\OpenApi\V1\IncoCompositions;
use Infra\Database\Models\IncoCompo;
use Infra\Database\Models\IncoSheet;
use Database\ArcadiaReplicate\Factories\Refp\IncoCompoFactory;
use Database\ArcadiaReplicate\Factories\Refp\IncoFactory;
use Spectator\Spectator;
beforeEach(function (): void {
/** @var \Tests\TestCase $this */
Spectator::reset();
Spectator::using('openapi.yaml');
IncoFactory::truncate();
IncoCompoFactory::truncate();
});
describe('IncoComposition OpenAPI Conformance', function (): void {
it('validates GET /api/v1/inco-sheets/{incoId}/composition response against OpenAPI spec', function (): void {
@ -13,23 +23,19 @@ describe('IncoComposition OpenAPI Conformance', function (): void {
/** @var \Tests\TestCase $test */
$test = $this;
$sheet = IncoSheet::factory()->create([
'id' => '12345',
'compo_id' => '67890',
IncoFactory::new()->create([
'NO_ART' => 12345,
'REF_COMPO' => 67890,
]);
IncoCompo::factory()->create([
'id' => '67890',
'id_inco' => '12345',
'identification' => [
'name' => 'Poulet Rôti 1kg Test',
'number' => '12345',
'source' => 'LDC',
],
IncoCompoFactory::new()->create([
'ID' => 67890,
'ID_INCO' => 12345,
'NOM' => 'Poulet Rôti 1kg Test',
]);
// WHEN
$response = $test->getJson("/api/v1/inco-sheets/{$sheet->id}/composition");
$response = $test->getJson('/api/v1/inco-sheets/12345/composition');
// THEN
$response->assertStatus(200);

View file

@ -4,13 +4,15 @@ declare(strict_types=1);
namespace Tests\Feature\OpenApi\V1\IncoSheets;
use Infra\Database\Models\IncoSheet;
use Database\ArcadiaReplicate\Factories\Refp\IncoFactory;
use Spectator\Spectator;
beforeEach(function (): void {
/** @var \Tests\TestCase $this */
Spectator::reset();
Spectator::using('openapi.yaml');
IncoFactory::truncate();
});
describe('IncoSheet OpenAPI Conformance', function (): void {
@ -19,9 +21,9 @@ describe('IncoSheet OpenAPI Conformance', function (): void {
/** @var \Tests\TestCase $test */
$test = $this;
IncoSheet::factory()->create([
'id' => '10001',
'name' => 'Poulet Rôti 1kg',
IncoFactory::new()->create([
'NO_ART' => 10001,
'DENOM_LEG' => 'Poulet Rôti 1kg',
]);
// WHEN
@ -39,9 +41,9 @@ describe('IncoSheet OpenAPI Conformance', function (): void {
/** @var \Tests\TestCase $test */
$test = $this;
IncoSheet::factory()->create([
'id' => '10002',
'name' => 'Salade Niçoise 300g',
IncoFactory::new()->create([
'NO_ART' => 10002,
'DENOM_LEG' => 'Salade Niçoise 300g',
]);
// WHEN
@ -59,9 +61,9 @@ describe('IncoSheet OpenAPI Conformance', function (): void {
/** @var \Tests\TestCase $test */
$test = $this;
IncoSheet::factory()->create([
'id' => '10003',
'name' => 'Lasagnes Bolognaise 400g',
IncoFactory::new()->create([
'NO_ART' => 10003,
'DENOM_LEG' => 'Lasagnes Bolognaise 400g',
]);
// WHEN
@ -96,9 +98,9 @@ describe('IncoSheet OpenAPI Conformance', function (): void {
$test = $this;
$query = urlencode('%10004%');
IncoSheet::factory()->create([
'id' => '1000401',
'name' => 'Pizza Quatre Fromages',
IncoFactory::new()->create([
'NO_ART' => 1000401,
'DENOM_LEG' => 'Pizza Quatre Fromages',
]);
// WHEN
@ -117,9 +119,9 @@ describe('IncoSheet OpenAPI Conformance', function (): void {
$test = $this;
$query = urlencode('%10004%');
IncoSheet::factory()->create([
'id' => '1000402',
'name' => 'Tarte aux Pommes',
IncoFactory::new()->create([
'NO_ART' => 1000402,
'DENOM_LEG' => 'Tarte aux Pommes',
]);
// WHEN