8490de99da
Auto Tag Develop / tag (push) Successful in 7s
## Contexte Branche ERP-119 — revue de la validation des formulaires clients (déclencheur : écran « Ajouter un client »), accompagnée de plusieurs évolutions de l'écran client (M1). ## Contenu ### Validation front (clients) - Boutons « Valider » toujours actifs (retrait du gating de validité) : c'est le back qui renvoie les 422, mappées en rouge par champ. - Champs requis adossés à une colonne non-nullable : la clé est omise du payload si vide (companyName, RIB, adresse) → 422 NotBlank au lieu d'un 400 de type. - Onglet Contact : au moins un contact requis (l'amorce vide est soumise → 422 RG-1.05). - Onglet Adresse : affichage inline des erreurs type / sites / catégories + RG back « au moins un type d'adresse obligatoire ». ### Nouveaux types d'adresse - Courtier / Distributeur, types autonomes exclusifs : colonnes `is_broker` / `is_distributor` (migration + CHECK miroir d'exclusivité), entité + Callback, et front (select, drapeaux, payloads). ### Saisies manuelles - Adresse : `allow-create` sur le champ Adresse → saisie libre si la BAN ne propose rien. - Date de création : `MalioDate :editable` → saisie clavier JJ/MM/AAAA en plus du calendrier. ### 2e email de facturation - Colonne `billing_email_secondary` (optionnel, max 2), miroir du téléphone secondaire. Bump `@malio/layer-ui` 1.7.8 (prop `addable`). ### Fin d'ajout d'un client - Redirection vers la liste à la validation du dernier onglet remplissable par le rôle (Adresse pour Bureau/Commerciale, Comptabilité pour Admin) + toast « Client ajouté ». Dérivé de `tabKeys`, sans règle RBAC custom. ## Vérifications - Back : suites Module/Commercial + Architecture vertes (Client : 124/124). Migrations appliquées (dev + test). - Front : Vitest vert (272), ESLint OK. > Note : le hook pré-commit flake aléatoirement (JWT 401 / timeout DB) sur des tests sans rapport (Supplier) ; les commits ont été faits après vérification des suites concernées en isolation. Reviewed-on: #80 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
162 lines
6.5 KiB
PHP
162 lines
6.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Module\Commercial\Api;
|
|
|
|
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
|
|
|
/**
|
|
* Tests fonctionnels du formulaire principal apres la refonte contact.
|
|
*
|
|
* RG-1.01 (prenom OU nom) et RG-1.02 (telephone secondaire) ont ete SUPPRIMEES
|
|
* du Client : le contact principal n'est plus porte inline, il vit uniquement
|
|
* dans ClientContact (onglet Contact). Ce fichier verifie que :
|
|
* - le formulaire principal se cree avec les seuls champs subsistants
|
|
* (companyName + categories), sans aucun champ de contact ;
|
|
* - les anciens champs de contact (firstName, lastName, phonePrimary,
|
|
* phoneSecondary, email) ne sont plus exposes ni persistes.
|
|
*
|
|
* @internal
|
|
*/
|
|
final class ClientFormulaireMainTest extends AbstractCommercialApiTestCase
|
|
{
|
|
private const string LD = 'application/ld+json';
|
|
|
|
/**
|
|
* Le formulaire principal n'exige plus que companyName + au moins une
|
|
* categorie (RG-1.16 / RG sur categories). Aucun champ de contact requis.
|
|
*/
|
|
public function testPostMainFormWithoutContactFields(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
$cat = $this->createCategory('SECTEUR');
|
|
|
|
$data = $client->request('POST', '/api/clients', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'companyName' => 'Main Form SARL',
|
|
'categories' => ['/api/categories/'.$cat->getId()],
|
|
],
|
|
])->toArray();
|
|
|
|
self::assertResponseStatusCodeSame(201);
|
|
self::assertSame('MAIN FORM SARL', $data['companyName']);
|
|
|
|
// Les champs de contact inline ont disparu de la representation.
|
|
self::assertArrayNotHasKey('firstName', $data);
|
|
self::assertArrayNotHasKey('lastName', $data);
|
|
self::assertArrayNotHasKey('phonePrimary', $data);
|
|
self::assertArrayNotHasKey('phoneSecondary', $data);
|
|
self::assertArrayNotHasKey('email', $data);
|
|
}
|
|
|
|
/**
|
|
* Les anciens champs de contact envoyes par un appel API direct (payload
|
|
* historique) sont ignores par le denormaliseur : ils n'apparaissent pas
|
|
* dans la representation et ne creent aucune colonne sur le client.
|
|
*/
|
|
public function testLegacyContactFieldsAreIgnored(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
$cat = $this->createCategory('SECTEUR');
|
|
|
|
$data = $client->request('POST', '/api/clients', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'companyName' => 'Legacy Fields SARL',
|
|
'firstName' => 'Ignored',
|
|
'lastName' => 'Ignored',
|
|
'phonePrimary' => '0612345678',
|
|
'phoneSecondary' => '0549001122',
|
|
'email' => 'ignored@test.fr',
|
|
'categories' => ['/api/categories/'.$cat->getId()],
|
|
],
|
|
])->toArray();
|
|
|
|
self::assertResponseStatusCodeSame(201);
|
|
self::assertArrayNotHasKey('firstName', $data);
|
|
self::assertArrayNotHasKey('phonePrimary', $data);
|
|
self::assertArrayNotHasKey('email', $data);
|
|
|
|
// Confirmation cote base : le client cree ne porte aucun contact inline
|
|
// (les colonnes n'existent plus, l'entite n'a plus les proprietes).
|
|
$persisted = $this->getEm()->getRepository(ClientEntity::class)->find($data['id']);
|
|
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);
|
|
}
|
|
}
|