test(i18n): add translated page CRUD locale validation coverage
This commit is contained in:
@@ -7,6 +7,11 @@ const { mockDb } = vi.hoisted(() => ({
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
findUnique: vi.fn(),
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
pageTranslation: {
|
||||
upsert: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
navigationMenu: {
|
||||
@@ -30,8 +35,10 @@ import {
|
||||
createNavigationItem,
|
||||
createNavigationMenu,
|
||||
createPage,
|
||||
getPublishedPageBySlugForLocale,
|
||||
listPublicNavigation,
|
||||
updatePage,
|
||||
upsertPageTranslation,
|
||||
} from "./pages-navigation"
|
||||
|
||||
describe("pages-navigation service", () => {
|
||||
@@ -120,4 +127,63 @@ describe("pages-navigation service", () => {
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("validates locale when upserting page translation", async () => {
|
||||
await expect(() =>
|
||||
upsertPageTranslation({
|
||||
pageId: "550e8400-e29b-41d4-a716-446655440000",
|
||||
locale: "it",
|
||||
title: "Titolo",
|
||||
content: "Contenuto",
|
||||
}),
|
||||
).rejects.toThrow()
|
||||
})
|
||||
|
||||
it("upserts page translation and reads localized page with fallback", async () => {
|
||||
mockDb.pageTranslation.upsert.mockResolvedValue({ id: "pt-1" })
|
||||
mockDb.page.findFirst
|
||||
.mockResolvedValueOnce({
|
||||
id: "page-1",
|
||||
title: "About",
|
||||
summary: "Base summary",
|
||||
content: "Base content",
|
||||
seoTitle: "Base SEO",
|
||||
seoDescription: "Base description",
|
||||
translations: [
|
||||
{
|
||||
locale: "de",
|
||||
title: "Uber Uns",
|
||||
summary: "Zusammenfassung",
|
||||
content: "Inhalt",
|
||||
seoTitle: "SEO DE",
|
||||
seoDescription: "Beschreibung",
|
||||
},
|
||||
],
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
id: "page-1",
|
||||
title: "About",
|
||||
summary: "Base summary",
|
||||
content: "Base content",
|
||||
seoTitle: "Base SEO",
|
||||
seoDescription: "Base description",
|
||||
translations: [],
|
||||
})
|
||||
|
||||
await upsertPageTranslation({
|
||||
pageId: "550e8400-e29b-41d4-a716-446655440000",
|
||||
locale: "de",
|
||||
title: "Uber Uns",
|
||||
content: "Inhalt",
|
||||
})
|
||||
|
||||
const translated = await getPublishedPageBySlugForLocale("about", "de")
|
||||
const fallback = await getPublishedPageBySlugForLocale("about", "fr")
|
||||
|
||||
expect(mockDb.pageTranslation.upsert).toHaveBeenCalledTimes(1)
|
||||
expect(translated?.title).toBe("Uber Uns")
|
||||
expect(translated?.content).toBe("Inhalt")
|
||||
expect(fallback?.title).toBe("About")
|
||||
expect(fallback?.content).toBe("Base content")
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user