submitForm reads forms.consentFieldName from ipalKit options
The option was typed but never read. An explicit argument still wins. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
38c1d9215e
commit
4585e0fc69
@@ -10,7 +10,8 @@ import { validateSubmission } from './validateSubmission.js'
|
||||
export type SubmitFormArgs = {
|
||||
/**
|
||||
* Name of the GDPR consent checkbox. A field with this name must be checked
|
||||
* for the submission to succeed (enforced server-side). Defaults to 'consent'.
|
||||
* for the submission to succeed (enforced server-side). Defaults to
|
||||
* ipalKit({ forms: { consentFieldName } }), then 'consent'.
|
||||
*/
|
||||
consentFieldName?: string
|
||||
/** Submitted field data — shape matches the form's fields. */
|
||||
@@ -129,7 +130,10 @@ export async function submitForm({
|
||||
|
||||
// 3. Validate against the form's schema. A public endpoint can't trust the
|
||||
// shape of `data` — drop unknown keys, enforce required, cap length.
|
||||
const validation = await validateSubmission(payload, formId, data, consentFieldName)
|
||||
// Explicit argument → ipalKit({ forms: { consentFieldName } }) → 'consent'.
|
||||
const configured = (payload.config?.custom as { ipal?: { consentFieldName?: unknown } } | undefined)?.ipal?.consentFieldName
|
||||
const consentField = consentFieldName ?? (typeof configured === 'string' && configured ? configured : undefined)
|
||||
const validation = await validateSubmission(payload, formId, data, consentField)
|
||||
if (!validation.ok) {
|
||||
if (validation.reason === 'not_found') {
|
||||
return { reason: 'not_found', success: false }
|
||||
|
||||
@@ -132,6 +132,18 @@ describe('submitForm — other gates', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('ipalKit forms.consentFieldName (payload.config.custom) names the consent field', async () => {
|
||||
const { payload } = fakePayload({ forms: { f: { fields: [{ name: 'zgoda', blockType: 'checkbox' }] } } })
|
||||
Object.assign(payload, { config: { custom: { ipal: { consentFieldName: 'zgoda' } } } })
|
||||
expect(await submitForm({ data: { zgoda: false }, formId: 'f', ip: nextIp(), payload })).toEqual({
|
||||
field: 'zgoda',
|
||||
reason: 'consent',
|
||||
success: false,
|
||||
})
|
||||
// an explicit argument still wins
|
||||
expect((await submitForm({ consentFieldName: 'other', data: { zgoda: false }, formId: 'f', ip: nextIp(), payload })).success).toBe(true)
|
||||
})
|
||||
|
||||
test('consent must be checked', async () => {
|
||||
const { payload } = fakePayload({ forms })
|
||||
expect(await submitForm({ data: { ...data, consent: false }, formId: 'contact', ip: nextIp(), payload })).toEqual({
|
||||
|
||||
Reference in New Issue
Block a user