Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

test: add coverage for getDbPostId util (#5980)

authored by yoginth.com and committed by

GitHub b8398dab faad8d80

+26
+26
apps/api/src/utils/getDbPostId.test.ts
··· 1 + import { describe, expect, it } from "vitest"; 2 + import getDbPostId from "./getDbPostId"; 3 + 4 + describe("getDbPostId", () => { 5 + it("converts decimal string to hex with prefix", () => { 6 + const result = getDbPostId("1234567890"); 7 + expect(result).toBe("\\x499602d2"); 8 + }); 9 + 10 + it("returns empty string when input is empty", () => { 11 + expect(getDbPostId("")).toBe(""); 12 + }); 13 + 14 + it("throws error for non digit strings", () => { 15 + expect(() => getDbPostId("abc123")).toThrow("Invalid decimal value"); 16 + }); 17 + 18 + it("throws error for negative numbers", () => { 19 + expect(() => getDbPostId("-1")).toThrow("Invalid decimal value"); 20 + }); 21 + 22 + it("handles large numbers", () => { 23 + const large = "18446744073709551615"; 24 + expect(getDbPostId(large)).toBe("\\xffffffffffffffff"); 25 + }); 26 + });