src/content/translations/en.json is a reviewable hu -> en memory built from the live staging content (179 texts). Tests guard every entry: placeholders, HTML, legal markup and e-mail/URL literals must survive. fillEnglishDraft() fills only empty English values whose Hungarian text exactly matches a memory key (lists all-or-nothing) and moves the page status none -> ai-draft; it never sets "approved" or overwrites English. The 20260929_en_ai_draft migration applies it to every global and legal page (published doc + latest version), reports untranslated texts, and wraps legacy values first so it does not depend on migration order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
3.1 KiB
TypeScript
67 lines
3.1 KiB
TypeScript
import { up } from '../migrations/20260929_en_ai_draft'
|
|
import { fakeArgs, fakeCollection } from './helpers/fake-mongo'
|
|
|
|
type Doc = Record<string, unknown>
|
|
|
|
// Texts taken from the real translation memory (en.json).
|
|
const homeData = (title: unknown): Doc => ({
|
|
hero: { title, trustBullets: { hu: [{ value: 'Saját dedikált infrastruktúra', id: 'b1' }] } },
|
|
})
|
|
|
|
function setup() {
|
|
const globals = fakeCollection([{ _id: 'g-home', globalType: 'home', ...homeData({ hu: 'Webtárhely, üzleti e-mail és domainkezelés egy helyen' }) }])
|
|
const homeVersions = fakeCollection([
|
|
{ _id: 'old', latest: false, version: homeData({ hu: 'Régi cím' }) },
|
|
{ _id: 'cur', latest: true, version: homeData({ hu: 'Webtárhely, üzleti e-mail és domainkezelés egy helyen' }) },
|
|
])
|
|
const legal = fakeCollection([
|
|
// legacy (unwrapped) shape: the migration must not depend on running after 20260929_localize_legal_pages
|
|
{ _id: 'lp', slug: 'adatvedelem', title: 'Adatvédelmi Tájékoztató', lastUpdated: '2026. augusztus 22.', sections: [{ id: 's1', title: 'Ismeretlen fejezet', content: '1. Bevezetés' }] },
|
|
])
|
|
return {
|
|
globals,
|
|
homeVersions,
|
|
legal,
|
|
...fakeArgs({ globals, collections: { 'legal-pages': legal }, versions: { home: homeVersions } }),
|
|
}
|
|
}
|
|
|
|
describe('20260929_en_ai_draft migration (MITHOME-113)', () => {
|
|
it('should fill English values on the published global and mark it as AI draft', async () => {
|
|
const { args, globals } = setup()
|
|
await up(args)
|
|
const home = globals.docs[0] as { hero: { title: Doc; trustBullets: { en: { value: string }[] } }; enTranslationStatus: string }
|
|
expect(home.hero.title.en).toBe('Web hosting, business email and domain management in one place')
|
|
expect(home.hero.trustBullets.en.map((r) => r.value)).toEqual(['Our own dedicated infrastructure'])
|
|
expect(home.enTranslationStatus).toBe('ai-draft')
|
|
expect(globals.updateOne.mock.calls[0][1].$set).toHaveProperty('enTranslationStatus', 'ai-draft')
|
|
})
|
|
|
|
it('should only fill the latest version, not history', async () => {
|
|
const { args, homeVersions } = setup()
|
|
await up(args)
|
|
expect(homeVersions.updateOne).toHaveBeenCalledTimes(1)
|
|
expect(homeVersions.updateOne.mock.calls[0][0]).toEqual({ _id: 'cur' })
|
|
})
|
|
|
|
it('should wrap legacy legal page values first and report untranslated Hungarian texts', async () => {
|
|
const { args, legal, payload } = setup()
|
|
await up(args)
|
|
expect(legal.docs[0]).toMatchObject({
|
|
slug: 'adatvedelem',
|
|
title: { hu: 'Adatvédelmi Tájékoztató', en: 'Privacy Notice' },
|
|
sections: [{ id: 's1', title: { hu: 'Ismeretlen fejezet' }, content: { hu: '1. Bevezetés', en: '1. Introduction' } }],
|
|
enTranslationStatus: 'ai-draft',
|
|
})
|
|
expect(payload.logger.warn).toHaveBeenCalledWith('MITHOME-113 no translation (legal-pages): Ismeretlen fejezet')
|
|
})
|
|
|
|
it('should be idempotent', async () => {
|
|
const { args, globals, legal } = setup()
|
|
await up(args)
|
|
const snapshot = JSON.stringify([globals.docs, legal.docs])
|
|
await up(args)
|
|
expect(JSON.stringify([globals.docs, legal.docs])).toBe(snapshot)
|
|
})
|
|
})
|