This commit is contained in:
Your Name committed 2026-07-24 21:45:44 -04:00
1 parent f8da2cceaf
commit 63bc3bfb1a
6 files changed
+658 -2

No files matched your search

+126
View File
@@ -270,4 +270,130 @@ describe("Page Builder block contracts", () => {
],
});
});
test("get_page_section_translation requests one language with source fallback", async () => {
const calls: string[] = [];
const api = {
get: async (url: string) => {
calls.push(url);
return {
data: {
id: 41,
type: "ARTICLE_REFERENCES",
payload: {
title: "参考资料",
items: [{ title: "精密冲裁技术", note: null, url: "https://example.com" }],
},
locale: {
lang: "zh",
fallback: true,
missingPaths: [],
fallbackPaths: ["items[0].note"],
},
updatedAt: "2026-07-24T10:00:00.000Z",
},
};
},
} as any;
const result = await handleSectionTool(api, "get_page_section_translation", {
sectionId: 41,
lang: "zh",
});
const response = JSON.parse(result?.content[0]?.text ?? "{}");
expect(calls).toEqual([
"/pages/sections/41?lang=zh&view=resolved&fallback=true",
]);
expect(response).toEqual({
sectionId: 41,
sectionType: "ARTICLE_REFERENCES",
lang: "zh",
payload: {
title: "参考资料",
items: [{ title: "精密冲裁技术", note: null, url: "https://example.com" }],
},
missingPaths: [],
fallbackPaths: ["items[0].note"],
updatedAt: "2026-07-24T10:00:00.000Z",
});
});
test("update_section_translation sends only translation fields and version", async () => {
const calls: Array<{ url: string; payload: unknown }> = [];
const api = {
patch: async (url: string, payload: unknown) => {
calls.push({ url, payload });
return {
data: {
success: true,
sectionId: 41,
sectionType: "ARTICLE_REFERENCES",
lang: "zh",
translatedPaths: ["title", "items[0].title"],
preservedOtherLanguages: true,
updatedAt: "2026-07-24T10:01:00.000Z",
},
};
},
} as any;
const translations = {
title: "参考资料",
items: [{ title: "精密冲裁技术" }],
};
const result = await handleSectionTool(api, "update_section_translation", {
sectionId: 41,
lang: "zh",
translations,
expectedUpdatedAt: "2026-07-24T10:00:00.000Z",
});
const response = JSON.parse(result?.content[0]?.text ?? "{}");
expect(calls).toEqual([{
url: "/pages/sections/41/translations/zh",
payload: {
translations,
expectedUpdatedAt: "2026-07-24T10:00:00.000Z",
},
}]);
expect(response.preservedOtherLanguages).toBe(true);
expect(response.translatedPaths).toEqual(["title", "items[0].title"]);
});
test("get_page_translation_status requests a compact language audit", async () => {
const calls: string[] = [];
const api = {
get: async (url: string) => {
calls.push(url);
return {
data: {
success: true,
pageId: 15,
lang: "zh",
complete: false,
translatedSections: 8,
totalSections: 9,
missingSections: [{
sectionId: 41,
type: "ARTICLE_REFERENCES",
order: 9,
complete: false,
missingPaths: ["items[0].note"],
}],
},
};
},
} as any;
const result = await handleSectionTool(api, "get_page_translation_status", {
pageId: 15,
lang: "zh",
});
const response = JSON.parse(result?.content[0]?.text ?? "{}");
expect(calls).toEqual(["/pages/translation-status/15?lang=zh"]);
expect(response.totalSections).toBe(9);
expect(response.missingSections[0].sectionId).toBe(41);
});
});