test: add unit tests for parseId helper
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
37
tests/lib/params.test.ts
Normal file
37
tests/lib/params.test.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { parseId } from "../../src/server/lib/params";
|
||||
|
||||
describe("parseId", () => {
|
||||
it("returns number for valid positive integers", () => {
|
||||
expect(parseId("1")).toBe(1);
|
||||
expect(parseId("42")).toBe(42);
|
||||
expect(parseId("999")).toBe(999);
|
||||
});
|
||||
|
||||
it("returns null for zero", () => {
|
||||
expect(parseId("0")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for negative numbers", () => {
|
||||
expect(parseId("-1")).toBeNull();
|
||||
expect(parseId("-100")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for decimals", () => {
|
||||
expect(parseId("1.5")).toBeNull();
|
||||
expect(parseId("3.14")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for non-numeric strings", () => {
|
||||
expect(parseId("abc")).toBeNull();
|
||||
expect(parseId("")).toBeNull();
|
||||
expect(parseId("hello")).toBeNull();
|
||||
expect(parseId("12abc")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for special values", () => {
|
||||
expect(parseId("NaN")).toBeNull();
|
||||
expect(parseId("Infinity")).toBeNull();
|
||||
expect(parseId("-Infinity")).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user