Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OB-2228 # Added civic rec workflow event validation #564

Merged
merged 3 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- custom pdf read only validation
- Civic Rec Workflow Event validation

## [11.0.1] - 2025-03-19

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/lib/forms-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export const formWorkflowEventTypes: SubmissionEventTypes.FormWorkflowEventType[
'FRESHDESK_ADD_NOTE_TO_TICKET',
'SHAREPOINT_CREATE_LIST_ITEM',
'SHAREPOINT_STORE_FILES',
'CIVIC_REC_COMPLETE_CHECKOUT',
]

export const WorkflowEventSchema = Joi.object().keys({
Expand Down Expand Up @@ -479,6 +480,10 @@ export const WorkflowEventSchema = Joi.object().keys({
excludeAttachments: Joi.boolean().default(false),
...pdfSubmissionEventConfiguration,
}),
})
.when('type', {
is: 'CIVIC_REC_COMPLETE_CHECKOUT',
then: Joi.object().keys({}),
}),
...formEventBaseSchema,
})
Expand Down
64 changes: 58 additions & 6 deletions tests/forms-schema/forms-schema-form-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Scheduling events should throw errors when not passed to "schedulingEv
submissionEvents: [schedulingEvent],
}),
).toThrow(
'"submissionEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES]',
'"submissionEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES, CIVIC_REC_COMPLETE_CHECKOUT]',
)
})
test('SCHEDULING form event should error when being passed to "paymentEvents"', () => {
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('Payment events should throw errors when not passed to "paymentEvents"
submissionEvents: [paymentEvent],
}),
).toThrow(
'"submissionEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES]',
'"submissionEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES, CIVIC_REC_COMPLETE_CHECKOUT]',
)
})
test('Payment form event should error when being passed to "schedulingEvents"', () => {
Expand Down Expand Up @@ -343,7 +343,7 @@ describe('"draftEvents" and "approvalEvents" should allow only submission events
draftEvents: [paymentEvent],
}),
).toThrow(
'"draftEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES]',
'"draftEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES, CIVIC_REC_COMPLETE_CHECKOUT]',
)
})
test('SCHEDULING form event should error when being passed to "draftEvents"', () => {
Expand All @@ -353,7 +353,7 @@ describe('"draftEvents" and "approvalEvents" should allow only submission events
draftEvents: [schedulingEvent],
}),
).toThrow(
'"draftEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES]',
'"draftEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES, CIVIC_REC_COMPLETE_CHECKOUT]',
)
})
test('Should not error when passing submissionEvents to "draftEvents"', () => {
Expand All @@ -372,7 +372,7 @@ describe('"draftEvents" and "approvalEvents" should allow only submission events
approvalEvents: [paymentEvent],
}),
).toThrow(
'"approvalEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES]',
'"approvalEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES, CIVIC_REC_COMPLETE_CHECKOUT]',
)
})
test('SCHEDULING form event should error when being passed to "approvalEvents"', () => {
Expand All @@ -382,7 +382,7 @@ describe('"draftEvents" and "approvalEvents" should allow only submission events
approvalEvents: [schedulingEvent],
}),
).toThrow(
'"approvalEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES]',
'"approvalEvents[0].type" must be one of [CALLBACK, POWER_AUTOMATE_FLOW, CP_INTEGRATION_HUB_WEBHOOK, PDF, EMAIL, ONEBLINK_API, TRIM, CP_HCMS, CIVICA_CRM, FRESHDESK_CREATE_TICKET, FRESHDESK_ADD_NOTE_TO_TICKET, SHAREPOINT_CREATE_LIST_ITEM, SHAREPOINT_STORE_FILES, CIVIC_REC_COMPLETE_CHECKOUT]',
)
})
test('Should not error when passing submissionEvents to "approvalEvents"', () => {
Expand Down Expand Up @@ -482,6 +482,58 @@ describe('SHAREPOINT_STORE_FILES', () => {
})
})

describe('CIVIC_REC_COMPLETE_CHECKOUT', () => {
const validSubmissionEvent = {
type: 'CIVIC_REC_COMPLETE_CHECKOUT',
configuration: {},
}
it('should allow empty object as the configuration', () => {
const form = validateFormThrowError({
...defaultForm,
submissionEvents: [validSubmissionEvent],
})

expect(form.submissionEvents[0]).toEqual({
...validSubmissionEvent,
conditionallyExecute: false,
requiresAllConditionallyExecutePredicates: false,
configuration: {},
})
})

it('should strip out any additional data in the configuration', () => {
const form = validateFormThrowError({
...defaultForm,
submissionEvents: [
{
...validSubmissionEvent,
configuration: { fakeVariable: "I'm fake!" },
},
],
})

expect(form.submissionEvents[0]).toEqual({
...validSubmissionEvent,
conditionallyExecute: false,
requiresAllConditionallyExecutePredicates: false,
configuration: {},
})
})

it('should fail without empty configuration on the submission event', () => {
expect(() =>
validateFormThrowError({
...defaultForm,
submissionEvents: [
{
type: 'CIVIC_REC_COMPLETE_CHECKOUT',
},
],
}),
).toThrow('"submissionEvents[0].configuration" is required')
})
})

describe('PDF configuration', () => {
const submissionEvent = {
type: 'PDF',
Expand Down