85 lines
3.2 KiB
PHP
85 lines
3.2 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 — combler les trous (ERP-60).
|
|
*
|
|
* RG-1.01 (prenom OU nom obligatoire) et RG-1.03 (distributor/broker exclusifs
|
|
* + type de categorie) sont DEJA couverts par ClientApiTest (ERP-55) : on ne les
|
|
* reduplique pas ici. Ce fichier ne couvre que RG-1.02 (telephone secondaire),
|
|
* non encore testee.
|
|
*
|
|
* @internal
|
|
*/
|
|
final class ClientFormulaireMainTest extends AbstractCommercialApiTestCase
|
|
{
|
|
private const string LD = 'application/ld+json';
|
|
|
|
/**
|
|
* RG-1.02 : le telephone secondaire est optionnel mais persiste (2 colonnes
|
|
* distinctes). Verifie aussi la normalisation chiffres-seuls (RG-1.20) sur
|
|
* la colonne secondaire.
|
|
*/
|
|
public function testPostPersistsSecondaryPhoneNormalized(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
$cat = $this->createCategory('SECTEUR');
|
|
|
|
$data = $client->request('POST', '/api/clients', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'companyName' => 'Two Phones SARL',
|
|
'firstName' => 'A',
|
|
'phonePrimary' => '06.12.34.56.78',
|
|
'phoneSecondary' => '05 49 00 11 22',
|
|
'email' => 'twophones@test.fr',
|
|
'categories' => ['/api/categories/'.$cat->getId()],
|
|
],
|
|
])->toArray();
|
|
|
|
self::assertResponseStatusCodeSame(201);
|
|
self::assertSame('0612345678', $data['phonePrimary']);
|
|
self::assertSame('0549001122', $data['phoneSecondary']);
|
|
}
|
|
|
|
/**
|
|
* RG-1.02 : maximum 2 telephones — le modele n'expose que phonePrimary et
|
|
* phoneSecondary. Un eventuel 3e champ envoye par un appel API direct est
|
|
* ignore (aucune 3e colonne), il ne peut donc pas creer un troisieme numero.
|
|
*/
|
|
public function testThirdPhoneFieldIsIgnored(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
$cat = $this->createCategory('SECTEUR');
|
|
|
|
$data = $client->request('POST', '/api/clients', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => [
|
|
'companyName' => 'Third Phone SARL',
|
|
'firstName' => 'A',
|
|
'phonePrimary' => '0612345678',
|
|
'phoneSecondary' => '0549001122',
|
|
'phoneTertiary' => '0700000000',
|
|
'email' => 'thirdphone@test.fr',
|
|
'categories' => ['/api/categories/'.$cat->getId()],
|
|
],
|
|
])->toArray();
|
|
|
|
self::assertResponseStatusCodeSame(201);
|
|
// Le champ inconnu est ignore par le denormaliseur : il n'apparait pas
|
|
// dans la representation et n'a pas ete persiste.
|
|
self::assertArrayNotHasKey('phoneTertiary', $data);
|
|
|
|
// Confirmation cote base : seules les 2 colonnes telephone existent.
|
|
$persisted = $this->getEm()->getRepository(ClientEntity::class)->find($data['id']);
|
|
self::assertNotNull($persisted);
|
|
self::assertSame('0612345678', $persisted->getPhonePrimary());
|
|
self::assertSame('0549001122', $persisted->getPhoneSecondary());
|
|
}
|
|
}
|