diff --git a/database/factories/IncoCompoFactory.php b/database/factories/IncoCompoFactory.php new file mode 100644 index 0000000..de297a2 --- /dev/null +++ b/database/factories/IncoCompoFactory.php @@ -0,0 +1,213 @@ + + */ +final class IncoCompoFactory extends Factory +{ + protected $model = IncoCompo::class; + + /** + * @return array + */ + #[\Override] + public function definition(): array + { + $idInco = (string) fake()->unique()->numberBetween(10000, 99999); + + return [ + 'id' => $idInco, + 'id_inco' => $idInco, + 'identification' => [ + 'name' => 'Poulet Rôti 1kg', + 'number' => $idInco, + 'source' => 'LDC', + ], + 'energy' => [ + 'reference' => ['size' => '100g', 'energyKj' => '500', 'energyKcal' => '120'], + 'portion' => ['size' => '150g', 'energyKj' => '750', 'energyKcal' => '180'], + ], + 'reference_macronutrients' => [ + 'fat' => ['amount' => '10.0', 'precision' => null], + 'saturatedFat' => ['amount' => '2.5', 'precision' => null], + 'carbohydrates' => ['amount' => '0.5', 'precision' => null], + 'sugars' => ['amount' => '0.1', 'precision' => null], + 'fiber' => ['amount' => '0.0', 'precision' => null], + 'protein' => ['amount' => '22.0', 'precision' => null], + 'salt' => ['amount' => '1.2', 'precision' => null], + 'sodium' => '0.48', + ], + 'portion_macronutrients' => [ + 'fat' => ['amount' => '15.0', 'precision' => null], + 'saturatedFat' => ['amount' => '3.75', 'precision' => null], + 'carbohydrates' => ['amount' => '0.75', 'precision' => null], + 'sugars' => ['amount' => '0.15', 'precision' => null], + 'fiber' => ['amount' => '0.0', 'precision' => null], + 'protein' => ['amount' => '33.0', 'precision' => null], + 'salt' => ['amount' => '1.8', 'precision' => null], + 'sodium' => '0.72', + ], + 'fresh_produce_and_nuts' => [ + 'reference' => ['fruits' => '0', 'nuts' => '0'], + 'portion' => ['fruits' => '0', 'nuts' => '0'], + 'freshFnlPercentage' => ['value' => '0'], + 'fruitsPercentage' => ['value' => '0'], + ], + 'reference_intakes' => [ + 'energyE14' => ['value' => '6%'], + 'energyKj' => ['value' => '6%'], + 'fat' => ['value' => '14%'], + 'saturatedFat' => ['value' => '13%'], + 'carbohydrates' => ['value' => '0%'], + 'sugars' => ['value' => '0%'], + 'protein' => ['value' => '44%'], + 'salt' => ['value' => '20%'], + 'portionAmount' => '150g', + 'proteinToLipidRatio' => '2.2', + ], + 'nutri_score' => [ + 'class' => 'A', + 'score' => -2, + 'isFnl' => false, + 'status' => 'valid', + ], + 'nutri_score_points' => [ + 'energyPoints' => '1', + 'saturatedFatPoints' => '1', + 'sugarsPoints' => '0', + 'saltPoints' => '2', + 'fiberPoints' => '0', + 'proteinPoints' => '5', + 'freshFnlPoints' => '0', + ], + 'minerals' => [ + 'calcium' => '12.0', + 'magnesium' => '25.0', + 'potassium' => '300.0', + 'phosphorus' => '200.0', + 'chloride' => '0.0', + 'iron' => '1.1', + 'zinc' => '1.5', + 'copper' => '0.1', + 'manganese' => '0.0', + 'selenium' => '15.0', + 'iodine' => '0.0', + 'chromium' => '0.0', + 'molybdenum' => '0.0', + 'sulfur' => '0.0', + 'nitrates' => '0.0', + ], + 'vitamins' => [ + 'vitaminA' => '0.0', + 'vitaminB6' => '0.4', + 'vitaminB12' => '0.5', + 'vitaminC' => '0.0', + 'vitaminD' => '0.0', + 'vitaminE' => '0.2', + 'vitaminK' => '0.0', + 'cholecalciferol' => '0.0', + 'niacin' => '8.0', + 'riboflavin' => '0.2', + 'thiamine' => '0.1', + 'pantothenicAcid' => '1.0', + 'biotin' => '0.0', + 'folates' => '10.0', + ], + 'carbohydrates_detail' => [ + 'starch' => '0.0', + 'maltodextrin' => '0.0', + 'sucrose' => '0.0', + 'glucose' => '0.0', + 'lactose' => '0.0', + 'maltose' => '0.0', + 'galactose' => '0.0', + 'carbohydrateHydrates' => '0.0', + 'boundFructose' => '0.0', + 'freeFructose' => '0.0', + 'oligosaccharides' => '0.0', + 'polyols' => '0.0', + 'solubleFiber' => '0.0', + 'inositol' => '0.0', + ], + 'fatty_acids' => [ + 'fd' => '0.0', + 'cholesterol' => '70.0', + 'transFat' => '0.1', + 'formic' => '0.0', + 'acetic' => '0.0', + 'propionic' => '0.0', + 'butyric' => '0.0', + 'valeric' => '0.0', + 'caproic' => '0.0', + 'enanthic' => '0.0', + 'caprylic' => '0.0', + 'pelargonic' => '0.0', + 'capric' => '0.0', + 'undecylic' => '0.0', + 'lauric' => '0.0', + 'tridecylic' => '0.0', + 'myristic' => '0.1', + 'pentadecylic' => '0.0', + 'f16d0' => '0.0', + 'margaric' => '0.0', + 'stearic' => '0.8', + 'arachidic' => '0.0', + 'heneicosylic' => '0.0', + 'behenic' => '0.0', + 'tricosylic' => '0.0', + 'lignoceric' => '0.0', + 'carboceric' => '0.0', + 'cerotic' => '0.0', + 'ceroplastic' => '0.0', + 'montanic' => '0.0', + 'nonacosylic' => '0.0', + 'melissic' => '0.0', + 'laceric' => '0.0', + 'hentriacontylic' => '0.0', + 'hextriacontylic' => '0.0', + 'heptatriacontylic' => '0.0', + 'octatriacontylic' => '0.0', + 'nonadylie' => '0.0', + 'psyllic' => '0.0', + 'palmitic' => '1.5', + 'oleic' => '2.0', + 'f18d' => '0.0', + 'f19d' => '0.0', + 'f11eico' => '0.0', + 'geddic' => '0.0', + 'erucic' => '0.0', + 'nervonic' => '0.0', + 'hyenic' => '0.0', + 'amscis' => '0.0', + 'f18d2cn6' => '0.5', + 'f18d3n3' => '0.1', + 'f20d4' => '0.0', + 'f20d5n3' => '0.0', + 'f22d6n3' => '0.0', + 'fapun3' => '0.0', + 'fapun6' => '0.0', + 'fapun9' => '0.0', + 'fapucis' => '0.0', + 'fapulc' => '0.0', + ], + 'amino_acids' => [ + 'essentialAminoAcids' => '8.5', + 'caseins' => '0.0', + 'wheyProtein' => '0.0', + ], + 'special_compounds' => [ + 'choline' => '60.0', + 'carnitine' => '5.0', + 'taurine' => '0.0', + 'nucleotides' => '0.0', + ], + ]; + } +} diff --git a/database/factories/IncoSheetFactory.php b/database/factories/IncoSheetFactory.php new file mode 100644 index 0000000..08dc140 --- /dev/null +++ b/database/factories/IncoSheetFactory.php @@ -0,0 +1,71 @@ + + */ +final class IncoSheetFactory extends Factory +{ + protected $model = IncoSheet::class; + + /** + * @return array + */ + #[\Override] + public function definition(): array + { + return [ + 'id' => (string) fake()->unique()->numberBetween(10000, 99999), + 'name' => 'Poulet Rôti 1kg', + 'label' => 'Poulet Rôti Classe A', + 'description' => 'Poulet prêt à cuire élevé en France', + 'allegations' => [ + 'allegations' => ['Volaille française'], + 'health' => [], + 'nutrition' => ['Riche en protéines'], + 'other' => [], + ], + 'sell_arguments' => 'Origine France garantie', + 'preparation_advices' => 'Cuisson au four 1h à 180°C', + 'tips' => 'Servir chaud', + 'sell_familly' => 'Volaille', + 'ingredients' => [ + 'Ingrédients' => ['Viande de poulet (98%)', 'Sel', 'Epices'], + ], + 'portions' => [ + 'lowPart' => 100, + 'highPart' => 150, + 'approximative' => false, + ], + 'allergens' => [ + ['code' => 1, 'label' => 'Gluten'], + ], + 'brand' => [ + 'code' => 'M01', + 'label' => 'Le Gaulois', + ], + 'is_seasonal' => false, + 'weight' => [ + 'netWeight' => 1000, + 'grossWeight' => 1100, + 'theoreticalAverage' => 1050, + ], + 'nutriscore' => [ + 'grade' => 'A', + ], + 'storage_condition' => [ + 'instructions' => 'À conserver entre 0°C et 4°C', + ], + 'additives' => [ + ['code' => 'E300', 'label' => 'Acide ascorbique'], + ], + 'compo_id' => (string) fake()->numberBetween(10000, 99999), + ]; + } +} diff --git a/database/migrations/2026_08_14_000001_create_inco_sheets_table.php b/database/migrations/2026_08_14_000001_create_inco_sheets_table.php new file mode 100644 index 0000000..3efd922 --- /dev/null +++ b/database/migrations/2026_08_14_000001_create_inco_sheets_table.php @@ -0,0 +1,56 @@ +dropIfExists('inco_sheets'); + + $schema->create('inco_sheets', function (Blueprint $table) { + $table->string('id')->primary(); + $table->string('name'); + $table->string('label'); + $table->text('description'); + $table->json('allegations'); + $table->text('sell_arguments'); + $table->text('preparation_advices'); + $table->text('tips')->nullable(); + $table->string('sell_familly')->nullable(); + $table->json('ingredients'); + $table->json('portions')->nullable(); + $table->json('allergens'); + $table->json('brand'); + $table->boolean('is_seasonal')->default(false); + $table->json('weight')->nullable(); + $table->json('nutriscore')->nullable(); + $table->json('storage_condition')->nullable(); + $table->json('additives'); + $table->string('compo_id')->nullable(); + $table->timestamps(); + + $table->index('name'); + $table->index('compo_id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::connection(Config::string('database.arcadia_meta_model')) + ->dropIfExists('inco_sheets'); + } +}; diff --git a/database/migrations/2026_08_14_000002_create_inco_compos_table.php b/database/migrations/2026_08_14_000002_create_inco_compos_table.php new file mode 100644 index 0000000..845596d --- /dev/null +++ b/database/migrations/2026_08_14_000002_create_inco_compos_table.php @@ -0,0 +1,52 @@ +dropIfExists('inco_compos'); + + $schema->create('inco_compos', function (Blueprint $table) { + $table->string('id')->primary(); + $table->string('id_inco'); + $table->json('identification'); + $table->json('energy'); + $table->json('reference_macronutrients'); + $table->json('portion_macronutrients'); + $table->json('fresh_produce_and_nuts'); + $table->json('reference_intakes'); + $table->json('nutri_score'); + $table->json('nutri_score_points'); + $table->json('minerals'); + $table->json('vitamins'); + $table->json('carbohydrates_detail'); + $table->json('fatty_acids'); + $table->json('amino_acids'); + $table->json('special_compounds'); + $table->timestamps(); + + $table->index('id_inco'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::connection(Config::string('database.arcadia_meta_model')) + ->dropIfExists('inco_compos'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index a7bdace..08417dd 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -4,18 +4,18 @@ declare(strict_types=1); namespace Database\Seeders; -use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; -class DatabaseSeeder extends Seeder +final class DatabaseSeeder extends Seeder { - use WithoutModelEvents; - /** * Seed the application's database. */ public function run(): void { - $this->call(EmployeeSeeder::class); + $this->call([ + EmployeeSeeder::class, + IncoSheetSeeder::class, + ]); } } diff --git a/database/seeders/IncoSheetSeeder.php b/database/seeders/IncoSheetSeeder.php new file mode 100644 index 0000000..0f40db8 --- /dev/null +++ b/database/seeders/IncoSheetSeeder.php @@ -0,0 +1,57 @@ + '1', + 'compo_id' => '1', + 'name' => 'Poulet Rôti 1kg', + 'label' => 'Poulet Rôti aux Herbes', + ], + [ + 'id' => '2', + 'compo_id' => '2', + 'name' => 'Salade Niçoise 300g', + 'label' => 'Salade Niçoise', + ], + [ + 'id' => '3', + 'compo_id' => '3', + 'name' => 'Lasagnes Bolognaise 400g', + 'label' => 'Lasagnes Bolognaise', + ], + ]; + + foreach ($sheetDataList as $data) { + if (! IncoSheet::query()->where('id', $data['id'])->exists()) { + IncoSheet::factory()->create([ + 'id' => $data['id'], + 'compo_id' => $data['compo_id'], + 'name' => $data['name'], + 'label' => $data['label'], + ]); + } + + if (! IncoCompo::query()->where('id', $data['compo_id'])->exists()) { + IncoCompo::factory()->create([ + 'id' => $data['compo_id'], + 'id_inco' => $data['compo_id'], + ]); + } + } + } +} diff --git a/tests/Integration/Database/Seeders/DatabaseSeederTest.php b/tests/Integration/Database/Seeders/DatabaseSeederTest.php new file mode 100644 index 0000000..896d44c --- /dev/null +++ b/tests/Integration/Database/Seeders/DatabaseSeederTest.php @@ -0,0 +1,29 @@ +run(); + + // THEN + expect(Employee::count())->toBeGreaterThan(0) + ->and(IncoSheet::count())->toBeGreaterThan(0); + }); +}); diff --git a/tests/Integration/Database/Seeders/EmployeeSeederTest.php b/tests/Integration/Database/Seeders/EmployeeSeederTest.php new file mode 100644 index 0000000..03af7d1 --- /dev/null +++ b/tests/Integration/Database/Seeders/EmployeeSeederTest.php @@ -0,0 +1,27 @@ +run(); + + // THEN + expect(Employee::count())->toBe(4); + }); +}); diff --git a/tests/Integration/Database/Seeders/IncoSheetSeederTest.php b/tests/Integration/Database/Seeders/IncoSheetSeederTest.php new file mode 100644 index 0000000..4c76db3 --- /dev/null +++ b/tests/Integration/Database/Seeders/IncoSheetSeederTest.php @@ -0,0 +1,29 @@ +run(); + + // THEN + expect(IncoSheet::count())->toBe(3) + ->and(IncoCompo::count())->toBe(3); + }); +}); diff --git a/tests/Integration/Infra/Database/Models/EmployeeModelTest.php b/tests/Integration/Infra/Database/Models/EmployeeModelTest.php new file mode 100644 index 0000000..a0fca5b --- /dev/null +++ b/tests/Integration/Infra/Database/Models/EmployeeModelTest.php @@ -0,0 +1,27 @@ +create(); + + // WHEN + $retrieved = Employee::find($employee->id); + + // THEN + expect($retrieved)->not->toBeNull() + ->and($retrieved->id)->toBe($employee->id); + }); +}); diff --git a/tests/Integration/Infra/Database/Models/IncoCompoModelTest.php b/tests/Integration/Infra/Database/Models/IncoCompoModelTest.php new file mode 100644 index 0000000..9df0c4c --- /dev/null +++ b/tests/Integration/Infra/Database/Models/IncoCompoModelTest.php @@ -0,0 +1,27 @@ +create(); + + // WHEN + $retrieved = IncoCompo::find($compo->id); + + // THEN + expect($retrieved)->not->toBeNull() + ->and($retrieved->id)->toBe($compo->id); + }); +}); diff --git a/tests/Integration/Infra/Database/Models/IncoSheetModelTest.php b/tests/Integration/Infra/Database/Models/IncoSheetModelTest.php new file mode 100644 index 0000000..de94bfe --- /dev/null +++ b/tests/Integration/Infra/Database/Models/IncoSheetModelTest.php @@ -0,0 +1,30 @@ +create([ + 'name' => 'Poulet Rôti 1kg Test', + ]); + + // WHEN + $retrieved = IncoSheet::find($sheet->id); + + // THEN + expect($retrieved)->not->toBeNull() + ->and($retrieved->id)->toBe($sheet->id) + ->and($retrieved->name)->toBe('Poulet Rôti 1kg Test'); + }); +});