test(commercial) : cover RG-1.01..1.29 except role-gated (M1) + polish stack (#38)
Auto Tag Develop / tag (push) Successful in 7s

Dernier wagon de la stack back M1. ERP-60 = polish stack + couverture de tests PHPUnit NON dépendante des rôles métier (cf. spec § 7 / § 8.1).

## Phase 0 — polish stack (déjà mergé dans les branches basses via rebase)
- ERP-59 : route sidebar `/clients` (au lieu de `/commercial/clients`), cohérente avec `/suppliers`.
- One-liner pagination Client abandonné : `pagination_client_enabled: true` est déjà le défaut global → `?pagination=false` marche déjà sur `/api/clients` (décision P7).

## Phase 1 — tests (combler les trous, zéro duplication)
8 nouvelles suites couvrant les RG non encore testées par ERP-55/56/57/58 :
- `ClientFormulaireMainTest` — RG-1.02 (téléphone secondaire, max 2).
- `ClientAddressTest` — RG-1.06/07/08 + RG-1.11 (CHECK BDD prospect/billing).
- `ClientUniquenessTest` — RG-1.15/1.17 (Q4 : SIREN/email NON uniques).
- `ClientArchiveTest` — **RG-1.23 : 409 restauration en conflit (gap P1)**.
- `ClientAuditTest` — RG-1.27 (created* figés / updatedBy modificateur) + iban/bic présents dans le diff audité.
- `ClientMigrationTest` — index partiel unique `uq_client_company_name_active` (1 seul) ; pas d'index siren/email.
- `ClientSecurityTest` — 401 anonyme + 403 sans `commercial.clients.view`.
- `ClientPatchStrictTest` — RG-1.28 (403 strict mix de groupes, fonctionnel).

Cahier de test complet (mapping de TOUTES les RG → test) : `docs/specs/M1-clients/cahier-test-back-M1.md`.

## Délégué à ERP-74 (#493)
Matrice RBAC différenciée (bureau/compta/commerciale/usine) + RG-1.04 fonctionnel — exigent les rôles métier seedés après le merge de la stack.

## Gaps documentés (cahier)
- RG-1.29 validation écriture (catégorie type sur adresse → 422) non implémentée back (hors § 8.1, ticket test-only).
- Violations CHECK adresse → rejet (≥400) sans mapping fin 422 (amélioration possible).

## Vérifs
`make db-reset && make php-cs-fixer-allow-risky && make test` → **421 tests OK, 1386 assertions, 0 risky**. Nouveaux tests : 17, 71 assertions.

---------

Co-authored-by: Matthieu <contact@malio.fr>
Reviewed-on: #38
Co-authored-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
Co-committed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
This commit was merged in pull request #38.
This commit is contained in:
2026-06-01 19:46:39 +00:00
committed by admin malio
parent 9507664bd0
commit 120058049c
37 changed files with 3230 additions and 158 deletions
+25 -3
View File
@@ -4,6 +4,9 @@ declare(strict_types=1);
namespace App\Module\Commercial\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineBankRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
@@ -13,10 +16,29 @@ use Symfony\Component\Serializer\Attribute\Groups;
* CIC, Credit Agricole) : referentiel statique seede par la migration M1 et
* re-seede en dev/test par CommercialReferentialFixtures.
*
* Lecture seule au M1 (HP-M2-2). Pas de Timestampable/Blamable (referentiel
* statique whiteliste dans EntitiesAreTimestampableBlamableTest::EXCLUDED). Le
* groupe `client:read:accounting` permet l'embarquement dans la reponse Client.
* Lecture seule au M1 (HP-M2-2) : GetCollection + Get uniquement (ERP-56),
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
* Timestampable/Blamable (referentiel statique whiteliste dans
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
* `client:read:accounting` permet l'embarquement dans la reponse Client.
*/
#[ApiResource(
operations: [
new GetCollection(
security: "is_granted('commercial.clients.view')",
normalizationContext: ['groups' => ['bank:read']],
// Tri par defaut spec M1 § 4.7 : position ASC puis label ASC.
order: ['position' => 'ASC', 'label' => 'ASC'],
// ERP-72 : pagination serveur + toggle ?pagination=false (cf. TvaMode).
paginationClientEnabled: true,
),
new Get(
security: "is_granted('commercial.clients.view')",
normalizationContext: ['groups' => ['bank:read']],
),
],
security: "is_granted('commercial.clients.view')",
)]
#[ORM\Entity(repositoryClass: DoctrineBankRepository::class)]
#[ORM\Table(name: 'bank')]
#[ORM\UniqueConstraint(name: 'uq_bank_code', columns: ['code'])]
@@ -4,6 +4,13 @@ declare(strict_types=1);
namespace App\Module\Commercial\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\ClientAddressProcessor;
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineClientAddressRepository;
use App\Shared\Domain\Attribute\Auditable;
use App\Shared\Domain\Contract\BlamableInterface;
@@ -28,11 +35,46 @@ use Symfony\Component\Validator\Constraints as Assert;
* - sites : SiteInterface (module Sites) via resolve_target_entities
* - contacts : ClientContact (meme module)
* - categories : CategoryInterface (module Catalog) via resolve_target_entities
* — limitees aux types SECTEUR/AUTRE cote validation (RG-1.29, futur Processor)
* — limitees aux types SECTEUR/AUTRE cote validation (RG-1.29, hors ERP-57)
*
* Audite (#[Auditable]) + Timestampable/Blamable. Aucun ApiResource au M1.1
* (sous-ressources branchees a un ticket dedie).
* Audite (#[Auditable]) + Timestampable/Blamable.
*
* Sous-ressource API (ERP-57, spec § 4.5) :
* - POST /api/clients/{clientId}/addresses : creation rattachee au client parent
* (Link toProperty 'client'), security commercial.clients.manage.
* - PATCH / DELETE /api/client_addresses/{id} : security commercial.clients.manage.
* - GET /api/client_addresses/{id} : lecture unitaire (security view) — la
* lecture courante reste via le parent. Pas de GET collection autonome.
* Tout passe par le ClientAddressProcessor (normalisation RG-1.21 billingEmail).
*/
#[ApiResource(
operations: [
new Get(
security: "is_granted('commercial.clients.view')",
normalizationContext: ['groups' => ['client_address:read']],
),
new Post(
uriTemplate: '/clients/{clientId}/addresses',
uriVariables: [
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
],
security: "is_granted('commercial.clients.manage')",
normalizationContext: ['groups' => ['client_address:read']],
denormalizationContext: ['groups' => ['client_address:write']],
processor: ClientAddressProcessor::class,
),
new Patch(
security: "is_granted('commercial.clients.manage')",
normalizationContext: ['groups' => ['client_address:read']],
denormalizationContext: ['groups' => ['client_address:write']],
processor: ClientAddressProcessor::class,
),
new Delete(
security: "is_granted('commercial.clients.manage')",
processor: ClientAddressProcessor::class,
),
],
)]
#[ORM\Entity(repositoryClass: DoctrineClientAddressRepository::class)]
#[ORM\Table(name: 'client_address')]
#[ORM\Index(name: 'idx_client_address_client', columns: ['client_id'])]
@@ -4,6 +4,13 @@ declare(strict_types=1);
namespace App\Module\Commercial\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\ClientContactProcessor;
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineClientContactRepository;
use App\Shared\Domain\Attribute\Auditable;
use App\Shared\Domain\Contract\BlamableInterface;
@@ -16,13 +23,50 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* Contact d'un client (1:n) — onglet Contact. Au moins firstName OU lastName
* doit etre renseigne (RG-1.05) : la contrainte est portee par un CHECK BDD
* (chk_client_contact_name) et validee dans le futur ClientContactProcessor ;
* (chk_client_contact_name) et validee dans le ClientContactProcessor ;
* l'entite reste permissive (les deux champs sont nullable).
*
* Audite (#[Auditable]) + Timestampable/Blamable (pattern Shared standard).
* Les operations CRUD (sous-ressources POST/PATCH/DELETE) sont branchees au
* ticket dedie des sous-ressources — aucun ApiResource au M1.1 (ERP-54).
*
* Sous-ressource API (ERP-57, spec § 4.5) :
* - POST /api/clients/{clientId}/contacts : creation rattachee au client parent
* (Link toProperty 'client'), security commercial.clients.manage.
* - PATCH / DELETE /api/client_contacts/{id} : security commercial.clients.manage.
* Le DELETE est physique (sous-collection, pas le client) ; le processor
* refuse la suppression du dernier contact (RG-1.14, 409).
* - GET /api/client_contacts/{id} : lecture unitaire (security view) — la
* lecture courante reste via le parent (client embarque ses contacts). Pas de
* GET collection autonome : non concernee par la pagination ERP-72.
* Tout passe par le ClientContactProcessor (normalisation RG-1.19/1.20/1.21).
*/
#[ApiResource(
operations: [
new Get(
security: "is_granted('commercial.clients.view')",
normalizationContext: ['groups' => ['client_contact:read']],
),
new Post(
uriTemplate: '/clients/{clientId}/contacts',
uriVariables: [
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
],
security: "is_granted('commercial.clients.manage')",
normalizationContext: ['groups' => ['client_contact:read']],
denormalizationContext: ['groups' => ['client_contact:write']],
processor: ClientContactProcessor::class,
),
new Patch(
security: "is_granted('commercial.clients.manage')",
normalizationContext: ['groups' => ['client_contact:read']],
denormalizationContext: ['groups' => ['client_contact:write']],
processor: ClientContactProcessor::class,
),
new Delete(
security: "is_granted('commercial.clients.manage')",
processor: ClientContactProcessor::class,
),
],
)]
#[ORM\Entity(repositoryClass: DoctrineClientContactRepository::class)]
#[ORM\Table(name: 'client_contact')]
#[ORM\Index(name: 'idx_client_contact_client', columns: ['client_id'])]
@@ -4,6 +4,13 @@ declare(strict_types=1);
namespace App\Module\Commercial\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\ClientRibProcessor;
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineClientRibRepository;
use App\Shared\Domain\Attribute\Auditable;
use App\Shared\Domain\Contract\BlamableInterface;
@@ -16,7 +23,7 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* Coordonnees bancaires d'un client (1:n) — onglet Comptabilite. Au moins un
* RIB est obligatoire si le type de reglement du client est LCR (RG-1.13,
* verifie au futur Processor).
* verifie au ClientRibProcessor : refus du DELETE du dernier RIB sous LCR).
*
* Audit (#[Auditable]) : TOUS les champs sont audites, y compris `iban` et
* `bic` — AUCUN #[AuditIgnore] (decision Matthieu en revue MR 29/05/2026 :
@@ -25,8 +32,45 @@ use Symfony\Component\Validator\Constraints as Assert;
*
* Validation IBAN/BIC : Assert\Iban + Assert\Bic standard Symfony au M1
* (HP-M2-14 : pas de controle externe banque reelle). Timestampable/Blamable
* standard. Aucun ApiResource au M1.1 (sous-ressource branchee ulterieurement).
* standard.
*
* Sous-ressource API (ERP-57, spec § 4.5) — gating comptable renforce :
* - POST /api/clients/{clientId}/ribs : creation rattachee au client parent
* (Link toProperty 'client'), security commercial.clients.accounting.manage.
* - PATCH / DELETE /api/client_ribs/{id} : security commercial.clients.accounting.manage.
* - GET /api/client_ribs/{id} : lecture unitaire, security
* commercial.clients.accounting.view (donnees bancaires sensibles). Pas de
* GET collection autonome.
* Tout passe par le ClientRibProcessor (RG-1.13 sur DELETE).
*/
#[ApiResource(
operations: [
new Get(
security: "is_granted('commercial.clients.accounting.view')",
normalizationContext: ['groups' => ['client_rib:read']],
),
new Post(
uriTemplate: '/clients/{clientId}/ribs',
uriVariables: [
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
],
security: "is_granted('commercial.clients.accounting.manage')",
normalizationContext: ['groups' => ['client_rib:read']],
denormalizationContext: ['groups' => ['client_rib:write']],
processor: ClientRibProcessor::class,
),
new Patch(
security: "is_granted('commercial.clients.accounting.manage')",
normalizationContext: ['groups' => ['client_rib:read']],
denormalizationContext: ['groups' => ['client_rib:write']],
processor: ClientRibProcessor::class,
),
new Delete(
security: "is_granted('commercial.clients.accounting.manage')",
processor: ClientRibProcessor::class,
),
],
)]
#[ORM\Entity(repositoryClass: DoctrineClientRibRepository::class)]
#[ORM\Table(name: 'client_rib')]
#[ORM\Index(name: 'idx_client_rib_client', columns: ['client_id'])]
@@ -4,6 +4,9 @@ declare(strict_types=1);
namespace App\Module\Commercial\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Module\Commercial\Infrastructure\Doctrine\DoctrinePaymentDelayRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
@@ -13,10 +16,29 @@ use Symfony\Component\Serializer\Attribute\Groups;
* referentiel statique seede par la migration M1 et re-seede en dev/test par
* CommercialReferentialFixtures.
*
* Lecture seule au M1 (HP-M2-2). Pas de Timestampable/Blamable (referentiel
* statique whiteliste dans EntitiesAreTimestampableBlamableTest::EXCLUDED). Le
* groupe `client:read:accounting` permet l'embarquement dans la reponse Client.
* Lecture seule au M1 (HP-M2-2) : GetCollection + Get uniquement (ERP-56),
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
* Timestampable/Blamable (referentiel statique whiteliste dans
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
* `client:read:accounting` permet l'embarquement dans la reponse Client.
*/
#[ApiResource(
operations: [
new GetCollection(
security: "is_granted('commercial.clients.view')",
normalizationContext: ['groups' => ['payment_delay:read']],
// Tri par defaut spec M1 § 4.7 : position ASC puis label ASC.
order: ['position' => 'ASC', 'label' => 'ASC'],
// ERP-72 : pagination serveur + toggle ?pagination=false (cf. TvaMode).
paginationClientEnabled: true,
),
new Get(
security: "is_granted('commercial.clients.view')",
normalizationContext: ['groups' => ['payment_delay:read']],
),
],
security: "is_granted('commercial.clients.view')",
)]
#[ORM\Entity(repositoryClass: DoctrinePaymentDelayRepository::class)]
#[ORM\Table(name: 'payment_delay')]
#[ORM\UniqueConstraint(name: 'uq_payment_delay_code', columns: ['code'])]
@@ -4,6 +4,9 @@ declare(strict_types=1);
namespace App\Module\Commercial\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Module\Commercial\Infrastructure\Doctrine\DoctrinePaymentTypeRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
@@ -16,10 +19,29 @@ use Symfony\Component\Serializer\Attribute\Groups;
* Le `code` porte une semantique metier : VIREMENT impose une banque (RG-1.12),
* LCR impose au moins un RIB (RG-1.13).
*
* Lecture seule au M1 (HP-M2-2). Pas de Timestampable/Blamable (referentiel
* statique whiteliste dans EntitiesAreTimestampableBlamableTest::EXCLUDED). Le
* groupe `client:read:accounting` permet l'embarquement dans la reponse Client.
* Lecture seule au M1 (HP-M2-2) : GetCollection + Get uniquement (ERP-56),
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
* Timestampable/Blamable (referentiel statique whiteliste dans
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
* `client:read:accounting` permet l'embarquement dans la reponse Client.
*/
#[ApiResource(
operations: [
new GetCollection(
security: "is_granted('commercial.clients.view')",
normalizationContext: ['groups' => ['payment_type:read']],
// Tri par defaut spec M1 § 4.7 : position ASC puis label ASC.
order: ['position' => 'ASC', 'label' => 'ASC'],
// ERP-72 : pagination serveur + toggle ?pagination=false (cf. TvaMode).
paginationClientEnabled: true,
),
new Get(
security: "is_granted('commercial.clients.view')",
normalizationContext: ['groups' => ['payment_type:read']],
),
],
security: "is_granted('commercial.clients.view')",
)]
#[ORM\Entity(repositoryClass: DoctrinePaymentTypeRepository::class)]
#[ORM\Table(name: 'payment_type')]
#[ORM\UniqueConstraint(name: 'uq_payment_type_code', columns: ['code'])]
@@ -4,6 +4,9 @@ declare(strict_types=1);
namespace App\Module\Commercial\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineTvaModeRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
@@ -13,15 +16,35 @@ use Symfony\Component\Serializer\Attribute\Groups;
* referentiel statique seede par la migration M1 (Version20260601000000) et
* re-seede en dev/test par CommercialReferentialFixtures.
*
* Lecture seule au M1 : pas de POST/PATCH/DELETE (HP-M2-2). L'ApiResource
* (GetCollection + Get, tri position ASC) est branche au ticket dedie des
* referentiels lecture seule.
* Lecture seule au M1 (HP-M2-2) : seules GetCollection et Get sont exposees
* (ERP-56), sous la permission commercial.clients.view ; aucune ecriture
* declaree -> POST/PATCH/DELETE renvoient 405.
*
* Referentiel statique : pas de Timestampable/Blamable (whiteliste dans
* EntitiesAreTimestampableBlamableTest::EXCLUDED, comme CategoryType). Le
* groupe `client:read:accounting` permet d'embarquer le mode dans la reponse
* d'un Client (onglet Comptabilite) au lieu d'un IRI.
*/
#[ApiResource(
operations: [
new GetCollection(
security: "is_granted('commercial.clients.view')",
normalizationContext: ['groups' => ['tva_mode:read']],
// Tri par defaut spec M1 § 4.7 : position ASC puis label ASC
// (ordre des selecteurs comptables) — provider Doctrine par defaut.
order: ['position' => 'ASC', 'label' => 'ASC'],
// ERP-72 : pagination serveur sur toute collection autonome. Le
// toggle client est desactive globalement, on l'active ici pour
// permettre ?pagination=false (alimenter un <MalioSelect> entier).
paginationClientEnabled: true,
),
new Get(
security: "is_granted('commercial.clients.view')",
normalizationContext: ['groups' => ['tva_mode:read']],
),
],
security: "is_granted('commercial.clients.view')",
)]
#[ORM\Entity(repositoryClass: DoctrineTvaModeRepository::class)]
#[ORM\Table(name: 'tva_mode')]
#[ORM\UniqueConstraint(name: 'uq_tva_mode_code', columns: ['code'])]