Per the managed web operations research (PLATFM-13), a client must not be
shown as a "partner" and names/logos need written permission. Partners
now carry a required relationship category and a publication permission
(default: none) with the permission's location and review date; only
entries with written permission, a category and a logo are public.
The homepage shows clients ("Akik már minket választottak") and other
relationships in separate blocks via ReferencesSection; every partner
shows its relationship type. The section copy moved from a hard-coded
constant into the Home global (localized). The 20260929_partner_references
migration marks Angele Pihenőház as a client reference with written
permission (owner-confirmed), hides any other uncategorised entry, and
seeds the copy in hu + en. The JSON seed uses the same source.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
269 lines
12 KiB
TypeScript
269 lines
12 KiB
TypeScript
/**
|
|
* MITHOME-96 — Payload collection/global config tesztek.
|
|
*
|
|
* WHY nem a teljes payload.config.ts-t importáljuk: az a valódi `payload` és
|
|
* `@payloadcms/db-mongodb` csomagokat importálja értékként (nem csak
|
|
* típusként), amik ESM-only, natív node_modules-forrást futtatnak — Jest
|
|
* (a next/jest transzformmal is) nem tudja lefordítani őket anélkül, hogy a
|
|
* teljes payload-függőségi fát is a transformIgnorePatterns kivételévé
|
|
* tennénk (próbáltuk: `SyntaxError: Cannot use import statement outside a
|
|
* module` a payload csomag saját forrásából). Az egyes Collection/Global
|
|
* fájlok viszont csak `import type` formában hivatkoznak a `payload`
|
|
* csomagra — ez típus-only import, a build kitörli, így ezek a fájlok
|
|
* önmagukban, gyors unit tesztként importálhatók, élő MongoDB/PAYLOAD_SECRET
|
|
* nélkül. Ez fedi le a ticket "Payload config tesztek" részét; a Local API
|
|
* ellen futó, élő adatbázist igénylő tesztek külön (integrációs) fájlban
|
|
* vannak — lásd src/__tests__/payload-local-api.test.ts.
|
|
*
|
|
* Ezek a tesztek szándékosan regresszió-őrök is: mindkettő egy-egy valódi,
|
|
* élesben megtalált hibát rögzít (MITHOME-121: Media publikus olvasása,
|
|
* Partners.logo opcionalitása), hogy soha többé ne térjenek vissza észrevétlenül.
|
|
*/
|
|
import { Users } from './collections/Users'
|
|
import { LegalPages } from './collections/LegalPages'
|
|
import { Media } from './collections/Media'
|
|
import { Partners } from './collections/Partners'
|
|
import { ContactSubmissions } from './collections/ContactSubmissions'
|
|
import { Home } from './globals/Home'
|
|
import { About } from './globals/About'
|
|
import { Services } from './globals/Services'
|
|
import { Contact } from './globals/Contact'
|
|
import { Common } from './globals/Common'
|
|
|
|
type FieldLike = { name?: string; required?: boolean; type?: string }
|
|
|
|
function findField(fields: unknown[], name: string): FieldLike | undefined {
|
|
return (fields as FieldLike[]).find((f) => f.name === name)
|
|
}
|
|
|
|
describe('Payload collections', () => {
|
|
it('all collection slugs are present and unique', () => {
|
|
const slugs = [Users, LegalPages, Media, Partners, ContactSubmissions].map((c) => c.slug)
|
|
expect(slugs).toEqual(['users', 'legal-pages', 'media', 'partners', 'contact-submissions'])
|
|
expect(new Set(slugs).size).toBe(slugs.length)
|
|
})
|
|
|
|
describe('Media', () => {
|
|
// Regresszió-őr — MITHOME-121: a Media collection read access-e sokáig
|
|
// (MITHOME-89 óta) alapértelmezetten csak bejelentkezett usernek volt
|
|
// engedélyezett, emiatt a partner logók sosem töltődtek be a publikus
|
|
// oldalon (403 -> a Next.js image-optimizer "nem érvényes kép" hibája).
|
|
it('allows public (unauthenticated) read access', () => {
|
|
expect(Media.access?.read).toBeDefined()
|
|
const result = Media.access!.read!({ req: { user: null } } as never)
|
|
expect(result).toBe(true)
|
|
})
|
|
|
|
it('only accepts image uploads', () => {
|
|
expect(Media.upload).toEqual(expect.objectContaining({ mimeTypes: ['image/*'] }))
|
|
})
|
|
})
|
|
|
|
describe('Partners', () => {
|
|
it('requires name and url', () => {
|
|
expect(findField(Partners.fields, 'name')?.required).toBe(true)
|
|
expect(findField(Partners.fields, 'url')?.required).toBe(true)
|
|
})
|
|
|
|
// Regresszió-őr — MITHOME-121: a felhasználó kérésére a logo mező
|
|
// opcionálissá vált, hogy egy partner logó nélkül is menthető legyen.
|
|
it('should require a relationship category and default to no publication permission (MITHOME-131)', () => {
|
|
const relationship = findField(Partners.fields, 'relationship') as unknown as { required: boolean; options: { value: string }[] }
|
|
const permission = findField(Partners.fields, 'publicationPermission') as unknown as { defaultValue: string }
|
|
expect(relationship.required).toBe(true)
|
|
expect(relationship.options.map((o) => o.value)).toContain('client-reference')
|
|
expect(permission.defaultValue).toBe('none')
|
|
})
|
|
|
|
it('does not require a logo', () => {
|
|
const logo = findField(Partners.fields, 'logo')
|
|
expect(logo).toBeDefined()
|
|
expect(logo?.required).not.toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('ContactSubmissions', () => {
|
|
// WHY nincs egyedi access blokk itt tesztelve mint "hiányzik": a Payload
|
|
// defaultAccess (csak bejelentkezett user) itt a kívánt viselkedés —
|
|
// lásd a collection saját WHY-kommentjét. Nincs mit tesztelni rajta
|
|
// (nincs felülírás), de a mezőszerkezetet igen.
|
|
it('requires the core submission fields', () => {
|
|
for (const name of ['name', 'email', 'subject', 'message', 'gdprConsent']) {
|
|
expect(findField(ContactSubmissions.fields, name)?.required).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('defaults status to "new"', () => {
|
|
const status = findField(ContactSubmissions.fields, 'status') as FieldLike & {
|
|
defaultValue?: string
|
|
options?: { value: string }[]
|
|
}
|
|
expect(status?.defaultValue).toBe('new')
|
|
expect(status?.options?.map((o) => o.value)).toEqual(['new', 'read', 'replied', 'archived'])
|
|
})
|
|
})
|
|
|
|
describe('LegalPages', () => {
|
|
it('has a required, unique slug field', () => {
|
|
const slug = findField(LegalPages.fields, 'slug') as FieldLike & { unique?: boolean }
|
|
expect(slug?.required).toBe(true)
|
|
expect(slug?.unique).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('Users', () => {
|
|
it('locks accounts after 5 failed attempts for 10 minutes', () => {
|
|
expect(Users.auth).toEqual(
|
|
expect.objectContaining({ maxLoginAttempts: 5, lockTime: 10 * 60 * 1000 })
|
|
)
|
|
})
|
|
|
|
it('requires an authenticated user for every access-controlled operation', () => {
|
|
const access = Users.access!
|
|
for (const op of ['create', 'read', 'update', 'delete', 'unlock'] as const) {
|
|
expect(access[op]!({ req: { user: null } } as never)).toBe(false)
|
|
expect(access[op]!({ req: { user: {} } } as never)).toBe(true)
|
|
}
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('Payload globals', () => {
|
|
it('all global slugs are present and unique', () => {
|
|
const slugs = [Home, About, Services, Contact, Common].map((g) => g.slug)
|
|
expect(slugs).toEqual(['home', 'about', 'services', 'contact', 'common'])
|
|
expect(new Set(slugs).size).toBe(slugs.length)
|
|
})
|
|
|
|
it('Home does not duplicate the Partners collection', () => {
|
|
// MITHOME-89 döntés: a partnerek önálló collection-ök, a Home global
|
|
// szándékosan nem tartalmaz "partners" mezőt.
|
|
expect(findField(Home.fields, 'partners')).toBeUndefined()
|
|
})
|
|
|
|
it('Common.buttons.* fields are localized (MITHOME-110 bizonyíték)', () => {
|
|
const buttonsGroup = findField(Common.fields, 'buttons') as FieldLike & {
|
|
fields?: (FieldLike & { localized?: boolean })[]
|
|
}
|
|
expect(buttonsGroup?.fields?.length).toBeGreaterThan(0)
|
|
for (const field of buttonsGroup!.fields!) {
|
|
expect(field.localized).toBe(true)
|
|
}
|
|
})
|
|
|
|
describe('MITHOME-111 localization rule', () => {
|
|
// DECISION (design D1): structural values shared across locales.
|
|
// MITHOME-112: `slug` is the shared URL identifier of LegalPages.
|
|
// MITHOME-113: `result`/`notes` are legal-validation metadata, not copy.
|
|
const SHARED_TEXT_FIELDS = new Set(['icon', 'id', 'address', 'slug', 'result', 'notes'])
|
|
|
|
type Node = FieldLike & { localized?: boolean; fields?: Node[] }
|
|
type Finding = { path: string; type?: string; localized: boolean }
|
|
|
|
const isStringArray = (f: Node) =>
|
|
f.type === 'array' && f.fields?.length === 1 && f.fields[0].name === 'value'
|
|
|
|
function walk(fields: Node[], prefix: string, out: Finding[]): Finding[] {
|
|
for (const f of fields) {
|
|
const path = `${prefix}${f.name}`
|
|
if (isStringArray(f)) {
|
|
out.push({ path: `${path}[]`, localized: f.localized === true })
|
|
} else if (f.type === 'group' || f.type === 'array') {
|
|
// Object arrays/groups themselves stay shared; only their leaves localize.
|
|
out.push({ path: `${path}(container)`, localized: f.localized === true })
|
|
walk(f.fields ?? [], `${path}.`, out)
|
|
} else {
|
|
out.push({ path, type: f.type, localized: f.localized === true })
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
function expected(finding: Finding): boolean {
|
|
if (finding.path.endsWith('(container)')) return false
|
|
if (finding.path.endsWith('[]')) return true
|
|
// Checkbox/radio/select (linkType, page) are structural.
|
|
if (finding.type !== 'text' && finding.type !== 'textarea') return false
|
|
return !SHARED_TEXT_FIELDS.has(finding.path.split('.').pop()!)
|
|
}
|
|
|
|
it.each([Home, About, Services, Contact, Common, LegalPages].map((g) => [g.slug, g] as const))(
|
|
'should localize exactly the translatable fields of %s',
|
|
(_slug, global) => {
|
|
const findings = walk(global.fields as Node[], '', [])
|
|
const wrong = findings.filter((f) => f.localized !== expected(f)).map((f) => f.path)
|
|
expect(wrong).toEqual([])
|
|
},
|
|
)
|
|
|
|
it('should localize the CTA URL but share the link type and page', () => {
|
|
const findings = walk(Home.fields as Node[], '', [])
|
|
const byPath = Object.fromEntries(findings.map((f) => [f.path, f.localized]))
|
|
expect(byPath['hero.cta.primary.href']).toBe(true)
|
|
expect(byPath['hero.cta.primary.linkType']).toBe(false)
|
|
expect(byPath['hero.cta.primary.page']).toBe(false)
|
|
// MITHOME-124: no manual new-tab switch — derived from the URL.
|
|
expect(byPath).not.toHaveProperty('hero.cta.primary.external')
|
|
})
|
|
})
|
|
|
|
describe('MITHOME-123 CTA links', () => {
|
|
type Validate = (value: unknown, opts: { siblingData: { linkType?: string } }) => true | string
|
|
const cta = (name: string) => {
|
|
const hero = findField(Home.fields, 'hero') as { fields: unknown[] }
|
|
const group = findField(hero.fields, 'cta') as { fields: unknown[] }
|
|
return (findField(group.fields, name) as { fields: unknown[] }).fields
|
|
}
|
|
const validate = (field: string) => (findField(cta('primary'), field) as unknown as { validate: Validate }).validate
|
|
|
|
it('should offer every routable page, including home, in the page selector', () => {
|
|
const page = findField(cta('primary'), 'page') as unknown as { options: { value: string }[] }
|
|
expect(page.options.map((o) => o.value)).toEqual(['home', 'about', 'services', 'contact', 'privacy', 'terms'])
|
|
})
|
|
|
|
it('should require a page only for internal links and a URL only for external links', () => {
|
|
expect(validate('page')(null, { siblingData: { linkType: 'page' } })).toEqual(expect.any(String))
|
|
expect(validate('page')(null, { siblingData: { linkType: 'url' } })).toBe(true)
|
|
expect(validate('href')('', { siblingData: { linkType: 'url' } })).toEqual(expect.any(String))
|
|
expect(validate('href')(null, { siblingData: { linkType: 'page' } })).toBe(true)
|
|
expect(validate('href')('https://mail.mozdit.hu', { siblingData: { linkType: 'url' } })).toBe(true)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('MITHOME-113 English translation status', () => {
|
|
it.each([Home, About, Services, Contact, Common, LegalPages].map((d) => [d.slug, d] as const))(
|
|
'should give %s a shared sidebar status that defaults to "none"',
|
|
(_slug, doc) => {
|
|
const field = findField(doc.fields, 'enTranslationStatus') as unknown as {
|
|
type: string
|
|
localized?: boolean
|
|
defaultValue: string
|
|
options: { value: string }[]
|
|
admin: { position: string }
|
|
}
|
|
expect(field).toMatchObject({ type: 'select', defaultValue: 'none', admin: { position: 'sidebar' } })
|
|
expect(field.localized).toBeUndefined()
|
|
expect(field.options.map((o) => o.value)).toEqual(['none', 'ai-draft', 'approved'])
|
|
},
|
|
)
|
|
})
|
|
|
|
describe('MITHOME-113 legal validation gate', () => {
|
|
type Validate = (value: unknown, opts: { siblingData: Record<string, unknown> }) => true | string
|
|
const statusOf = (doc: { fields: unknown[] }) => findField(doc.fields, 'enTranslationStatus') as unknown as { validate?: Validate }
|
|
|
|
it('should block approving a legal page without a validation record', () => {
|
|
expect(statusOf(LegalPages).validate?.('approved', { siblingData: {} })).toEqual(expect.any(String))
|
|
expect(findField(LegalPages.fields, 'legalValidation')).toMatchObject({ type: 'group' })
|
|
})
|
|
|
|
it.each([Home, About, Services, Contact, Common].map((g) => [g.slug, g] as const))(
|
|
'should not add the legal rule to the %s global',
|
|
(_slug, global) => {
|
|
expect(statusOf(global).validate).toBeUndefined()
|
|
expect(findField(global.fields, 'legalValidation')).toBeUndefined()
|
|
},
|
|
)
|
|
})
|