feat(documents) : add migration for type column with data classification

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-23 15:14:33 +01:00
parent 342b0afdbb
commit 8d920d5f65
8 changed files with 172 additions and 15 deletions

View File

@@ -290,10 +290,13 @@ abstract class AbstractApiTestCase extends ApiTestCase
return $machine;
}
protected function createComposant(string $name = 'Composant Test', ?ModelType $type = null): Composant
protected function createComposant(string $name = 'Composant Test', ?string $reference = null, ?ModelType $type = null): Composant
{
$c = new Composant();
$c->setName($name);
if (null !== $reference) {
$c->setReference($reference);
}
if (null !== $type) {
$c->setTypeComposant($type);
}

View File

@@ -42,7 +42,7 @@ class ModelTypeSyncControllerTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$this->createComposant('C1', $mt);
$this->createComposant('C1', null, $mt);
$client = $this->createGestionnaireClient();
$client->request('POST', '/api/model_types/'.$mt->getId().'/sync-preview', [
@@ -102,7 +102,7 @@ class ModelTypeSyncControllerTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$this->createComposant('C1', $mt);
$this->createComposant('C1', null, $mt);
// Add a skeleton requirement (simulates a PATCH that already happened)
$em = $this->getEntityManager();
@@ -131,7 +131,7 @@ class ModelTypeSyncControllerTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$composant = $this->createComposant('C1', $mt);
$composant = $this->createComposant('C1', null, $mt);
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
// No skeleton requirements → slot is orphaned
@@ -152,7 +152,7 @@ class ModelTypeSyncControllerTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$composant = $this->createComposant('C1', $mt);
$composant = $this->createComposant('C1', null, $mt);
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
$client = $this->createGestionnaireClient();
@@ -194,7 +194,7 @@ class ModelTypeSyncControllerTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$this->createComposant('C1', $mt);
$this->createComposant('C1', null, $mt);
$em = $this->getEntityManager();
$req = new SkeletonPieceRequirement();

View File

@@ -173,7 +173,7 @@ class MachineTest extends AbstractApiTestCase
$productType = $this->createModelType('Huile', 'HUILE-SLOT', ModelCategory::PRODUCT);
$compType = $this->createModelType('Pompe', 'POMPE-SLOT', ModelCategory::COMPONENT);
$composant = $this->createComposant('Composant avec slots', $compType);
$composant = $this->createComposant('Composant avec slots', null, $compType);
$piece = $this->createPiece('Joint sélectionné', 'REF-JS', $pieceType);
$product = $this->createProduct('Huile sélectionnée', 'REF-HS', $productType);

View File

@@ -109,4 +109,66 @@ class FilterTest extends AbstractApiTestCase
$this->assertResponseIsSuccessful();
$this->assertJsonContains(['totalItems' => 1]);
}
public function testOrSearchByNameOnPieces(): void
{
$this->createPiece('Joint torique', 'REF-JT-001');
$this->createPiece('Roulement', 'REF-RL-002');
$client = $this->createViewerClient();
$client->request('GET', '/api/pieces?q=joint');
$this->assertResponseIsSuccessful();
$this->assertJsonContains(['totalItems' => 1]);
}
public function testOrSearchByReferenceOnPieces(): void
{
$this->createPiece('Joint torique', 'REF-JT-001');
$this->createPiece('Roulement', 'REF-RL-002');
$client = $this->createViewerClient();
$client->request('GET', '/api/pieces?q=RL-002');
$this->assertResponseIsSuccessful();
$this->assertJsonContains(['totalItems' => 1]);
}
public function testOrSearchMatchesBothNameAndReference(): void
{
$this->createComposant('Pompe REF-X', 'REF-POMPE-01');
$this->createComposant('Vanne', 'REF-VANNE-01');
$this->createComposant('Moteur', 'POMPE-MOTEUR');
$client = $this->createViewerClient();
$client->request('GET', '/api/composants?q=pompe');
$this->assertResponseIsSuccessful();
$this->assertJsonContains(['totalItems' => 2]);
}
public function testOrSearchEmptyQueryReturnsAll(): void
{
$this->createProduct('Produit A', 'REF-A');
$this->createProduct('Produit B', 'REF-B');
$client = $this->createViewerClient();
$client->request('GET', '/api/products?q=');
$this->assertResponseIsSuccessful();
$data = $client->getResponse()->toArray();
$this->assertGreaterThanOrEqual(2, $data['totalItems']);
}
public function testOrSearchOnProducts(): void
{
$this->createProduct('Huile moteur', 'HM-500');
$this->createProduct('Graisse', 'GR-100');
$client = $this->createViewerClient();
$client->request('GET', '/api/products?q=HM-500');
$this->assertResponseIsSuccessful();
$this->assertJsonContains(['totalItems' => 1]);
}
}

View File

@@ -41,7 +41,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$this->createComposant('C1', $mt);
$this->createComposant('C1', null, $mt);
$result = $this->strategy->preview($mt, [
'pieces' => [['typePieceId' => $pieceType->getId(), 'position' => 0]],
@@ -58,7 +58,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$composant = $this->createComposant('C1', $mt);
$composant = $this->createComposant('C1', null, $mt);
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
$result = $this->strategy->preview($mt, [
@@ -75,7 +75,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$composant = $this->createComposant('C1', $mt);
$composant = $this->createComposant('C1', null, $mt);
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
$result = $this->strategy->preview($mt, [
@@ -92,7 +92,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$composant = $this->createComposant('C1', $mt);
$composant = $this->createComposant('C1', null, $mt);
$em = $this->getEntityManager();
$req = new SkeletonPieceRequirement();
@@ -115,7 +115,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$composant = $this->createComposant('C1', $mt);
$composant = $this->createComposant('C1', null, $mt);
$piece = $this->createPiece('P1', 'P1-REF', $pieceType);
$slot = $this->createComposantPieceSlot($composant, $pieceType, $piece, 5, 0);
@@ -142,7 +142,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$composant = $this->createComposant('C1', $mt);
$composant = $this->createComposant('C1', null, $mt);
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
// No skeleton requirements -> slot should be deleted
@@ -158,7 +158,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
{
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
$composant = $this->createComposant('C1', $mt);
$composant = $this->createComposant('C1', null, $mt);
$em = $this->getEntityManager();
$req = new SkeletonPieceRequirement();