8bfaa3f640
- 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
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);
|
|
}
|
|
}
|