fix(housekeeping): harden people read boundaries
This commit is contained in:
1 parent
e3f8b51d31
commit
d1382c839e
12 files changed
+1635
-446
No files matched your search
@@ -41,9 +41,12 @@ describe("People list normalization", () => {
|
||||
"id",
|
||||
),
|
||||
).toMatchObject({ pageSize: 20, offset: 0 });
|
||||
expect(
|
||||
normalizePeopleListInput({ offset: 999_999 }, ["id"], "id").offset,
|
||||
).toBe(10_000);
|
||||
});
|
||||
|
||||
it("sorts a page deterministically with an id tie breaker", () => {
|
||||
it("wraps rows already sorted and paged by the adapter", () => {
|
||||
const input = normalizePeopleListInput(
|
||||
{ pageSize: 2, offset: 1, sort: "username", order: "asc" },
|
||||
["id", "username"],
|
||||
@@ -51,20 +54,17 @@ describe("People list normalization", () => {
|
||||
);
|
||||
const page = createPeoplePage(
|
||||
[
|
||||
{ id: 4, username: "Bob" },
|
||||
{ id: 3, username: "alice" },
|
||||
{ id: 1, username: "Alice" },
|
||||
{ id: 2, username: "alice" },
|
||||
],
|
||||
4,
|
||||
input,
|
||||
(row) => row.username,
|
||||
);
|
||||
|
||||
expect(page).toEqual({
|
||||
items: [
|
||||
{ id: 2, username: "alice" },
|
||||
{ id: 3, username: "alice" },
|
||||
{ id: 1, username: "Alice" },
|
||||
],
|
||||
total: 4,
|
||||
pageSize: 2,
|
||||
@@ -116,6 +116,11 @@ describe("People canonical models", () => {
|
||||
accountCreated: toPeopleIsoDate(new Date("2026-08-29T10:20:30.000Z")),
|
||||
lastLogin: toPeopleIsoDate(1_700_000_000),
|
||||
sanctions: [],
|
||||
watched: false,
|
||||
permission: {
|
||||
rankName: "Moderator",
|
||||
ranks: [{ id: 5, name: "Moderator" }],
|
||||
},
|
||||
};
|
||||
|
||||
expect(JSON.parse(JSON.stringify(detail))).toEqual({
|
||||
@@ -132,6 +137,11 @@ describe("People canonical models", () => {
|
||||
accountCreated: "2026-08-29T10:20:30.000Z",
|
||||
lastLogin: "2023-11-14T22:13:20.000Z",
|
||||
sanctions: [],
|
||||
watched: false,
|
||||
permission: {
|
||||
rankName: "Moderator",
|
||||
ranks: [{ id: 5, name: "Moderator" }],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -150,4 +160,16 @@ describe("People canonical models", () => {
|
||||
"/ase/people/moderation/cfh/8",
|
||||
]);
|
||||
});
|
||||
|
||||
it("rejects corrupt identifiers and non-serializable date values", () => {
|
||||
expect(() =>
|
||||
normalizePeopleUser(
|
||||
{ ...rawUser, id: 0 },
|
||||
{ includeMail: false, includeIp: false },
|
||||
),
|
||||
).toThrow();
|
||||
expect(() => peopleUserHref(Number.MAX_SAFE_INTEGER + 1)).toThrow();
|
||||
expect(() => peopleGuildHref(-4)).toThrow();
|
||||
expect(() => toPeopleIsoDate("not-a-date")).toThrow();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user