Fix SMS, and added pagination+sorting+searching for GETs

This commit is contained in:
SepehrYahyaee
2026-05-20 14:57:10 +03:30
parent e4dfe7c572
commit 44723259d6
18 changed files with 519 additions and 30 deletions

View File

@@ -0,0 +1,51 @@
import { applyListQueryV2 } from "./list-query-v2";
describe("applyListQueryV2", () => {
const rows = [
{ publicId: "B100", createdAt: "2026-01-01", status: "OPEN" },
{ publicId: "A200", createdAt: "2026-02-01", status: "DONE" },
{ publicId: "C050", createdAt: "2026-03-01", status: "OPEN" },
];
const getters = {
publicId: (r: (typeof rows)[0]) => r.publicId,
createdAt: (r: (typeof rows)[0]) => r.createdAt,
status: (r: (typeof rows)[0]) => r.status,
};
it("returns all rows when no pagination query", () => {
const r = applyListQueryV2(rows, getters, {});
expect(r.total).toBe(3);
expect(r.list).toHaveLength(3);
expect(r.page).toBeUndefined();
});
it("filters by search on publicId", () => {
const r = applyListQueryV2(rows, getters, { search: "a200" });
expect(r.total).toBe(1);
expect(r.list[0].publicId).toBe("A200");
});
it("sorts by publicId ascending", () => {
const r = applyListQueryV2(rows, getters, {
sortBy: "publicId",
sortOrder: "asc",
});
expect(r.list.map((x) => x.publicId)).toEqual(["A200", "B100", "C050"]);
});
it("paginates when page and limit are set", () => {
const r = applyListQueryV2(rows, getters, {
sortBy: "publicId",
sortOrder: "asc",
page: 2,
limit: 1,
});
expect(r.total).toBe(3);
expect(r.list).toHaveLength(1);
expect(r.list[0].publicId).toBe("B100");
expect(r.page).toBe(2);
expect(r.limit).toBe(1);
expect(r.totalPages).toBe(3);
});
});