Skip to content

Commit 0b00507

Browse files
committed
OB-2228 # Added unit tests, changed schema validation
1 parent 2c5e3fd commit 0b00507

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/forms-schema/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ export const WorkflowEventSchema = Joi.object().keys({
483483
})
484484
.when('type', {
485485
is: 'CIVIC_REC_COMPLETE_CHECKOUT',
486-
then: Joi.any().strip(),
486+
then: Joi.object().keys({}),
487487
}),
488488
...formEventBaseSchema,
489489
})

tests/forms-schema/forms-schema-form-events.test.ts

+52
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,58 @@ describe('SHAREPOINT_STORE_FILES', () => {
482482
})
483483
})
484484

485+
describe('CIVIC_REC_COMPLETE_CHECKOUT', () => {
486+
const validSubmissionEvent = {
487+
type: 'CIVIC_REC_COMPLETE_CHECKOUT',
488+
configuration: {},
489+
}
490+
it('should allow empty object as the configuration', () => {
491+
const form = validateFormThrowError({
492+
...defaultForm,
493+
submissionEvents: [validSubmissionEvent],
494+
})
495+
496+
expect(form.submissionEvents[0]).toEqual({
497+
...validSubmissionEvent,
498+
conditionallyExecute: false,
499+
requiresAllConditionallyExecutePredicates: false,
500+
configuration: {},
501+
})
502+
})
503+
504+
it('should strip out any additional data in the configuration', () => {
505+
const form = validateFormThrowError({
506+
...defaultForm,
507+
submissionEvents: [
508+
{
509+
...validSubmissionEvent,
510+
configuration: { fakeVariable: "I'm fake!" },
511+
},
512+
],
513+
})
514+
515+
expect(form.submissionEvents[0]).toEqual({
516+
...validSubmissionEvent,
517+
conditionallyExecute: false,
518+
requiresAllConditionallyExecutePredicates: false,
519+
configuration: {},
520+
})
521+
})
522+
523+
it('should fail without empty configuration on the submission event', () => {
524+
expect(() =>
525+
validateFormThrowError({
526+
...defaultForm,
527+
submissionEvents: [
528+
{
529+
type: 'CIVIC_REC_COMPLETE_CHECKOUT',
530+
},
531+
],
532+
}),
533+
).toThrow('"submissionEvents[0].configuration" is required')
534+
})
535+
})
536+
485537
describe('PDF configuration', () => {
486538
const submissionEvent = {
487539
type: 'PDF',

0 commit comments

Comments
 (0)