48 lines
1.7 KiB
PHP
48 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Module\Commercial\Api;
|
|
|
|
/**
|
|
* Tests d'archivage / restauration — combler les trous (ERP-60).
|
|
*
|
|
* Le cas nominal RG-1.22 (archive pose archivedAt) + RG-1.23 (restauration
|
|
* repasse archivedAt a null) ainsi que le 422 « archive + autre champ » sont
|
|
* DEJA couverts par ClientApiTest (ERP-55). Ce fichier cible le trou identifie
|
|
* en revue (P1 review ERP-55) : le 409 de RESTAURATION en conflit d'unicite.
|
|
*
|
|
* @internal
|
|
*/
|
|
final class ClientArchiveTest extends AbstractCommercialApiTestCase
|
|
{
|
|
private const string MERGE = 'application/merge-patch+json';
|
|
|
|
/**
|
|
* RG-1.23 : restaurer un client archive dont le nom a ete repris par un
|
|
* client actif entre-temps doit echouer en 409 (l'index partiel
|
|
* uq_client_company_name_active n'admet qu'un seul actif portant ce nom).
|
|
*
|
|
* Scenario :
|
|
* 1. un client « ACME CONFLICT » est archive (donc hors index partiel) ;
|
|
* 2. un autre client actif « ACME CONFLICT » est cree (autorise tant que le
|
|
* premier reste archive) ;
|
|
* 3. la restauration du premier le rendrait actif -> collision d'unicite
|
|
* -> ClientProcessor traduit la UniqueConstraintViolationException en 409.
|
|
*/
|
|
public function testRestoreConflictReturns409(): void
|
|
{
|
|
$client = $this->createAdminClient();
|
|
|
|
$archived = $this->seedClient('Acme Conflict', true);
|
|
$this->seedClient('Acme Conflict', false);
|
|
|
|
$client->request('PATCH', '/api/clients/'.$archived->getId(), [
|
|
'headers' => ['Content-Type' => self::MERGE],
|
|
'json' => ['isArchived' => false],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(409);
|
|
}
|
|
}
|