test(commercial) : tests PHPUnit M2 fournisseurs (matrice RG + contrat sérialisation + DoD JSON réel) (ERP-92)
Suite fonctionnelle M2 assertant sur le CORPS JSON (jamais les annotations),
jumelle de la suite clients M1 :
- contrat de sérialisation : 4 régressions M1 re-testées (RIB gaté absent pour
Commerciale, booléens triageProvider/isArchived présents, embed
categories[].code/name, embed sites[].name/postalCode objet) + enveloppe AP4
(member/totalItems/view, archivés exclus) + suppression du contact inline ;
- matrice RBAC réelle (app:seed-rbac) bureau/compta/commerciale/usine 200/403,
gating accounting par omission de clé, mode strict PATCH (RG-2.16) ;
- RG-2.03/2.04/2.05/2.06/2.07/2.08/2.09/2.10/2.11/2.12/2.14/2.15/2.17 ;
- sous-ressources contacts/adresses/ribs (CRUD, sécurité, normalisation) ;
- anti N+1 liste (compte de requêtes constant), audit Supplier + RIB iban/bic.
Fix de contrat découvert et corrigé (sinon DoD figée sur un contrat faux) :
les référentiels comptables (TvaMode/PaymentType/PaymentDelay/Bank) ne portaient
que le groupe client:read:accounting (M1) → sur un fournisseur ils sortaient en
IRI nu. Ajout de supplier:read:accounting → objet {id, code, label} embarqué.
makefile : test-db-setup recrée l'index partiel uq_supplier_company_name_active
(droppé par schema:update comme pour le client) — oubli M2.
DoD § 4.0.bis : réponses JSON RÉELLES (liste + détail admin/commerciale) collées,
capturées via SupplierSerializationContractTest.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Module\Commercial\Api;
|
||||
|
||||
/**
|
||||
* Tests de structure / migration M2 (§ 8.1). Vérifie au niveau du schéma Postgres :
|
||||
* - l'unique index partiel fonctionnel uq_supplier_company_name_active existe
|
||||
* (LOWER(company_name), partiel sur actifs non archivés / non supprimés —
|
||||
* RG-2.11), seule unicité de nom conservée ; pas d'index unique siren/email ;
|
||||
* - le type de catégorie FOURNISSEUR est présent (seedé migration + fixture).
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class SupplierMigrationTest extends AbstractSupplierApiTestCase
|
||||
{
|
||||
public function testCompanyNameActivePartialIndexExistsExactlyOnce(): void
|
||||
{
|
||||
$rows = $this->supplierIndexes();
|
||||
|
||||
$companyNameIndexes = array_filter(
|
||||
$rows,
|
||||
static fn (array $r): bool => 'uq_supplier_company_name_active' === $r['indexname'],
|
||||
);
|
||||
|
||||
self::assertCount(1, $companyNameIndexes, 'Il doit exister exactement UN index uq_supplier_company_name_active.');
|
||||
|
||||
$def = strtolower((string) array_values($companyNameIndexes)[0]['indexdef']);
|
||||
self::assertStringContainsString('unique', $def);
|
||||
self::assertStringContainsString('lower', $def);
|
||||
self::assertStringContainsString('company_name', $def);
|
||||
self::assertStringContainsString('where', $def, 'L\'index doit etre partiel (clause WHERE sur les actifs).');
|
||||
}
|
||||
|
||||
public function testNoSirenOrEmailUniqueIndexOnSupplier(): void
|
||||
{
|
||||
$names = array_map(static fn (array $r): string => $r['indexname'], $this->supplierIndexes());
|
||||
|
||||
// § 2.6 : SIREN et email NON uniques sur le fournisseur.
|
||||
self::assertNotContains('uq_supplier_siren_active', $names);
|
||||
self::assertNotContains('uq_supplier_email_active', $names);
|
||||
}
|
||||
|
||||
public function testFournisseurCategoryTypeExists(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$count = (int) $this->getEm()->getConnection()->fetchOne(
|
||||
"SELECT COUNT(*) FROM category_type WHERE code = 'FOURNISSEUR'",
|
||||
);
|
||||
|
||||
self::assertSame(1, $count, 'Le type de categorie FOURNISSEUR doit etre present (migration + fixture).');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{indexname: string, indexdef: string}>
|
||||
*/
|
||||
private function supplierIndexes(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
/** @var list<array{indexname: string, indexdef: string}> $rows */
|
||||
return $this->getEm()->getConnection()->fetchAllAssociative(
|
||||
"SELECT indexname, indexdef FROM pg_indexes WHERE schemaname = 'public' AND tablename = 'supplier'",
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user