Skip to content

Commit 160cde6

Browse files
Merge pull request #882 from 1nonlypiece/feat/audit-pagination-envelope
feat(audit): add pagination response envelope
2 parents e19fbc2 + 3236d80 commit 160cde6

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/__tests__/routes/audit.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("auditRouter", () => {
3232
.set("Origin", allowedOrigin);
3333

3434
expect(response.status).toBe(200);
35-
expect(response.body).toEqual({ events: [] });
35+
expect(response.body).toEqual({ items: [], next_cursor: null });
3636
});
3737

3838
it("accepts a valid limit query parameter", async () => {
@@ -41,7 +41,16 @@ describe("auditRouter", () => {
4141
.set("Origin", allowedOrigin);
4242

4343
expect(response.status).toBe(200);
44-
expect(response.body).toEqual({ events: [] });
44+
expect(response.body).toEqual({ items: [], next_cursor: null });
45+
46+
it("keeps the envelope stable when a cursor is provided", async () => {
47+
const response = await request(app)
48+
.get("/api/audit?limit=5&cursor=opaque-cursor")
49+
.set("Origin", allowedOrigin);
50+
51+
expect(response.status).toBe(200);
52+
expect(response.body).toEqual({ items: [], next_cursor: null });
53+
});
4554
});
4655

4756
it("returns 400 if limit is not a number", async () => {

src/routes/audit.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ auditRouter.use(accessLog);
2121
* - Audit
2222
* parameters:
2323
* - in: query
24+
* name: cursor
25+
* schema:
26+
* type: string
27+
* description: Opaque cursor for the next page
28+
* - in: query
2429
* name: limit
2530
* schema:
2631
* type: integer
@@ -30,16 +35,19 @@ auditRouter.use(accessLog);
3035
* description: Maximum number of events to return
3136
* responses:
3237
* 200:
33-
* description: A list of audit events
38+
* description: A cursor-paginated page of audit events
3439
* content:
3540
* application/json:
3641
* schema:
3742
* type: object
3843
* properties:
39-
* events:
44+
* items:
4045
* type: array
4146
* items:
4247
* type: object
48+
* next_cursor:
49+
* type: string
50+
* nullable: true
4351
* 400:
4452
* description: Invalid input
4553
* content:
@@ -56,6 +64,7 @@ auditRouter.get("/", (req, res) => {
5664
return;
5765
}
5866

59-
// Placeholder for real audit events
60-
res.json({ events: [] });
67+
// Placeholder for real audit events. Keep the pagination envelope stable
68+
// while the backing audit store is introduced.
69+
res.json({ items: [], next_cursor: null });
6170
});

0 commit comments

Comments
 (0)