createMachine('Machine A'); $client = $this->createViewerClient(); $client->request('POST', '/api/comments', [ 'json' => [ 'content' => 'Test comment', 'entityType' => 'machine', 'entityId' => $machine->getId(), 'entityName' => 'Machine A', ], ]); $this->assertResponseStatusCodeSame(201); $this->assertJsonContains([ 'content' => 'Test comment', 'entityType' => 'machine', 'status' => 'open', ]); } public function testCreateCommentUnauthenticated(): void { $client = $this->createUnauthenticatedClient(); $client->request('POST', '/api/comments', [ 'json' => [ 'content' => 'No auth', 'entityType' => 'machine', 'entityId' => 'fake-id', ], ]); $this->assertResponseStatusCodeSame(401); } public function testCreateCommentEmptyContent(): void { $client = $this->createViewerClient(); $client->request('POST', '/api/comments', [ 'json' => [ 'content' => '', 'entityType' => 'machine', 'entityId' => 'some-id', ], ]); $this->assertResponseStatusCodeSame(400); $this->assertJsonContains(['message' => 'Le contenu est requis.']); } public function testCreateCommentInvalidEntityType(): void { $client = $this->createViewerClient(); $client->request('POST', '/api/comments', [ 'json' => [ 'content' => 'Invalid type', 'entityType' => 'invalid', 'entityId' => 'some-id', ], ]); $this->assertResponseStatusCodeSame(400); $this->assertJsonContains(['message' => "Type d'entité invalide."]); } public function testCreateCommentMissingEntityId(): void { $client = $this->createViewerClient(); $client->request('POST', '/api/comments', [ 'json' => [ 'content' => 'Missing ID', 'entityType' => 'machine', 'entityId' => '', ], ]); $this->assertResponseStatusCodeSame(400); } public function testResolveComment(): void { $machine = $this->createMachine('Machine A'); $viewerClient = $this->createViewerClient(); $response = $viewerClient->request('POST', '/api/comments', [ 'json' => [ 'content' => 'To resolve', 'entityType' => 'machine', 'entityId' => $machine->getId(), ], ]); $data = $response->toArray(); $commentId = $data['id']; $gestionnaireClient = $this->createGestionnaireClient(); $gestionnaireClient->request('PATCH', sprintf('/api/comments/%s/resolve', $commentId)); $this->assertResponseIsSuccessful(); $this->assertJsonContains(['status' => 'resolved']); } public function testResolveCommentNotFound(): void { $client = $this->createGestionnaireClient(); $client->request('PATCH', '/api/comments/nonexistent-id/resolve'); $this->assertResponseStatusCodeSame(404); } public function testUnresolvedCount(): void { $machine = $this->createMachine('Machine A'); $client = $this->createViewerClient(); $client->request('POST', '/api/comments', [ 'json' => [ 'content' => 'Open 1', 'entityType' => 'machine', 'entityId' => $machine->getId(), ], ]); $client->request('POST', '/api/comments', [ 'json' => [ 'content' => 'Open 2', 'entityType' => 'machine', 'entityId' => $machine->getId(), ], ]); $client->request('GET', '/api/comments/stats/unresolved-count'); $this->assertResponseIsSuccessful(); $this->assertJsonContains(['count' => 2]); } }