Merge branch 'develop' into feature/ERP-116-country-referentiel
This commit is contained in:
@@ -51,6 +51,9 @@ abstract class AbstractSupplierApiTestCase extends AbstractCommercialApiTestCase
|
||||
/** IBAN/BIC valides (Assert\Iban / Assert\Bic) reutilises par les seeds. */
|
||||
protected const string VALID_IBAN = 'FR1420041010050500013M02606';
|
||||
protected const string VALID_BIC = 'BNPAFRPPXXX';
|
||||
// BIC allemand valide isolement (pays DE en positions 5-6) : sert au controle
|
||||
// croise pays BIC/IBAN (DE vs IBAN FR -> mismatch, cf. Assert\Bic ibanPropertyPath).
|
||||
protected const string FOREIGN_BIC = 'DEUTDEFFXXX';
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
@@ -295,6 +298,26 @@ abstract class AbstractSupplierApiTestCase extends AbstractCommercialApiTestCase
|
||||
return $this->referential(Bank::class, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexe les violations d'un corps de reponse 422 par propertyPath. Permet
|
||||
* d'asserter qu'un 422 porte bien sur le champ attendu (et n'est pas un 422
|
||||
* orthogonal) : un test qui se contente du code 422 passerait meme si la RG
|
||||
* visee etait cassee pour une autre raison.
|
||||
*
|
||||
* @param array<string, mixed> $body corps decode de la reponse (toArray(false))
|
||||
*
|
||||
* @return array<string, string> propertyPath => message
|
||||
*/
|
||||
protected function violationsByPath(array $body): array
|
||||
{
|
||||
$byPath = [];
|
||||
foreach ($body['violations'] ?? [] as $v) {
|
||||
$byPath[$v['propertyPath']] = $v['message'];
|
||||
}
|
||||
|
||||
return $byPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recupere un referentiel comptable seede (CommercialReferentialFixtures) par
|
||||
* code. Echoue explicitement si absent (fixtures non chargees).
|
||||
@@ -316,24 +339,4 @@ abstract class AbstractSupplierApiTestCase extends AbstractCommercialApiTestCase
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexe les violations d'un corps de reponse 422 par propertyPath. Permet
|
||||
* d'asserter qu'un 422 porte bien sur le champ attendu (et n'est pas un 422
|
||||
* orthogonal) : un test qui se contente du code 422 passerait meme si la RG
|
||||
* visee etait cassee pour une autre raison.
|
||||
*
|
||||
* @param array<string, mixed> $body corps decode de la reponse (toArray(false))
|
||||
*
|
||||
* @return array<string, string> propertyPath => message
|
||||
*/
|
||||
protected function violationsByPath(array $body): array
|
||||
{
|
||||
$byPath = [];
|
||||
foreach ($body['violations'] ?? [] as $v) {
|
||||
$byPath[$v['propertyPath']] = $v['message'];
|
||||
}
|
||||
|
||||
return $byPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
||||
private const string MERGE = 'application/merge-patch+json';
|
||||
private const string VALID_IBAN = 'FR1420041010050500013M02606';
|
||||
private const string VALID_BIC = 'BNPAFRPPXXX';
|
||||
// BIC allemand valide isolement (pays DE en positions 5-6) : sert au controle
|
||||
// croise pays BIC/IBAN (DE vs IBAN FR -> mismatch, cf. Assert\Bic ibanPropertyPath).
|
||||
private const string FOREIGN_BIC = 'DEUTDEFFXXX';
|
||||
|
||||
// === Contacts ===
|
||||
|
||||
@@ -359,6 +362,35 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
||||
self::assertResponseStatusCodeSame(422);
|
||||
}
|
||||
|
||||
/**
|
||||
* Controle croise pays BIC/IBAN (Assert\Bic ibanPropertyPath) : un BIC (DE) et
|
||||
* un IBAN (FR) valides isolement mais de pays differents -> 422. La violation
|
||||
* porte propertyPath=bic et le message FR `ibanMessage` (mapping inline front).
|
||||
*/
|
||||
public function testPostRibWithBicIbanCountryMismatchReturns422WithFrenchMessageOnBic(): void
|
||||
{
|
||||
$client = $this->createAdminClient();
|
||||
$seed = $this->seedClient('Rib Pays Mismatch');
|
||||
|
||||
$response = $client->request('POST', '/api/clients/'.$seed->getId().'/ribs', [
|
||||
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||
'json' => [
|
||||
'label' => 'Compte incoherent',
|
||||
'bic' => self::FOREIGN_BIC,
|
||||
'iban' => self::VALID_IBAN,
|
||||
],
|
||||
]);
|
||||
|
||||
self::assertResponseStatusCodeSame(422);
|
||||
$byPath = [];
|
||||
foreach ($response->toArray(false)['violations'] ?? [] as $v) {
|
||||
$byPath[$v['propertyPath']] = $v['message'];
|
||||
}
|
||||
|
||||
self::assertArrayHasKey('bic', $byPath, 'Le mismatch pays BIC/IBAN doit porter propertyPath=bic (mapping front).');
|
||||
self::assertSame('Le BIC ne correspond pas au pays de l\'IBAN.', $byPath['bic']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression ERP-110 : POST d'un RIB sur un client qui en a DEJA >= 2 ne doit
|
||||
* pas exploser en 500 (NonUniqueResult sur la resolution du parent). L'admin
|
||||
|
||||
@@ -294,6 +294,27 @@ final class SupplierSubResourceApiTest extends AbstractSupplierApiTestCase
|
||||
self::assertResponseStatusCodeSame(422);
|
||||
}
|
||||
|
||||
/**
|
||||
* Controle croise pays BIC/IBAN (Assert\Bic ibanPropertyPath) : un BIC (DE) et
|
||||
* un IBAN (FR) valides isolement mais de pays differents -> 422. La violation
|
||||
* porte propertyPath=bic et le message FR `ibanMessage` (mapping inline front).
|
||||
*/
|
||||
public function testPostRibWithBicIbanCountryMismatchReturns422WithFrenchMessageOnBic(): void
|
||||
{
|
||||
$client = $this->createAdminClient();
|
||||
$seed = $this->seedSupplier('Rib Pays Mismatch');
|
||||
|
||||
$response = $client->request('POST', '/api/suppliers/'.$seed->getId().'/ribs', [
|
||||
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||
'json' => ['label' => 'Compte incoherent', 'bic' => self::FOREIGN_BIC, 'iban' => self::VALID_IBAN],
|
||||
]);
|
||||
|
||||
self::assertResponseStatusCodeSame(422);
|
||||
$byPath = $this->violationsByPath($response->toArray(false));
|
||||
self::assertArrayHasKey('bic', $byPath, 'Le mismatch pays BIC/IBAN doit porter propertyPath=bic (mapping front).');
|
||||
self::assertSame('Le BIC ne correspond pas au pays de l\'IBAN.', $byPath['bic']);
|
||||
}
|
||||
|
||||
public function testDeleteRibNonLcrReturns204(): void
|
||||
{
|
||||
$client = $this->createAdminClient();
|
||||
|
||||
Reference in New Issue
Block a user