feat(cms): hosting plans page with lifecycle gate and net + VAT prices (MITHOME-130)
CI Pipeline with Test Management / 🧪 Run Tests & Generate Reports (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 🧪 Run Tests & Generate Reports (push) Canceled after 0s
CI Pipeline with Test Management / 🐳 Docker Integration Tests (push) Canceled after 0s
CI Pipeline with Test Management / 🏗️ Build Docker Image (push) Canceled after 0s
CI Pipeline with Test Management / 📊 Generate Test Summary (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 📊 Analyze Test Coverage (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 🔄 Sync with Linear (push) Canceled after 0s
Test Reporting & Gherkin Analysis / ⚡ Performance Monitoring (push) Canceled after 0s
CI Pipeline with Test Management / 🧪 Run Tests & Generate Reports (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 🧪 Run Tests & Generate Reports (push) Canceled after 0s
CI Pipeline with Test Management / 🐳 Docker Integration Tests (push) Canceled after 0s
CI Pipeline with Test Management / 🏗️ Build Docker Image (push) Canceled after 0s
CI Pipeline with Test Management / 📊 Generate Test Summary (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 📊 Analyze Test Coverage (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 🔄 Sync with Linear (push) Canceled after 0s
Test Reporting & Gherkin Analysis / ⚡ Performance Monitoring (push) Canceled after 0s
- Products collection (interim mirror of the PLATFM-14 catalogue contract): lifecycle status, product type, required whole-forint net price, yearly billing, service definition, per-product English gate - HostingPlans global: page copy, comparison labels, VAT rate (27%) - Gate: production shows only active plans, staging all but retired; with no showable plan the page is 404 and left out of the menu and the sitemap - /hu/tarhely-csomagok <-> /en/hosting-plans via PAGE_SLUGS (hreflang, language switcher, CTA page picker) - Seed migration 20260929_hosting_plans: mIT Start (14 900 Ft/yr, 5 mailboxes) and mIT Mid (23 900 Ft/yr) as drafts, English AI draft; idempotent - Production SEO suite expects at least 12 sitemap URLs; new SMOKE-10 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
0c5888761b
commit
1e0742a548
@@ -19,6 +19,8 @@ describe('languageLinks (MITHOME-115)', () => {
|
||||
{ locale: 'en', href: '/en/services', isActive: false },
|
||||
])
|
||||
expect(languageLinks('/en/privacy-policy').map((l) => l.href)).toEqual(['/hu/adatvedelem', '/en/privacy-policy'])
|
||||
// MITHOME-130
|
||||
expect(languageLinks('/hu/tarhely-csomagok').map((l) => l.href)).toEqual(['/hu/tarhely-csomagok', '/en/hosting-plans'])
|
||||
})
|
||||
|
||||
it('should link the home pages from a home page', () => {
|
||||
|
||||
@@ -17,13 +17,15 @@ export function isLocale(value: string): value is Locale {
|
||||
}
|
||||
|
||||
/** A catch-all [slug] route alá tartozó oldalak azonosítói. */
|
||||
export type PageKey = 'about' | 'services' | 'contact' | 'privacy' | 'terms'
|
||||
export type PageKey = 'about' | 'services' | 'hostingPlans' | 'contact' | 'privacy' | 'terms'
|
||||
|
||||
/** Nyelvenkénti szlög minden oldalhoz — a nyelvváltó (MITHOME-115) és a
|
||||
* sitemap/hreflang (MITHOME-116) is ezt a táblát fogja használni. */
|
||||
export const PAGE_SLUGS: Record<PageKey, Record<Locale, string>> = {
|
||||
about: { hu: 'rolunk', en: 'about' },
|
||||
services: { hu: 'szolgaltatasok', en: 'services' },
|
||||
// MITHOME-130: only reachable while a showable plan exists (src/lib/products.ts).
|
||||
hostingPlans: { hu: 'tarhely-csomagok', en: 'hosting-plans' },
|
||||
contact: { hu: 'kapcsolat', en: 'contact' },
|
||||
privacy: { hu: 'adatvedelem', en: 'privacy-policy' },
|
||||
terms: { hu: 'felhasznalasi-feltetelek', en: 'terms-of-service' },
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
*/
|
||||
import { getPayload } from 'payload'
|
||||
import config from '@payload-config'
|
||||
import type { Locale } from './i18n'
|
||||
import { DEFAULT_LOCALE, type Locale } from './i18n'
|
||||
import { resolveCtaHref, type CtaLink } from './cta-link'
|
||||
import { readGated } from './translation-gate'
|
||||
import { publicPartners, type PartnerView } from './partner-references'
|
||||
import { hostingPlanViews, showableStatuses, type HostingPlanView, type ProductDoc } from './products'
|
||||
|
||||
let cached: ReturnType<typeof getPayload> | undefined
|
||||
|
||||
@@ -114,3 +115,37 @@ export async function getPartners(): Promise<PartnerView[]> {
|
||||
const result = await payload.find({ collection: 'partners', limit: 100, sort: 'name', depth: 1 })
|
||||
return publicPartners(result.docs)
|
||||
}
|
||||
|
||||
export type { HostingPlanView } from './products'
|
||||
|
||||
/** MITHOME-130: raw hosting products in one locale, lifecycle-gated in the query. */
|
||||
async function findHostingProducts(locale: Locale): Promise<ProductDoc[]> {
|
||||
const payload = await payloadClient()
|
||||
const result = await payload.find({
|
||||
collection: 'products',
|
||||
where: { productType: { equals: 'hosting' }, status: { in: showableStatuses() } },
|
||||
sort: 'sortOrder',
|
||||
locale,
|
||||
limit: 50,
|
||||
depth: 0,
|
||||
})
|
||||
return result.docs as unknown as ProductDoc[]
|
||||
}
|
||||
|
||||
/** MITHOME-130: showable hosting plans; the English gate works per product. */
|
||||
export async function getHostingPlans(locale: Locale): Promise<HostingPlanView[]> {
|
||||
const requested = await findHostingProducts(locale)
|
||||
const needsFallback = locale !== DEFAULT_LOCALE && requested.some((doc) => doc.enTranslationStatus !== 'approved')
|
||||
const fallback = needsFallback ? await findHostingProducts(DEFAULT_LOCALE) : []
|
||||
return hostingPlanViews(locale, requested, fallback)
|
||||
}
|
||||
|
||||
/** The page, the menu item and the sitemap entry all follow this one gate. */
|
||||
export async function hasHostingPlans(): Promise<boolean> {
|
||||
return (await getHostingPlans(DEFAULT_LOCALE)).length > 0
|
||||
}
|
||||
|
||||
export async function getHostingPlansContent(locale: Locale) {
|
||||
const payload = await payloadClient()
|
||||
return readGated(locale, (l) => payload.findGlobal({ slug: 'hosting-plans', locale: l }))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { formatHuf, grossAmount, hostingPlanViews, showableStatuses, type ProductDoc } from './products'
|
||||
|
||||
const product = (over: Partial<ProductDoc> = {}): 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()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
* MITHOME-130: hosting plans — lifecycle gate, price and view model.
|
||||
*
|
||||
* The product structure follows the central catalogue contract (mitplatform
|
||||
* PLATFM-14, docs/architecture/product-catalog-contract.md). The Payload
|
||||
* `products` collection is an interim mirror of it; reading goes through
|
||||
* src/lib/payload-content.ts so the source can be swapped in one place.
|
||||
*
|
||||
* Pure functions only — no Payload import, unit-testable.
|
||||
*/
|
||||
import { contentLocale } from './translation-gate'
|
||||
import type { Locale } from './i18n'
|
||||
|
||||
export const PRODUCT_STATUSES = ['draft', 'internal', 'publishable', 'active', 'retired'] as const
|
||||
export type ProductStatus = (typeof PRODUCT_STATUSES)[number]
|
||||
|
||||
export const PRODUCT_STATUS_LABELS: Record<ProductStatus, string> = {
|
||||
draft: 'Tervezet',
|
||||
internal: 'Belső',
|
||||
publishable: 'Publikálható',
|
||||
active: 'Aktív (éles)',
|
||||
retired: 'Kivezetett',
|
||||
}
|
||||
|
||||
export const PRODUCT_TYPES = ['hosting', 'managed-service'] as const
|
||||
export type ProductType = (typeof PRODUCT_TYPES)[number]
|
||||
|
||||
export const PRODUCT_TYPE_LABELS: Record<ProductType, string> = {
|
||||
hosting: 'Tárhely',
|
||||
'managed-service': 'Menedzselt szolgáltatás',
|
||||
}
|
||||
|
||||
export const BILLING_PERIODS = ['yearly', 'monthly', 'one-time'] as const
|
||||
export type BillingPeriod = (typeof BILLING_PERIODS)[number]
|
||||
|
||||
export const BILLING_PERIOD_LABELS: Record<BillingPeriod, string> = {
|
||||
yearly: 'Éves',
|
||||
monthly: 'Havi',
|
||||
'one-time': 'Egyszeri',
|
||||
}
|
||||
|
||||
export const DEFAULT_VAT_RATE_PERCENT = 27
|
||||
|
||||
/**
|
||||
* DECISION (user): production shows only active products; staging shows
|
||||
* everything except retired ones so drafts can be reviewed there.
|
||||
*/
|
||||
export function showableStatuses(deployEnv: string | undefined = process.env.NEXT_PUBLIC_DEPLOY_ENV): ProductStatus[] {
|
||||
return deployEnv === 'staging' ? PRODUCT_STATUSES.filter((s) => s !== 'retired') : ['active']
|
||||
}
|
||||
|
||||
/** Gross price from the stored net amount (whole forints). */
|
||||
export function grossAmount(netAmount: number, vatRatePercent: number = DEFAULT_VAT_RATE_PERCENT): number {
|
||||
return Math.round(netAmount * (1 + vatRatePercent / 100))
|
||||
}
|
||||
|
||||
/** "14 900 Ft" (hu) / "14,900 Ft" (en). */
|
||||
export function formatHuf(amount: number, locale: Locale): string {
|
||||
const number = new Intl.NumberFormat(locale === 'hu' ? 'hu-HU' : 'en-GB', { maximumFractionDigits: 0 }).format(amount)
|
||||
return `${number} Ft`
|
||||
}
|
||||
|
||||
type Localized<T> = T | null | undefined
|
||||
|
||||
export type ProductDoc = {
|
||||
id: string | number
|
||||
slug: string
|
||||
name: string
|
||||
productType?: string | null
|
||||
status?: string | null
|
||||
sortOrder?: number | null
|
||||
highlighted?: boolean | null
|
||||
enTranslationStatus?: string | null
|
||||
public?: {
|
||||
audience?: Localized<string>
|
||||
shortDescription?: Localized<string>
|
||||
features?: { value: string }[] | null
|
||||
ctaText?: Localized<string>
|
||||
} | null
|
||||
pricing?: { netAmount?: number | null; billingPeriod?: string | null } | null
|
||||
serviceDefinition?: {
|
||||
storageGb?: number | null
|
||||
mailStorageGb?: number | null
|
||||
domains?: number | null
|
||||
domainAliases?: number | null
|
||||
databases?: number | null
|
||||
mailboxes?: number | null
|
||||
backup?: Localized<string>
|
||||
ssl?: boolean | null
|
||||
spamFilter?: boolean | null
|
||||
} | null
|
||||
}
|
||||
|
||||
export type HostingPlanView = {
|
||||
id: string
|
||||
slug: string
|
||||
name: string
|
||||
highlighted: boolean
|
||||
audience: string
|
||||
shortDescription: string
|
||||
features: string[]
|
||||
ctaText: string
|
||||
netAmount: number
|
||||
billingPeriod: BillingPeriod
|
||||
service: {
|
||||
storageGb?: number
|
||||
mailStorageGb?: number
|
||||
domains?: number
|
||||
domainAliases?: number
|
||||
databases?: number
|
||||
mailboxes?: number
|
||||
backup?: string
|
||||
ssl: boolean
|
||||
spamFilter: boolean
|
||||
}
|
||||
}
|
||||
|
||||
const orUndefined = (value: number | null | undefined) => (value ?? undefined)
|
||||
|
||||
function toView(doc: ProductDoc): HostingPlanView {
|
||||
const s = doc.serviceDefinition ?? {}
|
||||
const period = doc.pricing?.billingPeriod
|
||||
return {
|
||||
id: String(doc.id),
|
||||
slug: doc.slug,
|
||||
name: doc.name,
|
||||
highlighted: doc.highlighted === true,
|
||||
audience: doc.public?.audience ?? '',
|
||||
shortDescription: doc.public?.shortDescription ?? '',
|
||||
features: (doc.public?.features ?? []).map((f) => f.value),
|
||||
ctaText: doc.public?.ctaText ?? '',
|
||||
netAmount: doc.pricing?.netAmount ?? 0,
|
||||
billingPeriod: (BILLING_PERIODS as readonly string[]).includes(period ?? '') ? (period as BillingPeriod) : 'yearly',
|
||||
service: {
|
||||
storageGb: orUndefined(s.storageGb),
|
||||
mailStorageGb: orUndefined(s.mailStorageGb),
|
||||
domains: orUndefined(s.domains),
|
||||
domainAliases: orUndefined(s.domainAliases),
|
||||
databases: orUndefined(s.databases),
|
||||
mailboxes: orUndefined(s.mailboxes),
|
||||
backup: s.backup ?? undefined,
|
||||
ssl: s.ssl === true,
|
||||
spamFilter: s.spamFilter === true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hosting products for `locale`, gated and ordered. The translation gate
|
||||
* works per product: `requested` holds the docs read in the requested
|
||||
* locale, `fallback` the same docs in the default locale (only needed for
|
||||
* English).
|
||||
*/
|
||||
export function hostingPlanViews(
|
||||
locale: Locale,
|
||||
requested: readonly ProductDoc[],
|
||||
fallback: readonly ProductDoc[] = [],
|
||||
statuses: readonly string[] = showableStatuses(),
|
||||
): HostingPlanView[] {
|
||||
const fallbackById = new Map(fallback.map((doc) => [String(doc.id), doc]))
|
||||
return requested
|
||||
.filter((doc) => doc.productType === 'hosting' && statuses.includes(doc.status ?? ''))
|
||||
.filter((doc) => typeof doc.pricing?.netAmount === 'number')
|
||||
.map((doc) => (contentLocale(locale, doc.enTranslationStatus) === locale ? doc : fallbackById.get(String(doc.id)) ?? doc))
|
||||
.sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
|
||||
.map(toView)
|
||||
}
|
||||
@@ -25,7 +25,7 @@ describe('SEO helpers (MITHOME-116)', () => {
|
||||
|
||||
it('should list every page in both languages in the sitemap', () => {
|
||||
const entries = sitemapEntries(SITE)
|
||||
expect(entries).toHaveLength(12)
|
||||
expect(entries).toHaveLength(14)
|
||||
expect(entries.map((e) => e.url)).toEqual(
|
||||
expect.arrayContaining(['https://mozdit.hu/hu', 'https://mozdit.hu/en', 'https://mozdit.hu/en/privacy-policy', 'https://mozdit.hu/hu/felhasznalasi-feltetelek']),
|
||||
)
|
||||
@@ -33,6 +33,15 @@ describe('SEO helpers (MITHOME-116)', () => {
|
||||
expect(privacy.alternates?.languages).toMatchObject({ hu: 'https://mozdit.hu/hu/adatvedelem' })
|
||||
})
|
||||
|
||||
it('should leave hidden pages out of the sitemap (MITHOME-130)', () => {
|
||||
const urls = sitemapEntries(SITE, ['hostingPlans']).map((e) => e.url)
|
||||
expect(urls).toHaveLength(12)
|
||||
expect(urls).not.toContain('https://mozdit.hu/hu/tarhely-csomagok')
|
||||
expect(sitemapEntries(SITE).map((e) => e.url)).toEqual(
|
||||
expect.arrayContaining(['https://mozdit.hu/hu/tarhely-csomagok', 'https://mozdit.hu/en/hosting-plans']),
|
||||
)
|
||||
})
|
||||
|
||||
it('should block all crawling on staging and publish the sitemap elsewhere', () => {
|
||||
expect(isIndexingDisabled('staging')).toBe(true)
|
||||
expect(isIndexingDisabled(undefined)).toBe(false)
|
||||
|
||||
@@ -44,8 +44,9 @@ export function isIndexingDisabled(deployEnv: string | undefined = process.env.N
|
||||
return deployEnv === 'staging'
|
||||
}
|
||||
|
||||
export function sitemapEntries(siteUrl?: string): MetadataRoute.Sitemap {
|
||||
return PAGES.flatMap((page) =>
|
||||
/** MITHOME-130: `hiddenPages` are left out (e.g. hosting plans with no showable plan). */
|
||||
export function sitemapEntries(siteUrl?: string, hiddenPages: readonly PageKey[] = []): MetadataRoute.Sitemap {
|
||||
return PAGES.filter((page) => page === undefined || !hiddenPages.includes(page)).flatMap((page) =>
|
||||
LOCALES.map((locale) => ({
|
||||
url: absoluteUrl(localePath(locale, page), siteUrl),
|
||||
changeFrequency: 'monthly' as const,
|
||||
|
||||
Reference in New Issue
Block a user