|
|
@@ -54,6 +54,45 @@ final class AuditLogControllerTest extends AppTestCase
|
|
|
self::assertSame('manual_block', $body['items'][0]['entity_type']);
|
|
|
}
|
|
|
|
|
|
+ public function testSubjectFilterUnionsActorAndTarget(): void
|
|
|
+ {
|
|
|
+ $now = (new \DateTimeImmutable('now', new \DateTimeZone('UTC')))->format('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ // (1) admin updated reporter #5 — target=reporter, actor=user
|
|
|
+ $this->seedAudit('user', '1', 'reporter.updated', 'reporter', '5', '{}', $now);
|
|
|
+ // (2) reporter #5 emitted a report.received — actor=reporter, target=report
|
|
|
+ $this->seedAudit('reporter', '5', 'report.received', 'report', '99', '{}', $now);
|
|
|
+ // (3) different reporter — must NOT appear in subject_kind=reporter,subject_id=5
|
|
|
+ $this->seedAudit('reporter', '6', 'report.received', 'report', '100', '{}', $now);
|
|
|
+ // (4) unrelated row — must NOT appear
|
|
|
+ $this->seedAudit('user', '1', 'manual_block.created', 'manual_block', '7', '{}', $now);
|
|
|
+
|
|
|
+ $token = $this->createToken(TokenKind::Admin, Role::Viewer);
|
|
|
+ $resp = $this->request(
|
|
|
+ 'GET',
|
|
|
+ '/api/v1/admin/audit-log?subject_kind=reporter&subject_id=5',
|
|
|
+ ['Authorization' => 'Bearer ' . $token],
|
|
|
+ );
|
|
|
+ $body = $this->decode($resp);
|
|
|
+ self::assertSame(2, $body['total']);
|
|
|
+ $actions = array_map(static fn (array $r): string => $r['action'], $body['items']);
|
|
|
+ self::assertContains('reporter.updated', $actions);
|
|
|
+ self::assertContains('report.received', $actions);
|
|
|
+ self::assertNotContains('manual_block.created', $actions);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testSubjectKindWithoutIdReturns400(): void
|
|
|
+ {
|
|
|
+ $token = $this->createToken(TokenKind::Admin, Role::Viewer);
|
|
|
+ $resp = $this->request(
|
|
|
+ 'GET',
|
|
|
+ '/api/v1/admin/audit-log?subject_kind=reporter',
|
|
|
+ ['Authorization' => 'Bearer ' . $token],
|
|
|
+ );
|
|
|
+ self::assertSame(400, $resp->getStatusCode());
|
|
|
+ self::assertArrayHasKey('subject', $this->decode($resp)['details']);
|
|
|
+ }
|
|
|
+
|
|
|
public function testInvalidActorKindReturns400(): void
|
|
|
{
|
|
|
$token = $this->createToken(TokenKind::Admin, Role::Viewer);
|