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,18 +1,9 @@
|
||||
import { down, up } 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) => ({})),
|
||||
}
|
||||
}
|
||||
|
||||
function setup() {
|
||||
const globals = fakeCollection([
|
||||
@@ -23,11 +14,7 @@ function setup() {
|
||||
{ _id: 'v1', version: { hero: { title: 'Régi cím' } } },
|
||||
{ _id: 'v2', version: { hero: { title: { hu: 'Már migrált' } } } },
|
||||
])
|
||||
const payload = {
|
||||
db: { globals: { collection: globals }, versions: { home: { collection: homeVersions } } },
|
||||
logger: { info: jest.fn() },
|
||||
}
|
||||
const args = { payload, session: undefined, req: {} } as never
|
||||
const { args, payload } = fakeArgs({ globals, versions: { home: homeVersions } })
|
||||
return { args, globals, homeVersions, payload }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user