diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f197cad..a05a501f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package-lock.json b/package-lock.json index bf31b310..71083b0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2858,7 +2858,7 @@ }, "node_modules/@oneblink/types": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/oneblink/types.git#cccdab4b7b6c4a7e9cca4ee37b9e4d0d423d59a9", + "resolved": "git+ssh://git@github.com/oneblink/types.git#2267e0f8ffb8a414814db1682cfc39eb4614114b", "dev": true, "license": "GPL-3.0-only", "dependencies": { diff --git a/src/lib/forms-schema/index.ts b/src/lib/forms-schema/index.ts index a30b98c3..c7f3f15d 100644 --- a/src/lib/forms-schema/index.ts +++ b/src/lib/forms-schema/index.ts @@ -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({ @@ -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, }) diff --git a/tests/forms-schema/forms-schema-form-events.test.ts b/tests/forms-schema/forms-schema-form-events.test.ts index 75a85aa1..2245a2f7 100644 --- a/tests/forms-schema/forms-schema-form-events.test.ts +++ b/tests/forms-schema/forms-schema-form-events.test.ts @@ -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"', () => { @@ -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"', () => { @@ -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"', () => { @@ -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"', () => { @@ -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"', () => { @@ -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"', () => { @@ -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',