-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Replace OpenLibrary autocomplete with Google Books search for b… #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8fa1e43
9121e3e
6fad924
3ea9e22
ca9c0c7
837a03f
ed2a523
618d29c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ node_modules/ | |
| .backups/ | ||
| *.code-workspace | ||
| .eslintrc.json | ||
| next-env.d.ts | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { parseBookMetadata } from "@/lib/book-utils" | ||
| import { BookMetadata } from "@/lib/types" | ||
|
|
||
| describe("parseBookMetadata", () => { | ||
| it("should parse Google Books data correctly", () => { | ||
| const googleBook: BookMetadata = { | ||
| title: "Google Book Title", | ||
| authors: ["Author One", "Author Two"], | ||
| coverUrl: "http://example.com/cover.jpg", | ||
| isbn: "1234567890", | ||
| googleId: "g1", | ||
| } | ||
|
|
||
| const result = parseBookMetadata(googleBook) | ||
|
|
||
| expect(result).toEqual({ | ||
| title: "Google Book Title", | ||
| author: "Author One, Author Two", | ||
| cover_url: "http://example.com/cover.jpg", | ||
| isbn: "1234567890", | ||
| }) | ||
| }) | ||
|
|
||
| it("should parse OpenLibrary data correctly", () => { | ||
| const olBook: BookMetadata = { | ||
| title: "OL Book Title", | ||
| author_name: ["OL Author"], | ||
| cover_edition_key: "OL123M", | ||
| isbn: ["0987654321"], | ||
| key: "/works/OL123W", | ||
| // Force type to satisfy simplified mock if needed, but the structure matches | ||
| edition_key: ["OL123M"], | ||
| publish_year: [2021], | ||
| } as any // Cast as any because OpenLibraryDoc has many required fields | ||
|
|
||
| const result = parseBookMetadata(olBook) | ||
|
|
||
| expect(result).toEqual({ | ||
| title: "OL Book Title", | ||
| author: "OL Author", | ||
| cover_url: "https://covers.openlibrary.org/b/olid/OL123M-M.jpg", // Expecting getBookCover logic | ||
| isbn: "0987654321", | ||
| }) | ||
| }) | ||
|
|
||
| it("should handle missing optional fields gracefully", () => { | ||
| const minimalBook: BookMetadata = { | ||
| title: "Minimal Book", | ||
| } as any | ||
|
|
||
| const result = parseBookMetadata(minimalBook) | ||
|
|
||
| expect(result).toEqual({ | ||
| title: "Minimal Book", | ||
| author: "Unknown Author", | ||
| cover_url: null, | ||
| isbn: null, | ||
| }) | ||
| }) | ||
|
|
||
| it("should return defaults for null input", () => { | ||
| const result = parseBookMetadata(null as any) | ||
| expect(result).toEqual({ | ||
| title: "Unknown Title", | ||
| author: "Unknown Author", | ||
| cover_url: null, | ||
| isbn: null, | ||
| }) | ||
| }) | ||
| }) | ||
|
Comment on lines
+1
to
+70
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -4,7 +4,9 @@ import { generateBookId } from "@/lib/id_generator" | |||
| import { createRouteHandlerClient } from "@supabase/auth-helpers-nextjs" | ||||
| import { cookies } from "next/headers" | ||||
| import { createClient } from "@supabase/supabase-js" | ||||
| import { parseBookMetadata } from "@/lib/book-utils" | ||||
| import { OpenLibraryDoc, getBookCover } from "@/lib/openLibrary" | ||||
|
||||
| import { OpenLibraryDoc, getBookCover } from "@/lib/openLibrary" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OpenLibraryDoc type definition has all fields marked as required, but the test mock casts to
anybecause some fields (likekey,edition_key,publish_year) are not part of the actual type definition. This indicates a mismatch between the actual OpenLibrary API response structure and the type definition. Consider making optional fields in OpenLibraryDoc optional (e.g.,cover_edition_key?,isbn?) to better reflect the actual data structure and avoid the need for unsafe type casts.