import { HOSTING_PLAN_SEEDS, productData, up } from '../migrations/20260929_hosting_plans' type Doc = Record /** Minimal Local API stand-in: products by slug + one global. */ function fakePayload(products: Doc[] = [], page: Doc = {}) { const payload = { find: jest.fn(async ({ where }: { where: { slug: { equals: string } } }) => ({ docs: products.filter((p) => p.slug === where.slug.equals), })), create: jest.fn(async ({ data }: { data: Doc }) => { const doc = { id: `id-${products.length}`, ...data } products.push(doc) return doc }), update: jest.fn(async () => ({})), findGlobal: jest.fn(async () => page), updateGlobal: jest.fn(async ({ data, locale }: { data: Doc; locale: string }) => { if (locale === 'hu') Object.assign(page, data) return page }), logger: { info: jest.fn(), warn: jest.fn() }, } return { payload, args: { payload, req: {} } as never } } describe('20260929_hosting_plans migration (MITHOME-130)', () => { it('should seed the catalogue figures and prices as a draft, with an English AI draft', () => { const start = productData(HOSTING_PLAN_SEEDS[0], 'hu') expect(start).toMatchObject({ slug: 'mit-start', productType: 'hosting', status: 'draft', enTranslationStatus: 'ai-draft', pricing: { netAmount: 14900, billingPeriod: 'yearly' }, serviceDefinition: { storageGb: 3, mailStorageGb: 1, databases: 1, mailboxes: 5, ssl: true, spamFilter: true }, _status: 'published', }) expect(productData(HOSTING_PLAN_SEEDS[1], 'hu')).toMatchObject({ highlighted: true, pricing: { netAmount: 23900 }, serviceDefinition: { storageGb: 8, mailStorageGb: 4, domainAliases: 2, databases: 2, mailboxes: 10 }, }) }) it('should write only localized fields in English', () => { const en = productData(HOSTING_PLAN_SEEDS[0], 'en') expect(Object.keys(en).sort()).toEqual(['_status', 'public', 'serviceDefinition']) expect(en.serviceDefinition).toEqual({ backup: 'Daily, with 7-day restore' }) }) it('should create the missing products and page copy once', async () => { const products: Doc[] = [] const { args, payload } = fakePayload(products) await up(args) expect(payload.create).toHaveBeenCalledTimes(2) expect(payload.update).toHaveBeenCalledWith(expect.objectContaining({ locale: 'en' })) expect(payload.updateGlobal).toHaveBeenCalledWith( expect.objectContaining({ locale: 'hu', data: expect.objectContaining({ vatRatePercent: 27, hero: expect.objectContaining({ title: 'Tárhelycsomagok' }) }) }), ) expect(payload.logger.info).toHaveBeenLastCalledWith('MITHOME-130 hosting plans: 2 product(s) created, 1 page copy seeded') await up(args) expect(payload.create).toHaveBeenCalledTimes(2) expect(payload.logger.info).toHaveBeenLastCalledWith('MITHOME-130 hosting plans: 0 product(s) created, 0 page copy seeded') }) it('should not overwrite an existing product or edited page copy', async () => { const { args, payload } = fakePayload([{ id: 'x', slug: 'mit-start', pricing: { netAmount: 1 } }], { hero: { title: 'Saját cím' } }) await up(args) expect(payload.create).toHaveBeenCalledTimes(1) expect(payload.updateGlobal).not.toHaveBeenCalled() }) })