89f9b2fff1
Suite fonctionnelle M2 assertant sur le CORPS JSON (jamais les annotations),
jumelle de la suite clients M1 :
- contrat de sérialisation : 4 régressions M1 re-testées (RIB gaté absent pour
Commerciale, booléens triageProvider/isArchived présents, embed
categories[].code/name, embed sites[].name/postalCode objet) + enveloppe AP4
(member/totalItems/view, archivés exclus) + suppression du contact inline ;
- matrice RBAC réelle (app:seed-rbac) bureau/compta/commerciale/usine 200/403,
gating accounting par omission de clé, mode strict PATCH (RG-2.16) ;
- RG-2.03/2.04/2.05/2.06/2.07/2.08/2.09/2.10/2.11/2.12/2.14/2.15/2.17 ;
- sous-ressources contacts/adresses/ribs (CRUD, sécurité, normalisation) ;
- anti N+1 liste (compte de requêtes constant), audit Supplier + RIB iban/bic.
Fix de contrat découvert et corrigé (sinon DoD figée sur un contrat faux) :
les référentiels comptables (TvaMode/PaymentType/PaymentDelay/Bank) ne portaient
que le groupe client:read:accounting (M1) → sur un fournisseur ils sortaient en
IRI nu. Ajout de supplier:read:accounting → objet {id, code, label} embarqué.
makefile : test-db-setup recrée l'index partiel uq_supplier_company_name_active
(droppé par schema:update comme pour le client) — oubli M2.
DoD § 4.0.bis : réponses JSON RÉELLES (liste + détail admin/commerciale) collées,
capturées via SupplierSerializationContractTest.
95 lines
3.2 KiB
PHP
95 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Module\Commercial\Api;
|
|
|
|
/**
|
|
* Tests fonctionnels des RG comptables inter-champs portees par les Assert\Callback
|
|
* de l'entite Supplier (M2, RG-2.07 / RG-2.08), via le PATCH de l'onglet
|
|
* Comptabilite (groupe supplier:write:accounting). On asserte le code HTTP et le
|
|
* propertyPath de la violation (consommable par extractApiViolations cote front,
|
|
* ERP-101). Complete les tests unitaires SupplierValidationTest par la preuve HTTP.
|
|
*
|
|
* @internal
|
|
*/
|
|
final class SupplierAccountingApiTest extends AbstractSupplierApiTestCase
|
|
{
|
|
// === RG-2.07 : Virement impose une banque ===
|
|
|
|
public function testVirementWithoutBankReturns422OnBankPath(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedSupplier('Virement No Bank');
|
|
|
|
$response = $client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
|
'headers' => ['Content-Type' => self::MERGE, 'Accept' => self::LD],
|
|
'json' => ['paymentType' => '/api/payment_types/'.$this->paymentType('VIREMENT')->getId()],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(422);
|
|
self::assertArrayHasKey('bank', $this->violationsByPath($response->toArray(false)));
|
|
}
|
|
|
|
public function testVirementWithBankReturns200(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedSupplier('Virement With Bank');
|
|
|
|
$client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
|
'headers' => ['Content-Type' => self::MERGE],
|
|
'json' => [
|
|
'paymentType' => '/api/payment_types/'.$this->paymentType('VIREMENT')->getId(),
|
|
'bank' => '/api/banks/'.$this->bank('SG')->getId(),
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(200);
|
|
}
|
|
|
|
// === RG-2.08 : LCR impose au moins un RIB ===
|
|
|
|
public function testLcrWithoutRibReturns422OnRibsPath(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedSupplier('Lcr No Rib');
|
|
|
|
$response = $client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
|
'headers' => ['Content-Type' => self::MERGE, 'Accept' => self::LD],
|
|
'json' => ['paymentType' => '/api/payment_types/'.$this->paymentType('LCR')->getId()],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(422);
|
|
self::assertArrayHasKey('ribs', $this->violationsByPath($response->toArray(false)));
|
|
}
|
|
|
|
public function testLcrWithRibReturns200(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
$seed = $this->seedSupplier('Lcr With Rib');
|
|
$this->addRib($seed);
|
|
|
|
$client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
|
'headers' => ['Content-Type' => self::MERGE],
|
|
'json' => ['paymentType' => '/api/payment_types/'.$this->paymentType('LCR')->getId()],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(200);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $body
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
private function violationsByPath(array $body): array
|
|
{
|
|
$byPath = [];
|
|
foreach ($body['violations'] ?? [] as $v) {
|
|
$byPath[$v['propertyPath']] = $v['message'];
|
|
}
|
|
|
|
return $byPath;
|
|
}
|
|
}
|