Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/nperez0111/bookhive. Track your books, share your shelves, see what others are reading bookhive.buzz
atproto bluesky books bookshelf goodreads management-system
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import { describe, it, expect } from "bun:test";import { normalizeGoodreadsId, deriveBookIdentifiers } from "./bookIdentifiers";
describe("normalizeGoodreadsId", () => { it("returns numeric Goodreads IDs", () => { expect(normalizeGoodreadsId("12345")).toBe("12345"); expect(normalizeGoodreadsId("18143945")).toBe("18143945"); });
it("extracts numeric part from ID.title-slug format", () => { expect(normalizeGoodreadsId("12345.my-book-title")).toBe("12345"); });
it("rejects Amazon/Kindle identifiers", () => { expect(normalizeGoodreadsId("kca://book/amzn1")).toBe(null); expect(normalizeGoodreadsId("amzn1.book.123")).toBe(null); });
it("returns null for empty or invalid input", () => { expect(normalizeGoodreadsId("")).toBe(null); expect(normalizeGoodreadsId(null)).toBe(null); expect(normalizeGoodreadsId(undefined)).toBe(null); expect(normalizeGoodreadsId(" ")).toBe(null); });});
describe("deriveBookIdentifiers", () => { it("extracts goodreadsId from sourceId when source is Goodreads", () => { const result = deriveBookIdentifiers({ id: "bk_test", source: "Goodreads", sourceId: "12345", sourceUrl: "https://www.goodreads.com/book/show/12345", meta: null, }); expect(result.goodreadsId).toBe("12345"); });
it("rejects invalid goodreadsId from sourceId", () => { const result = deriveBookIdentifiers({ id: "bk_test", source: "Goodreads", sourceId: "kca://book/amzn1", sourceUrl: "https://www.goodreads.com/book/show/kca://book/amzn1", meta: null, }); expect(result.goodreadsId).toBe(null); });
it("falls back to sourceUrl when sourceId is invalid", () => { const result = deriveBookIdentifiers({ id: "bk_test", source: "Goodreads", sourceId: "kca://book/amzn1", sourceUrl: "https://www.goodreads.com/book/show/12345-my-book", meta: null, }); expect(result.goodreadsId).toBe("12345"); });});