feat: extend resolveGame() with slug fallback lookup
This commit is contained in:
@@ -32,12 +32,23 @@ async function resolveGame(id: string) {
|
||||
.limit(1)
|
||||
game = rows[0]
|
||||
} else {
|
||||
// Try UUID first
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(games)
|
||||
.where(eq(games.id, id))
|
||||
.limit(1)
|
||||
game = rows[0]
|
||||
|
||||
// Fallback: try slug lookup
|
||||
if (!game) {
|
||||
const slugRows = await db
|
||||
.select()
|
||||
.from(games)
|
||||
.where(eq(games.slug, id))
|
||||
.limit(1)
|
||||
game = slugRows[0]
|
||||
}
|
||||
}
|
||||
return game
|
||||
}
|
||||
@@ -245,6 +256,7 @@ export default async function GamePage({
|
||||
capsuleImage: game.capsuleImage,
|
||||
storeUrl: game.storeUrl,
|
||||
source: game.source,
|
||||
slug: game.slug,
|
||||
lastSync: game.lastSync ? game.lastSync.toISOString() : null,
|
||||
syncStatus: game.syncStatus,
|
||||
createdAt: game.createdAt.toISOString(),
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { generateSlug } from "@/lib/utils/slug"
|
||||
|
||||
describe("generateSlug", () => {
|
||||
it("converts a simple title to lowercase hyphenated slug", () => {
|
||||
expect(generateSlug("The Witcher 3")).toBe("the-witcher-3")
|
||||
})
|
||||
it("replaces special characters with hyphens", () => {
|
||||
expect(generateSlug("Hades II: The Sequel")).toBe("hades-ii-the-sequel")
|
||||
})
|
||||
it("collapses multiple consecutive hyphens", () => {
|
||||
expect(generateSlug("Game!!! -- Test")).toBe("game-test")
|
||||
})
|
||||
it("trims leading and trailing hyphens", () => {
|
||||
expect(generateSlug(" -- My Game -- ")).toBe("my-game")
|
||||
})
|
||||
it("truncates to 80 characters", () => {
|
||||
const longTitle = "A".repeat(100)
|
||||
expect(generateSlug(longTitle).length).toBeLessThanOrEqual(80)
|
||||
})
|
||||
it("does not leave trailing hyphen after truncation", () => {
|
||||
const title = "A".repeat(79) + " -"
|
||||
expect(generateSlug(title)).not.toMatch(/-$/)
|
||||
})
|
||||
it("handles empty string", () => {
|
||||
expect(generateSlug("")).toBe("")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user