test(piece) : add quantity tests for MachinePieceLink

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-12 12:06:23 +01:00
parent a940f53f8a
commit 1f90f809ac
2 changed files with 39 additions and 1 deletions

View File

@@ -284,11 +284,12 @@ abstract class AbstractApiTestCase extends ApiTestCase
return $link;
}
protected function createMachinePieceLink(Machine $machine, Piece $piece, ?MachineComponentLink $parentLink = null): MachinePieceLink
protected function createMachinePieceLink(Machine $machine, Piece $piece, ?MachineComponentLink $parentLink = null, int $quantity = 1): MachinePieceLink
{
$link = new MachinePieceLink();
$link->setMachine($machine);
$link->setPiece($piece);
$link->setQuantity($quantity);
if (null !== $parentLink) {
$link->setParentLink($parentLink);
}

View File

@@ -85,6 +85,43 @@ class MachinePieceLinkTest extends AbstractApiTestCase
]);
}
public function testPostWithQuantity(): void
{
$client = $this->createGestionnaireClient();
$machine = $this->createMachine();
$piece = $this->createPiece();
$client->request('POST', '/api/machine_piece_links', [
'headers' => ['Content-Type' => 'application/ld+json'],
'json' => [
'machine' => self::iri('machines', $machine->getId()),
'piece' => self::iri('pieces', $piece->getId()),
'quantity' => 5,
],
]);
$this->assertResponseStatusCodeSame(201);
$this->assertJsonContains(['quantity' => 5]);
}
public function testPostDefaultQuantity(): void
{
$client = $this->createGestionnaireClient();
$machine = $this->createMachine();
$piece = $this->createPiece();
$client->request('POST', '/api/machine_piece_links', [
'headers' => ['Content-Type' => 'application/ld+json'],
'json' => [
'machine' => self::iri('machines', $machine->getId()),
'piece' => self::iri('pieces', $piece->getId()),
],
]);
$this->assertResponseStatusCodeSame(201);
$this->assertJsonContains(['quantity' => 1]);
}
public function testDelete(): void
{
$machine = $this->createMachine('Machine A');