Skip to content

Commit

Permalink
Fix limit <= 0 and add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0237h committed Apr 19, 2024
1 parent e30f6b1 commit 563e2ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { parseBlockId, parseTimestamp } from "./utils.js";
import { parseBlockId, parseLimit, parseTimestamp } from "./utils.js";
import { config } from "./config.js";

test("parseBlockId", () => {
expect(parseBlockId("0x123") as string).toBe("123");
Expand All @@ -11,3 +12,10 @@ test("parseTimestamp", () => {
expect(parseTimestamp("awdawd")).toBeNaN();
expect(parseTimestamp(null)).toBeUndefined();
});

test("parseLimit", () => {
expect(parseLimit("1")).toBe(1);
expect(parseLimit("0")).toBe(1);
expect(parseLimit(10)).toBe(10);
expect(parseLimit(config.maxLimit + 1)).toBe(config.maxLimit);
});
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function parseLimit(limit?: string | null | number, defaultLimit?: number
if (typeof limit === "number") value = limit;
}
// limit must be between 1 and maxLimit
if (value <= 0) value = 1;
if (value > config.maxLimit) value = config.maxLimit;
return value;
}
Expand Down

0 comments on commit 563e2ba

Please sign in to comment.