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>
68 lines
2.6 KiB
TypeScript
68 lines
2.6 KiB
TypeScript
import { down, up } from '../migrations/20260929_localize_globals'
|
|
|
|
import { fakeArgs, fakeCollection } from './helpers/fake-mongo'
|
|
|
|
type Doc = Record<string, unknown>
|
|
|
|
|
|
function setup() {
|
|
const globals = fakeCollection([
|
|
{ _id: 'g-home', globalType: 'home', hero: { title: 'Cím', trustBullets: [{ value: 'Egy' }] }, cta: { title: 'CTA' } },
|
|
{ _id: 'g-common', globalType: 'common', buttons: { contact: { hu: 'Kapcsolat', en: 'Contact' } } },
|
|
])
|
|
const homeVersions = fakeCollection([
|
|
{ _id: 'v1', version: { hero: { title: 'Régi cím' } } },
|
|
{ _id: 'v2', version: { hero: { title: { hu: 'Már migrált' } } } },
|
|
])
|
|
const { args, payload } = fakeArgs({ globals, versions: { home: homeVersions } })
|
|
return { args, globals, homeVersions, payload }
|
|
}
|
|
|
|
describe('20260929_localize_globals migration', () => {
|
|
it('should wrap legacy values of the published global under hu and $set only touched keys', async () => {
|
|
const { args, globals } = setup()
|
|
await up(args)
|
|
|
|
const homeCall = globals.updateOne.mock.calls.find(([filter]) => filter._id === 'g-home')
|
|
expect(homeCall).toBeDefined()
|
|
const [, update] = homeCall!
|
|
expect(update.$set.hero).toEqual({ title: { hu: 'Cím' }, trustBullets: { hu: [{ value: 'Egy' }] } })
|
|
expect(update.$set.cta).toEqual({ title: { hu: 'CTA' } })
|
|
expect(update.$set).not.toHaveProperty('_id')
|
|
expect(update.$set).not.toHaveProperty('globalType')
|
|
})
|
|
|
|
it('should not rewrite a global whose values are already localized', async () => {
|
|
const { args, globals } = setup()
|
|
await up(args)
|
|
const ids = globals.updateOne.mock.calls.map(([filter]) => filter._id)
|
|
expect(ids).not.toContain('g-common')
|
|
})
|
|
|
|
it('should migrate legacy version records and skip migrated ones', async () => {
|
|
const { args, homeVersions } = setup()
|
|
await up(args)
|
|
|
|
expect(homeVersions.updateOne).toHaveBeenCalledTimes(1)
|
|
expect(homeVersions.updateOne).toHaveBeenCalledWith(
|
|
{ _id: 'v1' },
|
|
{ $set: { version: { hero: { title: { hu: 'Régi cím' } } } } },
|
|
{ session: undefined },
|
|
)
|
|
})
|
|
|
|
it('should log a per-global summary', async () => {
|
|
const { args, payload } = setup()
|
|
await up(args)
|
|
expect(payload.logger.info).toHaveBeenCalledWith('MITHOME-111 locale migration: home — 4 value(s) rewritten')
|
|
})
|
|
|
|
it('should restore the hu value on down', async () => {
|
|
const { args, globals } = setup()
|
|
await down(args)
|
|
const commonCall = globals.updateOne.mock.calls.find(([filter]) => filter._id === 'g-common')
|
|
const [, update] = commonCall!
|
|
expect(update.$set.buttons).toEqual({ contact: 'Kapcsolat' })
|
|
})
|
|
})
|