From 1154bd365060195c6f897667879c4d31b3995f19 Mon Sep 17 00:00:00 2001 From: jdawg093 <49189518+jdawg093@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:22:49 +1100 Subject: [PATCH 1/3] OB-2228 # Added civic rec workflow event validation --- CHANGELOG.md | 1 + package-lock.json | 2 +- src/lib/forms-schema/index.ts | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) 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..177a082d 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#0ac777ad2ef449dd0db9466a775963e33b55c3e9", "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..cc8929d3 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.any().strip(), }), ...formEventBaseSchema, }) From 2c5e3fd8dbe491cf16c6bb8ae2bd6102ba3a24b9 Mon Sep 17 00:00:00 2001 From: jdawg093 <49189518+jdawg093@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:28:56 +1100 Subject: [PATCH 2/3] OB-2228 # Updated tests --- tests/forms-schema/forms-schema-form-events.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/forms-schema/forms-schema-form-events.test.ts b/tests/forms-schema/forms-schema-form-events.test.ts index 75a85aa1..2281b90b 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"', () => { From 0b00507f8a9bc38eddc94c003365c17367cb0a0a Mon Sep 17 00:00:00 2001 From: jdawg093 <49189518+jdawg093@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:59:42 +1100 Subject: [PATCH 3/3] OB-2228 # Added unit tests, changed schema validation --- package-lock.json | 2 +- src/lib/forms-schema/index.ts | 2 +- .../forms-schema-form-events.test.ts | 52 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 177a082d..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#0ac777ad2ef449dd0db9466a775963e33b55c3e9", + "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 cc8929d3..c7f3f15d 100644 --- a/src/lib/forms-schema/index.ts +++ b/src/lib/forms-schema/index.ts @@ -483,7 +483,7 @@ export const WorkflowEventSchema = Joi.object().keys({ }) .when('type', { is: 'CIVIC_REC_COMPLETE_CHECKOUT', - then: Joi.any().strip(), + 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 2281b90b..2245a2f7 100644 --- a/tests/forms-schema/forms-schema-form-events.test.ts +++ b/tests/forms-schema/forms-schema-form-events.test.ts @@ -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',