test(commercial) : reproduit la 500 NonUniqueResult au POST contact sur client peuple (ERP-110)
This commit is contained in:
@@ -94,6 +94,51 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertSame('L\'adresse email n\'est pas valide.', $byPath['email']);
|
self::assertSame('L\'adresse email n\'est pas valide.', $byPath['email']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regression ERP-110 (bug subresource Link toProperty) : POST d'un contact sur
|
||||||
|
* un client qui en a DEJA >= 2 ne doit pas exploser en 500
|
||||||
|
* (NonUniqueResultException sur la resolution du parent), mais creer (201).
|
||||||
|
*/
|
||||||
|
public function testPostContactOnClientWithTwoExistingContactsReturns201(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Contact Multi');
|
||||||
|
$this->seedContact($seed, 'Alpha');
|
||||||
|
$this->seedContact($seed, 'Beta');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/contacts', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['firstName' => 'Gamma'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Meme contexte (>= 2 contacts existants) : un email invalide doit produire
|
||||||
|
* une 422 par champ (la validation est bien atteinte), pas une 500.
|
||||||
|
*/
|
||||||
|
public function testPostInvalidContactOnPopulatedClientReturns422OnField(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Contact Multi Bad');
|
||||||
|
$this->seedContact($seed, 'Alpha');
|
||||||
|
$this->seedContact($seed, 'Beta');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/clients/'.$seed->getId().'/contacts', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['firstName' => 'Gamma', 'email' => 'pas-un-email'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = [];
|
||||||
|
foreach ($response->toArray(false)['violations'] ?? [] as $v) {
|
||||||
|
$byPath[$v['propertyPath']] = $v['message'];
|
||||||
|
}
|
||||||
|
self::assertArrayHasKey('email', $byPath);
|
||||||
|
self::assertSame('L\'adresse email n\'est pas valide.', $byPath['email']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testPatchContactNormalizes(): void
|
public function testPatchContactNormalizes(): void
|
||||||
{
|
{
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
|
|||||||
Reference in New Issue
Block a user