feat: switch sitemap from static file to dynamic DB-driven generation
This commit is contained in:
@@ -1,18 +1,32 @@
|
||||
import { describe, it, expect, vi } from "vitest"
|
||||
|
||||
// Helper to build a chainable mock that returns []
|
||||
function chainableMock() {
|
||||
const mock = {
|
||||
where: vi.fn().mockReturnThis(),
|
||||
limit: vi.fn().mockReturnThis(),
|
||||
offset: vi.fn().mockResolvedValue([]),
|
||||
}
|
||||
return mock
|
||||
}
|
||||
|
||||
// Mock database to prevent real queries
|
||||
vi.mock("@/lib/db/index", () => ({
|
||||
db: {
|
||||
select: vi.fn().mockReturnValue({
|
||||
from: vi.fn().mockReturnValue({
|
||||
where: vi.fn().mockResolvedValue([]),
|
||||
}),
|
||||
}),
|
||||
select: vi.fn(() => ({
|
||||
from: vi.fn(() => chainableMock()),
|
||||
})),
|
||||
$count: vi.fn().mockResolvedValue(0),
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock("@/lib/db/schema", () => ({
|
||||
games: { id: "id", updatedAt: "updatedAt", capsuleImage: "capsuleImage", syncStatus: "syncStatus" },
|
||||
games: {
|
||||
id: "id",
|
||||
updatedAt: "updatedAt",
|
||||
capsuleImage: "capsuleImage",
|
||||
syncStatus: "syncStatus",
|
||||
},
|
||||
hardware: { slug: "slug", createdAt: "createdAt" },
|
||||
}))
|
||||
|
||||
@@ -23,9 +37,19 @@ vi.mock("drizzle-orm", () => ({
|
||||
}))
|
||||
|
||||
describe("Sitemap Generator", () => {
|
||||
it("default export returns empty array (static sitemap is in public/)", async () => {
|
||||
it("generateSitemaps returns a single sitemap id when no data", async () => {
|
||||
const mod = await import("@/app/sitemap")
|
||||
const result = mod.default()
|
||||
expect(result).toEqual([])
|
||||
const sitemaps = await mod.generateSitemaps()
|
||||
expect(sitemaps).toEqual([{ id: "0" }])
|
||||
})
|
||||
})
|
||||
|
||||
it("default export returns static pages in first chunk", async () => {
|
||||
const mod = await import("@/app/sitemap")
|
||||
const result = await mod.default({ id: "0" })
|
||||
expect(Array.isArray(result)).toBe(true)
|
||||
// Static pages: /, /games, /dashboard, /devices, /updates, /contact
|
||||
expect(result.length).toBeGreaterThanOrEqual(6)
|
||||
expect(result[0].url).toContain("deckyvault.xyz")
|
||||
expect(result[0].priority).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user