feat(documents) : accept type on upload + expose in query controller + PATCH tests
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -121,6 +121,7 @@ class DocumentQueryController extends AbstractController
|
||||
'composantId' => $document->getComposant()?->getId(),
|
||||
'pieceId' => $document->getPiece()?->getId(),
|
||||
'productId' => $document->getProduct()?->getId(),
|
||||
'type' => $document->getType()->value,
|
||||
'createdAt' => $document->getCreatedAt()->format(DATE_ATOM),
|
||||
'updatedAt' => $document->getUpdatedAt()->format(DATE_ATOM),
|
||||
];
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\State;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Entity\Document;
|
||||
use App\Enum\DocumentType;
|
||||
use App\Service\DocumentStorageService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
@@ -76,6 +77,10 @@ final class DocumentUploadProcessor implements ProcessorInterface
|
||||
$document->setMimeType($mimeType);
|
||||
$document->setSize((int) $size);
|
||||
|
||||
$typeValue = $request->request->get('type', 'documentation');
|
||||
$docType = DocumentType::tryFrom($typeValue) ?? DocumentType::DOCUMENTATION;
|
||||
$document->setType($docType);
|
||||
|
||||
// Handle entity relations from form fields
|
||||
$this->setRelationsFromRequest($document, $request);
|
||||
|
||||
|
||||
@@ -114,6 +114,58 @@ class DocumentTest extends AbstractApiTestCase
|
||||
$this->assertJsonContains(['totalItems' => 1]);
|
||||
}
|
||||
|
||||
public function testPatchType(): void
|
||||
{
|
||||
$doc = $this->createDocumentInDb();
|
||||
|
||||
$client = $this->createGestionnaireClient();
|
||||
$client->request('PATCH', self::iri('documents', $doc->getId()), [
|
||||
'headers' => ['Content-Type' => 'application/merge-patch+json'],
|
||||
'json' => ['type' => 'devis'],
|
||||
]);
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertJsonContains(['type' => 'devis']);
|
||||
}
|
||||
|
||||
public function testPatchNameAndType(): void
|
||||
{
|
||||
$doc = $this->createDocumentInDb();
|
||||
|
||||
$client = $this->createGestionnaireClient();
|
||||
$client->request('PATCH', self::iri('documents', $doc->getId()), [
|
||||
'headers' => ['Content-Type' => 'application/merge-patch+json'],
|
||||
'json' => ['name' => 'new-name', 'type' => 'facture'],
|
||||
]);
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertJsonContains(['name' => 'new-name', 'type' => 'facture']);
|
||||
}
|
||||
|
||||
public function testGetItemIncludesType(): void
|
||||
{
|
||||
$doc = $this->createDocumentInDb();
|
||||
|
||||
$client = $this->createViewerClient();
|
||||
$client->request('GET', self::iri('documents', $doc->getId()));
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertJsonContains(['type' => 'documentation']);
|
||||
}
|
||||
|
||||
public function testViewerCannotPatch(): void
|
||||
{
|
||||
$doc = $this->createDocumentInDb();
|
||||
|
||||
$client = $this->createViewerClient();
|
||||
$client->request('PATCH', self::iri('documents', $doc->getId()), [
|
||||
'headers' => ['Content-Type' => 'application/merge-patch+json'],
|
||||
'json' => ['type' => 'devis'],
|
||||
]);
|
||||
|
||||
$this->assertResponseStatusCodeSame(403);
|
||||
}
|
||||
|
||||
private function createDocumentInDb(?string $machineId = null, ?string $siteId = null): Document
|
||||
{
|
||||
$doc = new Document();
|
||||
|
||||
Reference in New Issue
Block a user