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:
Matthieu
2026-03-23 15:20:39 +01:00
parent 8d920d5f65
commit 5ec6e49af2
3 changed files with 58 additions and 0 deletions

View File

@@ -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();