feat(commercial) : validation back de la relation + suivi de revue MR (ERP-119)
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 2m52s
Pull Request — Quality gate / Frontend (lint + Vitest + build) (pull_request) Successful in 1m9s

- validation serveur « relation choisie => FK obligatoire » : champ transitoire
  relationType (non persiste) + Assert\Callback portant la 422 sur distributor /
  broker, que le back ne pouvait pas deriver des seules FK nullable
- mutualisation des payloads d'ecriture clients : new.vue consomme buildMainPayload
  / buildAddressPayload / buildRibPayload (fin de la duplication create/edit)
- COMMENT ON TABLE client_address : ajout des types Courtier / Distributeur
  (catalogue + migration Version20260609120000)
- tests : violationsByPath remonte dans AbstractCommercialApiTestCase (fin des
  copies inline) + couverture de la nouvelle RG relation
This commit is contained in:
2026-06-09 21:42:47 +02:00
parent 5b3ce0eb13
commit 8bfaa3f640
11 changed files with 185 additions and 80 deletions
@@ -85,4 +85,77 @@ final class ClientFormulaireMainTest extends AbstractCommercialApiTestCase
self::assertNotNull($persisted);
self::assertSame('LEGACY FIELDS SARL', $persisted->getCompanyName());
}
/**
* RG-1.03 bis : declarer une relation « depend d'un distributeur »
* (relationType, champ transitoire) sans renseigner la FK distributor doit
* produire une 422 portee sur `distributor`. Le back ne peut pas deviner
* l'intention depuis la seule FK nullable (distributor=null = client
* independant), d'ou relationType qui la transporte.
*/
public function testRelationDistributeurSansDistributeurEst422(): void
{
$client = $this->createAdminClient();
$cat = $this->createCategory('SECTEUR');
$body = $client->request('POST', '/api/clients', [
'headers' => ['Content-Type' => self::LD],
'json' => [
'companyName' => 'Relation Sans Distrib SARL',
'categories' => ['/api/categories/'.$cat->getId()],
'relationType' => 'distributeur',
],
])->toArray(false);
self::assertResponseStatusCodeSame(422);
$byPath = $this->violationsByPath($body);
self::assertArrayHasKey('distributor', $byPath);
self::assertSame('Le nom du distributeur est obligatoire.', $byPath['distributor']);
}
/** Idem courtier : relationType=courtier sans broker -> 422 portee sur `broker`. */
public function testRelationCourtierSansCourtierEst422(): void
{
$client = $this->createAdminClient();
$cat = $this->createCategory('SECTEUR');
$body = $client->request('POST', '/api/clients', [
'headers' => ['Content-Type' => self::LD],
'json' => [
'companyName' => 'Relation Sans Courtier SARL',
'categories' => ['/api/categories/'.$cat->getId()],
'relationType' => 'courtier',
],
])->toArray(false);
self::assertResponseStatusCodeSame(422);
$byPath = $this->violationsByPath($body);
self::assertArrayHasKey('broker', $byPath);
self::assertSame('Le nom du courtier est obligatoire.', $byPath['broker']);
}
/**
* Le champ transitoire relationType ne casse pas la creation nominale : avec
* la FK correspondante renseignee, le client se cree (201) et relationType
* n'est jamais serialise en sortie (write-only, aucun groupe de lecture).
*/
public function testRelationDistributeurAvecDistributeurEst201(): void
{
$client = $this->createAdminClient();
$cat = $this->createCategory('SECTEUR');
$distributor = $this->seedClient('Distrib Cible', false, 'DISTRIBUTEUR');
$data = $client->request('POST', '/api/clients', [
'headers' => ['Content-Type' => self::LD],
'json' => [
'companyName' => 'Relation Ok SARL',
'categories' => ['/api/categories/'.$cat->getId()],
'relationType' => 'distributeur',
'distributor' => '/api/clients/'.$distributor->getId(),
],
])->toArray();
self::assertResponseStatusCodeSame(201);
self::assertArrayNotHasKey('relationType', $data);
}
}