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:
co-authored by
Claude Opus 5.5
parent
ef93cec935
commit
0eb6594acc
@@ -1,19 +1,10 @@
|
||||
import { down, toPageLink, up } from '../migrations/20260929_cta_page_links'
|
||||
import { up as localizeUp } from '../migrations/20260929_localize_globals'
|
||||
|
||||
import { fakeArgs, fakeCollection } from './helpers/fake-mongo'
|
||||
|
||||
type Doc = Record<string, unknown>
|
||||
|
||||
function fakeCollection(docs: Doc[]) {
|
||||
return {
|
||||
findOne: jest.fn(async (filter: { globalType: string }) => docs.find((d) => d.globalType === filter.globalType) ?? null),
|
||||
find: jest.fn(() => ({
|
||||
async *[Symbol.asyncIterator]() {
|
||||
yield* docs
|
||||
},
|
||||
})),
|
||||
updateOne: jest.fn(async (_filter: Doc, _update: { $set: Doc }, _options?: unknown) => ({})),
|
||||
}
|
||||
}
|
||||
|
||||
const heroWith = (primaryHref: unknown, secondaryHref: unknown) => ({
|
||||
title: 'Cím',
|
||||
@@ -28,11 +19,8 @@ function setup(primaryHref: unknown = { hu: '/kapcsolat' }, secondaryHref: unkno
|
||||
const version: Doc = { _id: 'v1', version: { hero: heroWith({ hu: '/hu/kapcsolat' }, 'https://mail.mozdit.hu') } }
|
||||
const globals = fakeCollection([home])
|
||||
const versions = fakeCollection([version])
|
||||
const payload = {
|
||||
db: { globals: { collection: globals }, versions: { home: { collection: versions } } },
|
||||
logger: { info: jest.fn() },
|
||||
}
|
||||
return { args: { payload, session: undefined, req: {} } as never, home, version, payload }
|
||||
const { args, payload } = fakeArgs({ globals, versions: { home: versions } })
|
||||
return { args, home, version, payload }
|
||||
}
|
||||
|
||||
const cta = (doc: Doc) => (doc.hero as { cta: Record<string, Doc> }).cta
|
||||
|
||||
Reference in New Issue
Block a user