faafd99ef8
Auto Tag Develop / tag (push) Successful in 8s
MR unique regroupant tout le module M5 « Tickets de pesée » (remplace les MR empilées #140/#141/#142/#143).
## Périmètre
- **ERP-188** — Page liste des tickets de pesée + export XLSX (colonnes Fournisseur/Client/Autre + Statut).
- **ERP-189** — Écran « Ajouter » (4 champs en haut, 2 blocs de pesée, pesée bascule/manuelle, date+heure horodatée à la validation).
- **ERP-190** — Écran « Modifier » + bouton Imprimer.
- **ERP-191** — i18n + libellés + branchement site courant.
- **ERP-192** — Bon de pesée PDF généré côté back (template Twig → Dompdf), endpoint `GET /api/weighing_tickets/{id}/print.pdf`.
- **ERP-193** — Cycle de vie brouillon/validé (status DRAFT/VALIDATED, numéro attribué à la validation), DSD saisi conservé en pesée manuelle, retours métier design.
## Vérifications
- Back : tests Logistique + architecture verts, php-cs-fixer propre, migrations appliquées (dev + test).
- Front : suite Vitest complète verte, ESLint propre.
Base : `develop` — contient les 16 commits du M5 (rien d'autre).
Reviewed-on: #144
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
93 lines
3.9 KiB
PHP
93 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Module\Logistique\Api;
|
|
|
|
/**
|
|
* Numerotation des tickets de pesee (RG-5.02 / § 2.5) — tests fonctionnels sur
|
|
* l'API reelle (compteur DBAL `weighing_ticket_counter`, verrou FOR UPDATE).
|
|
*
|
|
* Couvre : format {siteCode}-TP-{NNNN}, sequence incrementale et unique PAR site,
|
|
* independance des sequences entre sites, immuabilite du numero et du site au PATCH
|
|
* (RG-5.09 : aucun groupe d'ecriture sur ces champs).
|
|
*
|
|
* La serialisation concurrente (FOR UPDATE) est exercee a l'identique par le
|
|
* DsdAllocator (cf. DsdAllocatorTest) ; un vrai parallelisme n'est pas reproductible
|
|
* en PHPUnit mono-processus — on valide ici la sequence deterministe.
|
|
*
|
|
* @internal
|
|
*/
|
|
final class WeighingTicketNumberingTest extends AbstractWeighingTicketApiTestCase
|
|
{
|
|
public function testNumberFormatAndSequentialPerSite(): void
|
|
{
|
|
$site = $this->siteByCode('86');
|
|
$http = $this->authManageOnSite($site);
|
|
$client = $this->seedTestClient('Num');
|
|
|
|
// Le numero est attribue a la VALIDATION (brouillon -> valide, ERP-193).
|
|
$first = $this->createValidatedTicket($http, $this->validClientTicketPayload($client));
|
|
$second = $this->createValidatedTicket($http, $this->validClientTicketPayload($client));
|
|
|
|
$n1 = (string) $first['number'];
|
|
$n2 = (string) $second['number'];
|
|
|
|
self::assertMatchesRegularExpression('/^86-TP-\d{4}$/', $n1);
|
|
self::assertMatchesRegularExpression('/^86-TP-\d{4}$/', $n2);
|
|
self::assertNotSame($n1, $n2, 'Deux tickets du meme site portent des numeros distincts (unicite).');
|
|
|
|
// Sequence : le second numero = premier + 1 (compteur par site).
|
|
self::assertSame($this->suffix($n1) + 1, $this->suffix($n2));
|
|
}
|
|
|
|
public function testNumberingIsIsolatedPerSite(): void
|
|
{
|
|
$client = $this->seedTestClient('IsoSite');
|
|
|
|
$http86 = $this->authManageOnSite($this->siteByCode('86'));
|
|
$http17 = $this->authManageOnSite($this->siteByCode('17'));
|
|
|
|
$n86 = (string) $this->createValidatedTicket($http86, $this->validClientTicketPayload($client))['number'];
|
|
$n17 = (string) $this->createValidatedTicket($http17, $this->validClientTicketPayload($client))['number'];
|
|
|
|
// Chaque site encode son propre code dans le numero ; sequences disjointes.
|
|
self::assertStringStartsWith('86-TP-', $n86);
|
|
self::assertStringStartsWith('17-TP-', $n17);
|
|
}
|
|
|
|
public function testNumberAndSiteAreImmutableOnPatch(): void
|
|
{
|
|
$site = $this->siteByCode('86');
|
|
$http = $this->authManageOnSite($site);
|
|
$client = $this->seedTestClient('Immutable');
|
|
|
|
// Ticket valide (numero attribue) puis tentative de re-ecriture.
|
|
$created = $this->createValidatedTicket($http, $this->validClientTicketPayload($client));
|
|
$id = (int) $created['id'];
|
|
$number = (string) $created['number'];
|
|
|
|
// Tentative de re-ecriture du numero et du site (aucun groupe d'ecriture) +
|
|
// changement legitime de la pesee a plein -> net recalcule.
|
|
$patched = $http->request('PATCH', '/api/weighing_tickets/'.$id, [
|
|
'headers' => ['Content-Type' => self::MERGE],
|
|
'json' => [
|
|
'number' => 'HACK-TP-9999',
|
|
'site' => '/api/sites/'.$this->siteByCode('17')->getId(),
|
|
'fullWeight' => 20000,
|
|
],
|
|
])->toArray();
|
|
|
|
self::assertSame($number, $patched['number'], 'Le numero est immuable (RG-5.02 / RG-5.09).');
|
|
self::assertSame('86', $patched['site']['code'], 'Le site est immuable (RG-5.09).');
|
|
// Net recalcule : 20000 - 7150 = 12850 (RG-5.05).
|
|
self::assertSame(12850, $patched['netWeight']);
|
|
}
|
|
|
|
/** Suffixe numerique {NNNN} d'un numero {siteCode}-TP-{NNNN}. */
|
|
private function suffix(string $number): int
|
|
{
|
|
return (int) substr($number, strrpos($number, '-') + 1);
|
|
}
|
|
}
|