feat(cms): localize legal pages with a lossless migration (MITHOME-112)

Legal page title, last-updated text and section titles/contents become
localized; slug and section ids stay shared. A Payload migration wraps
existing values into { hu: value } on every legal page and its whole
version history, like the globals migration (MITHOME-111).

The migration helper now handles collections as well as globals
(rewriteDocs) and can scope version rewrites to the latest working copy,
which the upcoming English import needs. Migration tests share an
in-memory Mongo fake that honours query filters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-09-29 10:54:44 +02:00
co-authored by Claude Opus 5.5
parent ef93cec935
commit 0eb6594acc
11 changed files with 233 additions and 53 deletions
@@ -0,0 +1,46 @@
import { down, up } from '../migrations/20260929_localize_legal_pages'
import { fakeArgs, fakeCollection } from './helpers/fake-mongo'
const legacyPage = () => ({
_id: 'p1',
slug: 'adatvedelem',
title: 'Adatvédelmi tájékoztató',
lastUpdated: '2026. augusztus 22.',
sections: [{ id: 'bevezetes', title: 'Bevezetés', content: 'Szöveg' }],
_status: 'published',
})
function setup() {
const pages = fakeCollection([legacyPage()])
const versions = fakeCollection([{ _id: 'v1', latest: true, version: legacyPage() }])
return { pages, versions, ...fakeArgs({ collections: { 'legal-pages': pages }, versions: { 'legal-pages': versions } }) }
}
describe('20260929_localize_legal_pages migration (MITHOME-112)', () => {
it('should wrap title, date and section texts under hu, keeping slug and section ids shared', async () => {
const { args, pages } = setup()
await up(args)
expect(pages.docs[0]).toMatchObject({
slug: 'adatvedelem',
title: { hu: 'Adatvédelmi tájékoztató' },
lastUpdated: { hu: '2026. augusztus 22.' },
sections: [{ id: 'bevezetes', title: { hu: 'Bevezetés' }, content: { hu: 'Szöveg' } }],
})
expect(pages.updateOne.mock.calls[0][1].$set).not.toHaveProperty('slug')
})
it('should migrate version records and be idempotent', async () => {
const { args, versions, payload } = setup()
await up(args)
expect((versions.docs[0].version as { title: unknown }).title).toEqual({ hu: 'Adatvédelmi tájékoztató' })
await up(args)
expect(payload.logger.info).toHaveBeenLastCalledWith('MITHOME-112 locale migration: legal-pages — 0 value(s) rewritten')
})
it('should restore the legacy shape on down', async () => {
const { args, pages } = setup()
await up(args)
await down(args)
expect(pages.docs[0]).toEqual(legacyPage())
})
})