test(torob): verify PostgreSQL feed regression and guard invalid pagination

This commit is contained in:
devops committed 2026-10-14 19:35:21 +00:00
1 parent d87885826c
commit 30cebb92fa
5 files changed
+108 -2

No files matched your search

@@ -140,6 +140,18 @@ describe("TorobController", () => {
expect(result.max_pages).toBe(1);
});
it.each([['garbage', 'garbage', 100], ['2', 'garbage', 100], ['garbage', '20', 20]])(
"defaults nonnumeric pagination safely (%s, %s)", async (page, size, take) => {
mockPrismaService.product.count.mockResolvedValue(0);
mockPrismaService.product.findMany.mockResolvedValue([]);
const result = await controller.getTorobProducts(page, size);
expect(mockPrismaService.product.findMany).toHaveBeenCalledWith(
expect.objectContaining({ skip: page === '2' ? 100 : 0, take }),
);
expect(result.max_pages).toBe(1);
},
);
it("should correctly mark out-of-stock products", async () => {
const mockOutOfStock = [
{
+4 -2
View File
@@ -141,10 +141,12 @@ export class TorobController {
@Query("page") pageQuery?: string,
@Query("page_size") pageSizeQuery?: string,
) {
const page = Math.max(1, parseInt(pageQuery || "1", 10));
const parsedPage = parseInt(pageQuery || "1", 10);
const parsedSize = parseInt(pageSizeQuery || "100", 10);
const page = Math.max(1, Number.isFinite(parsedPage) ? parsedPage : 1);
const pageSize = Math.min(
100,
Math.max(10, parseInt(pageSizeQuery || "100", 10)),
Math.max(10, Number.isFinite(parsedSize) ? parsedSize : 100),
);
const baseUrl = (process.env.FRONTEND_URL || "https://canina.ir").replace(
/\/$/,