3fe0f676f6
Auto Tag Develop / tag (push) Successful in 11s
Ticket Lesstime #139 (M3 — Répertoire prestataires, position 1.9). DoD back avant le front : suite PHPUnit consolidée sur la matrice § 8.1 + captures JSON réelles dans la spec § 4.0.bis. ## Contenu - **Fix réfs comptables** : `provider:read:accounting` ajouté sur `TvaMode`/`PaymentDelay`/`PaymentType`/`Bank` — sans ça elles sortaient en IRI nu dans le détail prestataire (réplique du fix ERP-92 du M2, piège #1 § 4.0.bis). - **`ProviderSerializationContractTest`** (13 tests) : gating RIB/scalaires par omission, réfs compta en objet `{id,code,label}`, `isArchived`, embed categories/sites liste+détail, sous-collections, enveloppe AP4 ; `testDodReferenceJsonShape` dumpe le JSON réel (`PROVIDER_DOD_DUMP=1`). - **`ProviderAuditTest`** (5 tests) : create/update/archive (`technique.Provider`), iban/bic dans le diff (`technique.ProviderRib`, pas dAuditIgnore), trace M2M `sites`. - **`ProviderListTest`** étendu : `?pagination=false`, anti-N+1, filtre `?typeCode=PRESTATAIRE`. - **`ProviderRbacGatingTest`** étendu : restauration en conflit de nom → 409 (RG-3.14). - **`ProviderFixtures`** (§ 8.4) : démo idempotente (complet VIREMENT+banque+RIB, LCR+RIB, CHEQUE multi-cat, minimal, archivé) répartie sur sites 86/17/82 ; skip en env `test`. - Helper `seedCompleteProvider` ; spec § 4.0.bis : gabarits remplacés par les captures réelles (liste + détail avec/sans accounting.view). ## Vérifications - `make php-cs-fixer-allow-risky` → 0 fichier - `make test` → OK, 677 tests, 3328 assertions (garde-fous globaux verts) ## Notes - MR stackée sur ERP-138 (base = sa branche). - Fixtures démo exercées en dev via `make fixtures` (autowiring vérifié). --------- Co-authored-by: Matthieu <contact@malio.fr> Reviewed-on: #100
116 lines
4.2 KiB
PHP
116 lines
4.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Module\Technique\Api;
|
|
|
|
/**
|
|
* Tests fonctionnels du formulaire principal prestataire (POST + PATCH) — ERP-134.
|
|
* Couvre : creation (RG-3.03 sites obligatoires, RG-3.09 type categorie),
|
|
* normalisation companyName (RG-3.11), 409 doublon (RG-3.10).
|
|
*
|
|
* @internal
|
|
*/
|
|
final class ProviderApiTest extends AbstractProviderApiTestCase
|
|
{
|
|
public function testPostMainCreatesProvider(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
|
|
$response = $client->request('POST', '/api/providers', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => $this->validMainPayload('Maintenance Pro', [self::SITE_86]),
|
|
]);
|
|
|
|
self::assertSame(201, $response->getStatusCode());
|
|
$body = $response->toArray();
|
|
// RG-3.11 : companyName normalise en MAJUSCULES.
|
|
self::assertSame('MAINTENANCE PRO', $body['companyName']);
|
|
self::assertArrayHasKey('id', $body);
|
|
// sites embarque (relation directe, site:read) avec name/postalCode.
|
|
self::assertCount(1, $body['sites']);
|
|
self::assertSame('86100', $body['sites'][0]['postalCode']);
|
|
}
|
|
|
|
public function testPostWithoutSiteIsRejected(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
|
|
$payload = $this->validMainPayload('Sans Site', [self::SITE_86]);
|
|
$payload['sites'] = [];
|
|
|
|
$response = $client->request('POST', '/api/providers', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => $payload,
|
|
]);
|
|
|
|
// RG-3.03 : au moins un site obligatoire.
|
|
self::assertSame(422, $response->getStatusCode());
|
|
self::assertArrayHasKey('sites', $this->violationsByPath($response->toArray(false)));
|
|
}
|
|
|
|
public function testPostWithoutCategoryIsRejected(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
|
|
$payload = $this->validMainPayload('Sans Categorie', [self::SITE_86]);
|
|
$payload['categories'] = [];
|
|
|
|
$response = $client->request('POST', '/api/providers', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => $payload,
|
|
]);
|
|
|
|
// RG-3.09 : au moins une categorie obligatoire.
|
|
self::assertSame(422, $response->getStatusCode());
|
|
self::assertArrayHasKey('categories', $this->violationsByPath($response->toArray(false)));
|
|
}
|
|
|
|
public function testPostWithForeignCategoryTypeIsRejected(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
$foreign = $this->foreignCategory();
|
|
|
|
$payload = $this->validMainPayload('Mauvais Type', [self::SITE_86]);
|
|
$payload['categories'] = ['/api/categories/'.$foreign->getId()];
|
|
|
|
$response = $client->request('POST', '/api/providers', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => $payload,
|
|
]);
|
|
|
|
// RG-3.09 : categorie hors type PRESTATAIRE -> 422 sur `categories`.
|
|
self::assertSame(422, $response->getStatusCode());
|
|
self::assertArrayHasKey('categories', $this->violationsByPath($response->toArray(false)));
|
|
}
|
|
|
|
public function testDuplicateCompanyNameReturns409(): void
|
|
{
|
|
$this->seedProvider('Doublon Sarl', [self::SITE_86]);
|
|
$client = $this->createAdminClient();
|
|
|
|
$response = $client->request('POST', '/api/providers', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
// Casse differente : l'unicite est insensible a la casse (LOWER).
|
|
'json' => $this->validMainPayload('doublon sarl', [self::SITE_86]),
|
|
]);
|
|
|
|
// RG-3.10 : doublon de nom (case-insensitive) -> 409.
|
|
self::assertSame(409, $response->getStatusCode());
|
|
}
|
|
|
|
public function testSameNameAfterArchiveIsAllowed(): void
|
|
{
|
|
// Index partiel : l'unicite ignore les archives -> reutilisation du nom OK.
|
|
$this->seedProvider('Recyclage Express', [self::SITE_86], isArchived: true);
|
|
$client = $this->createAdminClient();
|
|
|
|
$response = $client->request('POST', '/api/providers', [
|
|
'headers' => ['Content-Type' => self::LD],
|
|
'json' => $this->validMainPayload('Recyclage Express', [self::SITE_86]),
|
|
]);
|
|
|
|
self::assertSame(201, $response->getStatusCode());
|
|
}
|
|
}
|