00bd02858c
Auto Tag Develop / tag (push) Successful in 8s
Refonte de la taxonomie Catégories (décision produit 01/06) : le modèle est inversé. ## Modèle - **UN SEUL `category_type` : CLIENT**. `Distributeur` / `Courtier` / `Secteur` / `Autre` (+ catégories métier) deviennent des `Category` rattachées à CLIENT. - Filtrage métier sur un **`code` stable porté par `Category`** (NOT NULL, unique partiel `uq_category_code`), slug MAJUSCULE auto-généré du nom (`CategoryCodeGenerator`), figé à la création, exposé en **lecture seule**. ## Contenu - **M0** : `Category.code` (entité + migration corrective `Version20260602100000` au namespace racine + `COMMENT ON COLUMN` + catalogue + ligne `test-db-setup`). Retrofit `Version20260528120000` rendu conscient des colonnes. - **Seed** : type unique CLIENT, catégories codées (`Distributeur→DISTRIBUTEUR`, etc.), anciens types supprimés. Fixtures `CategoryType`/`Category`/`Client` alignées. - **RG-1.03** : `ClientProcessor::hasCategoryCode` — un distributor/broker doit porter la `Category` de code `DISTRIBUTEUR`/`COURTIER`. Filtre liste/export `categoryType` → `categoryCode`. - **RG-1.29** : `ClientAddress::validateCategoryCodes` — denylist des codes `DISTRIBUTEUR`/`COURTIER` sur une adresse (toute autre catégorie autorisée). - **Specs** M0/M1 (back + front) amendées. ## Tests `make php-cs-fixer-allow-risky` OK ; `make db-reset` OK (type unique CLIENT + 11 catégories codées, idempotent) ; `make test` **443 vert**. Ajouts : RG-1.03 courtier, génération/unicité/lecture-seule du code (`CategoryCodeTest`). ## Coordination - #76 (#500) : RG-1.29 réécrite ici sur le nouveau modèle ; #76 ne garde que le gap 2 (mapping CHECK adresse → 422), indépendant de la taxonomie. - ERP-68 (#486) : fixtures démo (déjà mergées via #41) adaptées ici au type unique CLIENT + codes. - Front #480–483 : selects Catégorie / distributeur / courtier basés sur le `code` (`?categoryCode=`), plus le type. Décisions actées avec le PO : `code` NOT NULL auto-généré (slug) ; périmètre complet (réécriture RG + fixtures déjà mergées). --------- Co-authored-by: Matthieu <contact@malio.fr> Reviewed-on: #42 Co-authored-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr> Co-committed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
300 lines
11 KiB
PHP
300 lines
11 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Module\Commercial\Api;
|
|
|
|
use App\Module\Sites\Domain\Entity\Site;
|
|
|
|
/**
|
|
* Tests fonctionnels de l'onglet Adresse.
|
|
*
|
|
* RG-1.09 (code postal) et RG-1.10 (>= 1 site) sont DEJA couverts par
|
|
* ClientSubResourceApiTest (ERP-57) et ne sont pas reduplique ici. Ce fichier
|
|
* cible :
|
|
* - RG-1.06 / RG-1.07 / RG-1.08 : exclusivite is_prospect vs
|
|
* is_delivery / is_billing ;
|
|
* - RG-1.11 : billing_email obligatoire ssi is_billing ;
|
|
* - RG-1.29 (ERP-78) : les categories de code DISTRIBUTEUR / COURTIER sont
|
|
* interdites sur une adresse (-> 422) ; toute autre categorie est acceptee.
|
|
*
|
|
* Depuis ERP-76, ces regles sont portees par des Assert\Callback sur l'entite
|
|
* ClientAddress (mirror applicatif des CHECK Postgres) : la combinaison invalide
|
|
* est donc rejetee en 422 AVANT la base, et non plus par une violation CHECK
|
|
* remontant en 500. Les CHECK BDD restent en filet de securite (non testes ici,
|
|
* inatteignables tant que les validators applicatifs passent en premier).
|
|
*
|
|
* @internal
|
|
*/
|
|
final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|
{
|
|
private const string LD = 'application/ld+json';
|
|
|
|
/**
|
|
* RG-1.06 / RG-1.07 : une adresse de prospection ne peut pas etre une
|
|
* adresse de livraison -> 422 (Assert\Callback, mirror du CHECK
|
|
* chk_client_address_prospect_exclusive).
|
|
*/
|
|
public function testProspectAddressCannotBeDelivery(): void
|
|
{
|
|
$this->skipIfSitesModuleDisabled();
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedClient('Prospect Delivery');
|
|
|
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'isProspect' => true,
|
|
'isDelivery' => true,
|
|
'postalCode' => '86100',
|
|
'city' => 'Châtellerault',
|
|
'street' => '1 rue du Test',
|
|
'sites' => [$this->firstSiteIri()],
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(422);
|
|
}
|
|
|
|
/**
|
|
* RG-1.06 / RG-1.08 : une adresse de prospection ne peut pas etre une
|
|
* adresse de facturation -> 422. On fournit billingEmail pour que la seule
|
|
* violation possible soit l'exclusivite prospect/billing.
|
|
*/
|
|
public function testProspectAddressCannotBeBilling(): void
|
|
{
|
|
$this->skipIfSitesModuleDisabled();
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedClient('Prospect Billing');
|
|
|
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'isProspect' => true,
|
|
'isBilling' => true,
|
|
'billingEmail' => 'facturation@test.fr',
|
|
'postalCode' => '86100',
|
|
'city' => 'Châtellerault',
|
|
'street' => '1 rue du Test',
|
|
'sites' => [$this->firstSiteIri()],
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(422);
|
|
}
|
|
|
|
/**
|
|
* RG-1.11 : une adresse de facturation exige un billingEmail -> 422.
|
|
*/
|
|
public function testBillingAddressRequiresBillingEmail(): void
|
|
{
|
|
$this->skipIfSitesModuleDisabled();
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedClient('Billing No Email');
|
|
|
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'isBilling' => true,
|
|
'postalCode' => '86100',
|
|
'city' => 'Châtellerault',
|
|
'street' => '1 rue du Test',
|
|
'sites' => [$this->firstSiteIri()],
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(422);
|
|
}
|
|
|
|
/**
|
|
* RG-1.11 (cas chaine vide) : une adresse de facturation avec un billingEmail
|
|
* vide ("") doit etre rejetee en 422, et NON passer la validation pour finir
|
|
* en 500 sur le CHECK BDD. Le ClientAddressProcessor normalise "" -> null
|
|
* APRES la validation : le callback doit donc traiter "" comme « absent ».
|
|
*/
|
|
public function testBillingAddressRejectsEmptyBillingEmail(): void
|
|
{
|
|
$this->skipIfSitesModuleDisabled();
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedClient('Billing Empty Email');
|
|
|
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'isBilling' => true,
|
|
'billingEmail' => '',
|
|
'postalCode' => '86100',
|
|
'city' => 'Châtellerault',
|
|
'street' => '1 rue du Test',
|
|
'sites' => [$this->firstSiteIri()],
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(422);
|
|
}
|
|
|
|
/**
|
|
* RG-1.11 (sens inverse) : une adresse NON facturable ne peut pas porter un
|
|
* billingEmail -> 422.
|
|
*/
|
|
public function testNonBillingAddressRejectsBillingEmail(): void
|
|
{
|
|
$this->skipIfSitesModuleDisabled();
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedClient('Non Billing With Email');
|
|
|
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'isBilling' => false,
|
|
'billingEmail' => 'parasite@test.fr',
|
|
'postalCode' => '86100',
|
|
'city' => 'Châtellerault',
|
|
'street' => '1 rue du Test',
|
|
'sites' => [$this->firstSiteIri()],
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(422);
|
|
}
|
|
|
|
/**
|
|
* RG-1.11 (sens inverse, cas chaine vide) : une adresse NON facturable avec
|
|
* un billingEmail vide ("") est ACCEPTEE (201). Le "" equivaut a « pas
|
|
* d'email » : il ne doit pas declencher la violation « email interdit hors
|
|
* facturation » (sinon un champ simplement vide serait refuse a tort).
|
|
*/
|
|
public function testNonBillingAddressAcceptsEmptyBillingEmail(): void
|
|
{
|
|
$this->skipIfSitesModuleDisabled();
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedClient('Non Billing Empty Email');
|
|
|
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'isBilling' => false,
|
|
'billingEmail' => '',
|
|
'postalCode' => '86100',
|
|
'city' => 'Châtellerault',
|
|
'street' => '1 rue du Test',
|
|
'sites' => [$this->firstSiteIri()],
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(201);
|
|
}
|
|
|
|
/**
|
|
* RG-1.29 : poster une categorie de type DISTRIBUTEUR sur une adresse -> 422
|
|
* avec violation sur le champ `categories`.
|
|
*/
|
|
public function testAddressRejectsDistributorCategory(): void
|
|
{
|
|
$this->skipIfSitesModuleDisabled();
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedClient('Address Distributor Cat');
|
|
$category = $this->createCategory('DISTRIBUTEUR');
|
|
|
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'postalCode' => '86100',
|
|
'city' => 'Châtellerault',
|
|
'street' => '1 rue du Test',
|
|
'sites' => [$this->firstSiteIri()],
|
|
'categories' => ['/api/categories/'.$category->getId()],
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(422);
|
|
self::assertStringContainsString(
|
|
'Type de catégorie non autorisé sur une adresse.',
|
|
(string) $client->getResponse()->getContent(false),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* RG-1.29 : poster une categorie de type COURTIER sur une adresse -> 422.
|
|
*/
|
|
public function testAddressRejectsBrokerCategory(): void
|
|
{
|
|
$this->skipIfSitesModuleDisabled();
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedClient('Address Broker Cat');
|
|
$category = $this->createCategory('COURTIER');
|
|
|
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'postalCode' => '86100',
|
|
'city' => 'Châtellerault',
|
|
'street' => '1 rue du Test',
|
|
'sites' => [$this->firstSiteIri()],
|
|
'categories' => ['/api/categories/'.$category->getId()],
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(422);
|
|
}
|
|
|
|
/**
|
|
* RG-1.29 : une categorie de type SECTEUR est autorisee sur une adresse.
|
|
*/
|
|
public function testAddressAcceptsSectorCategory(): void
|
|
{
|
|
$this->skipIfSitesModuleDisabled();
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedClient('Address Sector Cat');
|
|
$category = $this->createCategory('SECTEUR');
|
|
|
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'postalCode' => '86100',
|
|
'city' => 'Châtellerault',
|
|
'street' => '1 rue du Test',
|
|
'sites' => [$this->firstSiteIri()],
|
|
'categories' => ['/api/categories/'.$category->getId()],
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(201);
|
|
}
|
|
|
|
/**
|
|
* RG-1.29 : une categorie de type AUTRE est autorisee sur une adresse.
|
|
*/
|
|
public function testAddressAcceptsOtherCategory(): void
|
|
{
|
|
$this->skipIfSitesModuleDisabled();
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedClient('Address Other Cat');
|
|
$category = $this->createCategory('AUTRE');
|
|
|
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'postalCode' => '86100',
|
|
'city' => 'Châtellerault',
|
|
'street' => '1 rue du Test',
|
|
'sites' => [$this->firstSiteIri()],
|
|
'categories' => ['/api/categories/'.$category->getId()],
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(201);
|
|
}
|
|
|
|
/**
|
|
* Retourne l'IRI du premier site seede (fixtures Sites).
|
|
*/
|
|
private function firstSiteIri(): string
|
|
{
|
|
$site = $this->getEm()->getRepository(Site::class)->findOneBy([]);
|
|
self::assertNotNull($site, 'Aucun site seede : impossible de tester les adresses.');
|
|
|
|
return '/api/sites/'.$site->getId();
|
|
}
|
|
}
|