import { formatHuf, grossAmount, hostingPlanViews, showableStatuses, type ProductDoc } from './products' const product = (over: Partial = {}): ProductDoc => ({ id: 'p1', slug: 'mit-start', name: 'mIT Start', productType: 'hosting', status: 'draft', sortOrder: 10, enTranslationStatus: 'ai-draft', public: { audience: 'Kinek', shortDescription: 'Leírás', features: [{ value: 'SSL' }], ctaText: 'Ezt választom' }, pricing: { netAmount: 14900, billingPeriod: 'yearly' }, serviceDefinition: { storageGb: 3, mailboxes: 5, ssl: true }, ...over, }) const normalizeSpaces = (text: string) => text.replace(/\s/g, ' ') describe('hosting plans (MITHOME-130)', () => { it('should show only active products in production and everything but retired on staging', () => { expect(showableStatuses(undefined)).toEqual(['active']) expect(showableStatuses('production')).toEqual(['active']) expect(showableStatuses('staging')).toEqual(['draft', 'internal', 'publishable', 'active']) }) it('should compute the gross price from the net price and the VAT rate', () => { expect(grossAmount(14900)).toBe(18923) expect(grossAmount(23900, 27)).toBe(30353) expect(grossAmount(10001, 27)).toBe(12701) expect(grossAmount(1000, 0)).toBe(1000) }) it('should format forint amounts per locale', () => { expect(normalizeSpaces(formatHuf(14900, 'hu'))).toBe('14 900 Ft') expect(formatHuf(14900, 'en')).toBe('14,900 Ft') }) it('should gate by status and type, and order by sortOrder', () => { const docs = [ product({ id: 'mid', slug: 'mit-mid', sortOrder: 20 }), product({ id: 'start', sortOrder: 10 }), product({ id: 'old', slug: 'old', status: 'retired' }), product({ id: 'webor', slug: 'webor', productType: 'managed-service' }), product({ id: 'live', slug: 'live', status: 'active', sortOrder: 30 }), ] expect(hostingPlanViews('hu', docs, [], showableStatuses('staging')).map((p) => p.id)).toEqual(['start', 'mid', 'live']) expect(hostingPlanViews('hu', docs, [], showableStatuses('production')).map((p) => p.id)).toEqual(['live']) }) it('should never show a plan without a price', () => { const docs = [product({ pricing: { netAmount: null, billingPeriod: 'yearly' } })] expect(hostingPlanViews('hu', docs, [], ['draft'])).toEqual([]) }) it('should apply the English gate per product', () => { const en = [ product({ id: 'a', public: { audience: 'EN draft' }, enTranslationStatus: 'ai-draft' }), product({ id: 'b', public: { audience: 'EN approved' }, enTranslationStatus: 'approved', sortOrder: 20 }), ] const hu = [product({ id: 'a', public: { audience: 'HU a' } }), product({ id: 'b', public: { audience: 'HU b' }, sortOrder: 20 })] expect(hostingPlanViews('en', en, hu, ['draft']).map((p) => p.audience)).toEqual(['HU a', 'EN approved']) expect(hostingPlanViews('hu', hu, [], ['draft']).map((p) => p.audience)).toEqual(['HU a', 'HU b']) }) it('should build the view model with unwrapped features and service figures', () => { const [view] = hostingPlanViews('hu', [product({ highlighted: true })], [], ['draft']) expect(view).toMatchObject({ slug: 'mit-start', highlighted: true, features: ['SSL'], netAmount: 14900, billingPeriod: 'yearly', service: { storageGb: 3, mailboxes: 5, ssl: true, spamFilter: false }, }) expect(view.service.databases).toBeUndefined() }) })