fix: update db import validation tests to account for reverse links
- Translation count test now adds reverse link count to expected total - Non-English translations test now filters to kaikki source only - Target language test now filters to kaikki source only — reverse links to English are valid and expected
This commit is contained in:
parent
1c44ef989b
commit
76af2ab093
1 changed files with 16 additions and 8 deletions
|
|
@ -100,12 +100,17 @@ describe("pipeline.db — import validation", () => {
|
|||
expect(errors, `\n${errors.join("\n")}`).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("translation count matches source files", () => {
|
||||
it("translation count matches source files plus reverse links", () => {
|
||||
if (!db) return;
|
||||
const row = db
|
||||
.prepare("SELECT COUNT(*) as count FROM translations")
|
||||
.get() as { count: number };
|
||||
expect(row.count).toBe(expectedTotalTranslations);
|
||||
const reverseLinks = db
|
||||
.prepare(
|
||||
"SELECT COUNT(*) as count FROM translations WHERE source = 'reverse_link'",
|
||||
)
|
||||
.get() as { count: number };
|
||||
expect(row.count).toBe(expectedTotalTranslations + reverseLinks.count);
|
||||
});
|
||||
|
||||
it("every translation references a valid entry", () => {
|
||||
|
|
@ -180,7 +185,7 @@ describe("pipeline.db — import validation", () => {
|
|||
expect(errors, `\n${errors.join("\n")}`).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("non-English entries have no translations", () => {
|
||||
it("non-English entries have no Kaikki translations", () => {
|
||||
if (!db) return;
|
||||
const nonEnLangs = SUPPORTED_LANGUAGE_CODES.filter((l) => l !== "en")
|
||||
.map((l) => `'${l}'`)
|
||||
|
|
@ -192,25 +197,28 @@ describe("pipeline.db — import validation", () => {
|
|||
FROM entries e
|
||||
JOIN translations t ON t.entry_id = e.id
|
||||
WHERE e.language IN (${nonEnLangs})
|
||||
AND t.source = 'kaikki'
|
||||
GROUP BY e.id`,
|
||||
)
|
||||
.all() as { headword: string; language: string; c: number }[];
|
||||
|
||||
const errors = rows.map(
|
||||
(r) => `"${r.headword}" (${r.language}): unexpected ${r.c} translations`,
|
||||
(r) =>
|
||||
`"${r.headword}" (${r.language}): unexpected ${r.c} Kaikki translations`,
|
||||
);
|
||||
expect(errors, `\n${errors.join("\n")}`).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("all translation target languages are supported and not English", () => {
|
||||
it("all Kaikki translation target languages are supported and not English", () => {
|
||||
if (!db) return;
|
||||
const validLangs = SUPPORTED_LANGUAGE_CODES.map((l) => `'${l}'`).join(", ");
|
||||
|
||||
const rows = db
|
||||
.prepare(
|
||||
`SELECT id, target_lang FROM translations
|
||||
WHERE target_lang NOT IN (${validLangs})
|
||||
OR target_lang = 'en'`,
|
||||
`SELECT t.id, t.target_lang
|
||||
FROM translations t
|
||||
WHERE t.source = 'kaikki'
|
||||
AND (t.target_lang NOT IN (${validLangs}) OR t.target_lang = 'en')`,
|
||||
)
|
||||
.all() as { id: number; target_lang: string }[];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue