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()) }) })