From 5c6f0bd104cdd2143d92e7becf36d0f989be4409 Mon Sep 17 00:00:00 2001 From: David Porter Date: Fri, 17 Jan 2025 12:07:03 +1100 Subject: [PATCH 1/6] ON-46214 # set preventPayment prop on FormSubmissionResult --- src/scheduling-service.ts | 3 ++- src/services/schedulingHandlers.ts | 5 +++++ src/services/submit.ts | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/scheduling-service.ts b/src/scheduling-service.ts index c2058920..37218431 100644 --- a/src/scheduling-service.ts +++ b/src/scheduling-service.ts @@ -45,7 +45,8 @@ async function getSchedulingFormSubmissionResult( ) } - if (paymentReceiptUrl) { + //@ts-expect-error TODO update types + if (paymentReceiptUrl && !formSubmissionResult.preventPayment) { await setSchedulingBooking(schedulingBooking) const paymentSubmissionEventConfiguration = checkForPaymentSubmissionEvent(formSubmissionResult) diff --git a/src/services/schedulingHandlers.ts b/src/services/schedulingHandlers.ts index b237d16b..567c62f2 100644 --- a/src/services/schedulingHandlers.ts +++ b/src/services/schedulingHandlers.ts @@ -11,6 +11,7 @@ import { SchedulingUrlConfiguration } from '../types/scheduling' const SCHEDULING_SUBMISSION_RESULT_KEY = 'SCHEDULING_SUBMISSION_RESULT' type SchedulingSubmissionResult = { formSubmissionResult: FormSubmissionResult + preventPayment: boolean paymentReceiptUrl: string | undefined paymentFormUrl: string | undefined } @@ -106,12 +107,14 @@ async function handleSchedulingSubmissionEvent({ schedulingUrlConfiguration, paymentReceiptUrl, paymentFormUrl, + preventPayment, }: { formSubmissionResult: FormSubmissionResult schedulingSubmissionEvent: SubmissionEventTypes.FormSchedulingEvent schedulingUrlConfiguration: SchedulingUrlConfiguration paymentReceiptUrl: string | undefined paymentFormUrl: string | undefined + preventPayment: boolean }): Promise> { console.log( 'Attempting to handle submission with scheduling submission event', @@ -140,6 +143,8 @@ async function handleSchedulingSubmissionEvent({ formSubmissionResult: { ...formSubmissionResult, scheduling, + //@ts-expect-error TODO update types + preventPayment, }, paymentReceiptUrl, paymentFormUrl, diff --git a/src/services/submit.ts b/src/services/submit.ts index 2dce168a..fe8277f4 100644 --- a/src/services/submit.ts +++ b/src/services/submit.ts @@ -183,6 +183,7 @@ export default async function submit({ schedulingUrlConfiguration, paymentReceiptUrl, paymentFormUrl, + preventPayment: data.preventPayment, }) } else if ( paymentSubmissionEventConfiguration && From ea78ccbaf58d49683ec7310f3418a04fad4080c3 Mon Sep 17 00:00:00 2001 From: David Porter Date: Fri, 17 Jan 2025 15:08:57 +1100 Subject: [PATCH 2/6] ON-46214 # add jest tests --- src/scheduling-service.ts | 55 +++- tests/scheduling-service.test.ts | 543 +++++++++++++++++++++++++++++++ 2 files changed, 584 insertions(+), 14 deletions(-) create mode 100644 tests/scheduling-service.test.ts diff --git a/src/scheduling-service.ts b/src/scheduling-service.ts index 37218431..266b3b31 100644 --- a/src/scheduling-service.ts +++ b/src/scheduling-service.ts @@ -12,6 +12,40 @@ import { setSchedulingBooking, } from './services/schedulingHandlers' +async function getPaymentConfiguration({ + paymentReceiptUrl, + paymentFormUrl, + formSubmissionResult, + schedulingBooking, +}: { + paymentReceiptUrl: string | undefined + paymentFormUrl: string | undefined + formSubmissionResult: FormSubmissionResult + schedulingBooking: SchedulingBooking +}) { + //@ts-expect-error TODO update types + if (formSubmissionResult.preventPayment) { + return null + } + + if (paymentReceiptUrl) { + await setSchedulingBooking(schedulingBooking) + const paymentSubmissionEventConfiguration = + checkForPaymentSubmissionEvent(formSubmissionResult) + console.log(paymentSubmissionEventConfiguration) + if (paymentSubmissionEventConfiguration) { + return await handlePaymentSubmissionEvent({ + ...paymentSubmissionEventConfiguration, + formSubmissionResult, + paymentReceiptUrl, + paymentFormUrl, + }) + } + } + + return null +} + async function getSchedulingFormSubmissionResult( submissionId: string, schedulingBooking: SchedulingBooking, @@ -45,20 +79,12 @@ async function getSchedulingFormSubmissionResult( ) } - //@ts-expect-error TODO update types - if (paymentReceiptUrl && !formSubmissionResult.preventPayment) { - await setSchedulingBooking(schedulingBooking) - const paymentSubmissionEventConfiguration = - checkForPaymentSubmissionEvent(formSubmissionResult) - if (paymentSubmissionEventConfiguration) { - formSubmissionResult.payment = await handlePaymentSubmissionEvent({ - ...paymentSubmissionEventConfiguration, - formSubmissionResult, - paymentReceiptUrl, - paymentFormUrl, - }) - } - } + formSubmissionResult.payment = await getPaymentConfiguration({ + paymentFormUrl, + paymentReceiptUrl, + formSubmissionResult, + schedulingBooking, + }) await removeSchedulingSubmissionResult() @@ -271,4 +297,5 @@ export { handleCancelSchedulingBookingQuerystring, createNylasExistingBookingSession, createNylasNewBookingSession, + getSchedulingFormSubmissionResult, } diff --git a/tests/scheduling-service.test.ts b/tests/scheduling-service.test.ts new file mode 100644 index 00000000..0c043595 --- /dev/null +++ b/tests/scheduling-service.test.ts @@ -0,0 +1,543 @@ +import { FormTypes } from '@oneblink/types' +import { getSchedulingFormSubmissionResult } from '../src/scheduling-service' +import { getSchedulingSubmissionResult } from '../src/services/schedulingHandlers' +import { handlePaymentSubmissionEvent } from '../src/payment-service' + +jest.mock('../src/services/schedulingHandlers') +jest.mock('../src/payment-service', () => ({ + ...jest.requireActual('../src/payment-service'), + handlePaymentSubmissionEvent: jest.fn(), +})) + +const formDefinition: FormTypes.Form = { + id: 1, + name: 'Form', + description: 'A form', + organisationId: 'ORGANISATION_ID', + formsAppEnvironmentId: 1, + formsAppIds: [], + elements: [ + { + type: 'calculation', + id: 'ELEMENT_ID', + name: 'calc', + label: 'Calculon', + conditionallyShow: false, + defaultValue: '10', + calculation: '10', + }, + ], + submissionEvents: [], + schedulingEvents: [ + { + type: 'NYLAS', + configuration: { + nylasGrantId: 'grant1', + nylasConfigurationId: 'config1', + }, + }, + ], + paymentEvents: [ + { + type: 'WESTPAC_QUICK_STREAM', + configuration: { + elementId: 'ELEMENT_ID', + environmentId: 'ENVIRONMENT_ID', + customerReferenceNumber: 'crn', + }, + }, + ], + tags: [], + isAuthenticated: true, + isMultiPage: false, + postSubmissionAction: 'BACK', + cancelAction: 'BACK', + createdAt: '', + updatedAt: '', +} + +const SUBMISSION_ID = 'abc123' + +describe('sheduling service', () => { + describe('getSchedulingFormSubmissionResult', () => { + it('should throw an error if scheduling result config not found', () => { + jest.mocked(getSchedulingSubmissionResult).mockResolvedValue(null) + expect( + getSchedulingFormSubmissionResult(SUBMISSION_ID, { + submissionId: SUBMISSION_ID, + startTime: new Date(), + endTime: new Date(), + location: undefined, + isReschedule: false, + }), + ).rejects.toThrow( + 'It looks like you are attempting to view a scheduling receipt for an unknown booking.', + ) + }) + + it('should fail if there is no formSubmissionResult', () => { + jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ + paymentReceiptUrl: 'RECEIPT_URL', + paymentFormUrl: 'FORM_URL', + //@ts-expect-error setting to empty for test + formSubmissionResult: null, + }) + + expect( + getSchedulingFormSubmissionResult(SUBMISSION_ID, { + submissionId: SUBMISSION_ID, + startTime: new Date(), + endTime: new Date(), + location: undefined, + isReschedule: false, + }), + ).rejects.toThrow( + 'It looks like you are attempting to view a scheduling receipt for a misconfigured booking.', + ) + }) + + it('should fail if formSubmissionResult scheduling prop is falsey', () => { + jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ + paymentReceiptUrl: 'RECEIPT_URL', + paymentFormUrl: 'FORM_URL', + formSubmissionResult: { + //@ts-expect-error update TYPES + preventPayment: false, + submissionId: SUBMISSION_ID, + submission: { + calc: 10, + }, + definition: formDefinition, + preFillFormDataId: null, + scheduling: null, + payment: null, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }, + }) + + expect( + getSchedulingFormSubmissionResult(SUBMISSION_ID, { + submissionId: SUBMISSION_ID, + startTime: new Date(), + endTime: new Date(), + location: undefined, + isReschedule: false, + }), + ).rejects.toThrow( + 'It looks like you are attempting to view a scheduling receipt for a misconfigured booking.', + ) + }) + + it('should fail if formSubmissionResult scheduling.submissionEvent is falsey', () => { + jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ + paymentReceiptUrl: 'RECEIPT_URL', + paymentFormUrl: 'FORM_URL', + formSubmissionResult: { + preventPayment: false, + submissionId: SUBMISSION_ID, + submission: { + calc: 10, + }, + definition: formDefinition, + preFillFormDataId: null, + scheduling: { + bookingUrl: 'BOOKING_URL', + //@ts-expect-error + submissionEvent: null, + }, + payment: null, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }, + }) + + expect( + getSchedulingFormSubmissionResult(SUBMISSION_ID, { + submissionId: SUBMISSION_ID, + startTime: new Date(), + endTime: new Date(), + location: undefined, + isReschedule: false, + }), + ).rejects.toThrow( + 'It looks like you are attempting to view a scheduling receipt for a misconfigured booking.', + ) + }) + + it('should throw if submissionId and formSubmissionResult.submissionId are mismatched', () => { + jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ + paymentReceiptUrl: 'RECEIPT_URL', + paymentFormUrl: 'FORM_URL', + formSubmissionResult: { + //@ts-expect-error update TYPES + preventPayment: false, + submissionId: 'def456', + submission: { + calc: 10, + }, + definition: formDefinition, + preFillFormDataId: null, + scheduling: { + bookingUrl: 'BOOKING_URL', + submissionEvent: { + type: 'NYLAS', + configuration: { + nylasGrantId: 'grant1', + nylasConfigurationId: 'config1', + }, + }, + }, + payment: null, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }, + }) + + expect( + getSchedulingFormSubmissionResult(SUBMISSION_ID, { + submissionId: SUBMISSION_ID, + startTime: new Date(), + endTime: new Date(), + location: undefined, + isReschedule: false, + }), + ).rejects.toThrow( + 'It looks like you are attempting to view a scheduling receipt for the incorrect booking.', + ) + }) + + it('should not add payment configuration if prevent payment is true', async () => { + jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ + paymentReceiptUrl: 'RECEIPT_URL', + paymentFormUrl: 'FORM_URL', + formSubmissionResult: { + //@ts-expect-error update types + preventPayment: true, + submissionId: SUBMISSION_ID, + submission: { + calc: 10, + }, + definition: formDefinition, + preFillFormDataId: null, + scheduling: { + bookingUrl: 'BOOKING_URL', + submissionEvent: { + type: 'NYLAS', + configuration: { + nylasGrantId: 'grant1', + nylasConfigurationId: 'config1', + }, + }, + }, + payment: { + amount: 10, + paymentFormUrl: 'FORM_URL', + paymentReceiptUrl: 'RECEIPT_URL', + hostedFormUrl: 'HOSTED_FORM_URL', + submissionEvent: { + type: 'WESTPAC_QUICK_STREAM', + configuration: { + elementId: 'ELEMENT_ID', + environmentId: 'ENVIRONMENT_ID', + customerReferenceNumber: 'crn', + }, + }, + }, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }, + }) + + expect( + await getSchedulingFormSubmissionResult(SUBMISSION_ID, { + submissionId: SUBMISSION_ID, + startTime: new Date(), + endTime: new Date(), + location: undefined, + isReschedule: false, + }), + ).toEqual({ + preventPayment: true, + submissionId: SUBMISSION_ID, + submission: { + calc: 10, + }, + definition: formDefinition, + preFillFormDataId: null, + scheduling: { + bookingUrl: 'BOOKING_URL', + submissionEvent: { + type: 'NYLAS', + configuration: { + nylasGrantId: 'grant1', + nylasConfigurationId: 'config1', + }, + }, + }, + payment: null, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }) + }) + + it('should not add payment configuration if there is no paymentReceiptUrl', async () => { + jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ + paymentReceiptUrl: undefined, + paymentFormUrl: 'FORM_URL', + formSubmissionResult: { + //@ts-expect-error update TYPES + preventPayment: false, + submissionId: SUBMISSION_ID, + submission: { + calc: 10, + }, + definition: formDefinition, + preFillFormDataId: null, + scheduling: { + bookingUrl: 'BOOKING_URL', + submissionEvent: { + type: 'NYLAS', + configuration: { + nylasGrantId: 'grant1', + nylasConfigurationId: 'config1', + }, + }, + }, + payment: { + amount: 10, + paymentFormUrl: 'FORM_URL', + paymentReceiptUrl: 'RECEIPT_URL', + hostedFormUrl: 'HOSTED_FORM_URL', + submissionEvent: { + type: 'WESTPAC_QUICK_STREAM', + configuration: { + elementId: 'ELEMENT_ID', + environmentId: 'ENVIRONMENT_ID', + customerReferenceNumber: 'crn', + }, + }, + }, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }, + }) + + expect( + await getSchedulingFormSubmissionResult(SUBMISSION_ID, { + submissionId: SUBMISSION_ID, + startTime: new Date(), + endTime: new Date(), + location: undefined, + isReschedule: false, + }), + ).toEqual({ + submissionId: SUBMISSION_ID, + submission: { + calc: 10, + }, + definition: formDefinition, + preFillFormDataId: null, + scheduling: { + bookingUrl: 'BOOKING_URL', + submissionEvent: { + type: 'NYLAS', + configuration: { + nylasGrantId: 'grant1', + nylasConfigurationId: 'config1', + }, + }, + }, + preventPayment: false, + payment: null, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }) + }) + + it('should not add payment configuration if there is no payment event', async () => { + jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ + paymentReceiptUrl: 'RECEIPT_URL', + paymentFormUrl: 'FORM_URL', + formSubmissionResult: { + //@ts-expect-error update TYPES + preventPayment: false, + submissionId: SUBMISSION_ID, + submission: { + calc: 10, + }, + definition: { ...formDefinition, paymentEvents: [] }, + preFillFormDataId: null, + scheduling: { + bookingUrl: 'BOOKING_URL', + submissionEvent: { + type: 'NYLAS', + configuration: { + nylasGrantId: 'grant1', + nylasConfigurationId: 'config1', + }, + }, + }, + payment: { + amount: 10, + paymentFormUrl: 'FORM_URL', + paymentReceiptUrl: 'RECEIPT_URL', + hostedFormUrl: 'HOSTED_FORM_URL', + submissionEvent: { + type: 'WESTPAC_QUICK_STREAM', + configuration: { + elementId: 'ELEMENT_ID', + environmentId: 'ENVIRONMENT_ID', + customerReferenceNumber: 'crn', + }, + }, + }, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }, + }) + + expect( + await getSchedulingFormSubmissionResult(SUBMISSION_ID, { + submissionId: SUBMISSION_ID, + startTime: new Date(), + endTime: new Date(), + location: undefined, + isReschedule: false, + }), + ).toEqual({ + submissionId: SUBMISSION_ID, + submission: { + calc: 10, + }, + definition: { ...formDefinition, paymentEvents: [] }, + preFillFormDataId: null, + scheduling: { + bookingUrl: 'BOOKING_URL', + submissionEvent: { + type: 'NYLAS', + configuration: { + nylasGrantId: 'grant1', + nylasConfigurationId: 'config1', + }, + }, + }, + payment: null, + preventPayment: false, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }) + }) + + it('should add payment configuration if there a payment event and paymentReceiptUrl', async () => { + jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ + paymentReceiptUrl: 'RECEIPT_URL', + paymentFormUrl: 'FORM_URL', + formSubmissionResult: { + //@ts-expect-error update TYPES + preventPayment: false, + submissionId: SUBMISSION_ID, + submission: { + calc: 10, + }, + definition: formDefinition, + preFillFormDataId: null, + scheduling: { + bookingUrl: 'BOOKING_URL', + submissionEvent: { + type: 'NYLAS', + configuration: { + nylasGrantId: 'grant1', + nylasConfigurationId: 'config1', + }, + }, + }, + payment: null, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }, + }) + + jest.mocked(handlePaymentSubmissionEvent).mockResolvedValue({ + amount: 10, + paymentFormUrl: 'FORM_URL', + paymentReceiptUrl: 'RECEIPT_URL', + hostedFormUrl: 'HOSTED_FORM_URL', + submissionEvent: { + type: 'WESTPAC_QUICK_STREAM', + configuration: { + elementId: 'ELEMENT_ID', + environmentId: 'ENVIRONMENT_ID', + customerReferenceNumber: 'crn', + }, + }, + }) + + expect( + await getSchedulingFormSubmissionResult(SUBMISSION_ID, { + submissionId: SUBMISSION_ID, + startTime: new Date(), + endTime: new Date(), + location: undefined, + isReschedule: false, + }), + ).toEqual({ + submissionId: SUBMISSION_ID, + submission: { + calc: 10, + }, + definition: formDefinition, + preFillFormDataId: null, + scheduling: { + bookingUrl: 'BOOKING_URL', + submissionEvent: { + type: 'NYLAS', + configuration: { + nylasGrantId: 'grant1', + nylasConfigurationId: 'config1', + }, + }, + }, + preventPayment: false, + payment: { + amount: 10, + paymentFormUrl: 'FORM_URL', + paymentReceiptUrl: 'RECEIPT_URL', + hostedFormUrl: 'HOSTED_FORM_URL', + submissionEvent: { + type: 'WESTPAC_QUICK_STREAM', + configuration: { + elementId: 'ELEMENT_ID', + environmentId: 'ENVIRONMENT_ID', + customerReferenceNumber: 'crn', + }, + }, + }, + submissionTimestamp: '2025-01-17T03:09:25.559Z', + isInPendingQueue: false, + isOffline: false, + isUploadingAttachments: false, + }) + }) + }) +}) From 750292d3b09a59c489b8614499cb7696fca88389 Mon Sep 17 00:00:00 2001 From: David Porter Date: Fri, 17 Jan 2025 15:14:59 +1100 Subject: [PATCH 3/6] ON-46214 # add type and remove TODOs --- src/scheduling-service.ts | 1 - src/services/schedulingHandlers.ts | 2 -- src/types/submissions.ts | 5 +++++ tests/scheduling-service.test.ts | 6 ------ 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/scheduling-service.ts b/src/scheduling-service.ts index 266b3b31..22bad02c 100644 --- a/src/scheduling-service.ts +++ b/src/scheduling-service.ts @@ -23,7 +23,6 @@ async function getPaymentConfiguration({ formSubmissionResult: FormSubmissionResult schedulingBooking: SchedulingBooking }) { - //@ts-expect-error TODO update types if (formSubmissionResult.preventPayment) { return null } diff --git a/src/services/schedulingHandlers.ts b/src/services/schedulingHandlers.ts index 567c62f2..cb76ac0f 100644 --- a/src/services/schedulingHandlers.ts +++ b/src/services/schedulingHandlers.ts @@ -11,7 +11,6 @@ import { SchedulingUrlConfiguration } from '../types/scheduling' const SCHEDULING_SUBMISSION_RESULT_KEY = 'SCHEDULING_SUBMISSION_RESULT' type SchedulingSubmissionResult = { formSubmissionResult: FormSubmissionResult - preventPayment: boolean paymentReceiptUrl: string | undefined paymentFormUrl: string | undefined } @@ -143,7 +142,6 @@ async function handleSchedulingSubmissionEvent({ formSubmissionResult: { ...formSubmissionResult, scheduling, - //@ts-expect-error TODO update types preventPayment, }, paymentReceiptUrl, diff --git a/src/types/submissions.ts b/src/types/submissions.ts index 8ea8085b..c255b498 100644 --- a/src/types/submissions.ts +++ b/src/types/submissions.ts @@ -158,6 +158,11 @@ export type FormSubmissionResult = FormSubmission & { isUploadingAttachments: boolean /** Exists if the form allows PDF download */ downloadSubmissionPdfUrl?: string + /** + * `true` if true will skip payment even if the payment prop is supplied and a + * payment event exists + */ + preventPayment: boolean } export type PendingFormSubmission = Omit & { diff --git a/tests/scheduling-service.test.ts b/tests/scheduling-service.test.ts index 0c043595..0dde1853 100644 --- a/tests/scheduling-service.test.ts +++ b/tests/scheduling-service.test.ts @@ -101,7 +101,6 @@ describe('sheduling service', () => { paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', formSubmissionResult: { - //@ts-expect-error update TYPES preventPayment: false, submissionId: SUBMISSION_ID, submission: { @@ -174,7 +173,6 @@ describe('sheduling service', () => { paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', formSubmissionResult: { - //@ts-expect-error update TYPES preventPayment: false, submissionId: 'def456', submission: { @@ -218,7 +216,6 @@ describe('sheduling service', () => { paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', formSubmissionResult: { - //@ts-expect-error update types preventPayment: true, submissionId: SUBMISSION_ID, submission: { @@ -296,7 +293,6 @@ describe('sheduling service', () => { paymentReceiptUrl: undefined, paymentFormUrl: 'FORM_URL', formSubmissionResult: { - //@ts-expect-error update TYPES preventPayment: false, submissionId: SUBMISSION_ID, submission: { @@ -374,7 +370,6 @@ describe('sheduling service', () => { paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', formSubmissionResult: { - //@ts-expect-error update TYPES preventPayment: false, submissionId: SUBMISSION_ID, submission: { @@ -452,7 +447,6 @@ describe('sheduling service', () => { paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', formSubmissionResult: { - //@ts-expect-error update TYPES preventPayment: false, submissionId: SUBMISSION_ID, submission: { From 6a74334c4dc95501a96033eea411b8e2fd68ad0c Mon Sep 17 00:00:00 2001 From: David Porter Date: Fri, 17 Jan 2025 15:18:32 +1100 Subject: [PATCH 4/6] ON-46214 # remove log and add to if --- src/scheduling-service.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/scheduling-service.ts b/src/scheduling-service.ts index 22bad02c..bf9f7c5a 100644 --- a/src/scheduling-service.ts +++ b/src/scheduling-service.ts @@ -23,23 +23,20 @@ async function getPaymentConfiguration({ formSubmissionResult: FormSubmissionResult schedulingBooking: SchedulingBooking }) { - if (formSubmissionResult.preventPayment) { + if (formSubmissionResult.preventPayment || !paymentReceiptUrl) { return null } - if (paymentReceiptUrl) { - await setSchedulingBooking(schedulingBooking) - const paymentSubmissionEventConfiguration = - checkForPaymentSubmissionEvent(formSubmissionResult) - console.log(paymentSubmissionEventConfiguration) - if (paymentSubmissionEventConfiguration) { - return await handlePaymentSubmissionEvent({ - ...paymentSubmissionEventConfiguration, - formSubmissionResult, - paymentReceiptUrl, - paymentFormUrl, - }) - } + await setSchedulingBooking(schedulingBooking) + const paymentSubmissionEventConfiguration = + checkForPaymentSubmissionEvent(formSubmissionResult) + if (paymentSubmissionEventConfiguration) { + return await handlePaymentSubmissionEvent({ + ...paymentSubmissionEventConfiguration, + formSubmissionResult, + paymentReceiptUrl, + paymentFormUrl, + }) } return null From b34890de379a3f3f432cc988b6c868794e75897a Mon Sep 17 00:00:00 2001 From: David Porter Date: Fri, 17 Jan 2025 15:29:07 +1100 Subject: [PATCH 5/6] ON-46214 # move preventPayment to SchedulingSubmissionResult --- src/scheduling-service.ts | 13 ++++++++++--- src/services/schedulingHandlers.ts | 3 ++- src/services/submit.ts | 5 +++++ src/types/submissions.ts | 5 ----- tests/scheduling-service.test.ts | 17 ++++++----------- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/scheduling-service.ts b/src/scheduling-service.ts index bf9f7c5a..4a244b26 100644 --- a/src/scheduling-service.ts +++ b/src/scheduling-service.ts @@ -15,15 +15,17 @@ import { async function getPaymentConfiguration({ paymentReceiptUrl, paymentFormUrl, + preventPayment, formSubmissionResult, schedulingBooking, }: { paymentReceiptUrl: string | undefined paymentFormUrl: string | undefined + preventPayment: boolean formSubmissionResult: FormSubmissionResult schedulingBooking: SchedulingBooking }) { - if (formSubmissionResult.preventPayment || !paymentReceiptUrl) { + if (preventPayment || !paymentReceiptUrl) { return null } @@ -57,8 +59,12 @@ async function getSchedulingFormSubmissionResult( ) } - const { formSubmissionResult, paymentReceiptUrl, paymentFormUrl } = - schedulingSubmissionResultConfiguration + const { + formSubmissionResult, + paymentReceiptUrl, + paymentFormUrl, + preventPayment, + } = schedulingSubmissionResultConfiguration if ( !formSubmissionResult || !formSubmissionResult.scheduling || @@ -78,6 +84,7 @@ async function getSchedulingFormSubmissionResult( formSubmissionResult.payment = await getPaymentConfiguration({ paymentFormUrl, paymentReceiptUrl, + preventPayment, formSubmissionResult, schedulingBooking, }) diff --git a/src/services/schedulingHandlers.ts b/src/services/schedulingHandlers.ts index cb76ac0f..49f465cc 100644 --- a/src/services/schedulingHandlers.ts +++ b/src/services/schedulingHandlers.ts @@ -13,6 +13,7 @@ type SchedulingSubmissionResult = { formSubmissionResult: FormSubmissionResult paymentReceiptUrl: string | undefined paymentFormUrl: string | undefined + preventPayment: boolean } export async function getSchedulingSubmissionResult(): Promise { return await utilsService.getLocalForageItem(SCHEDULING_SUBMISSION_RESULT_KEY) @@ -142,10 +143,10 @@ async function handleSchedulingSubmissionEvent({ formSubmissionResult: { ...formSubmissionResult, scheduling, - preventPayment, }, paymentReceiptUrl, paymentFormUrl, + preventPayment, }) return scheduling diff --git a/src/services/submit.ts b/src/services/submit.ts index fe8277f4..f4e4f132 100644 --- a/src/services/submit.ts +++ b/src/services/submit.ts @@ -105,6 +105,7 @@ export default async function submit({ submissionTimestamp: null, submissionId: null, payment: null, + preventPayment: false, scheduling: null, isUploadingAttachments: false, }) @@ -127,6 +128,7 @@ export default async function submit({ submissionTimestamp: null, submissionId: null, payment: null, + preventPayment: false, scheduling: null, isUploadingAttachments: true, }) @@ -141,6 +143,7 @@ export default async function submit({ submissionTimestamp: null, submissionId: null, payment: null, + preventPayment: false, scheduling: null, isUploadingAttachments: true, }) @@ -231,6 +234,7 @@ export default async function submit({ payment: null, scheduling: null, isUploadingAttachments: false, + preventPayment: false, }) } @@ -247,6 +251,7 @@ export default async function submit({ payment: null, scheduling: null, isUploadingAttachments: false, + preventPayment: false, }) } diff --git a/src/types/submissions.ts b/src/types/submissions.ts index c255b498..8ea8085b 100644 --- a/src/types/submissions.ts +++ b/src/types/submissions.ts @@ -158,11 +158,6 @@ export type FormSubmissionResult = FormSubmission & { isUploadingAttachments: boolean /** Exists if the form allows PDF download */ downloadSubmissionPdfUrl?: string - /** - * `true` if true will skip payment even if the payment prop is supplied and a - * payment event exists - */ - preventPayment: boolean } export type PendingFormSubmission = Omit & { diff --git a/tests/scheduling-service.test.ts b/tests/scheduling-service.test.ts index 0dde1853..73ac6b80 100644 --- a/tests/scheduling-service.test.ts +++ b/tests/scheduling-service.test.ts @@ -100,8 +100,8 @@ describe('sheduling service', () => { jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', + preventPayment: false, formSubmissionResult: { - preventPayment: false, submissionId: SUBMISSION_ID, submission: { calc: 10, @@ -135,7 +135,6 @@ describe('sheduling service', () => { paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', formSubmissionResult: { - preventPayment: false, submissionId: SUBMISSION_ID, submission: { calc: 10, @@ -172,8 +171,8 @@ describe('sheduling service', () => { jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', + preventPayment: false, formSubmissionResult: { - preventPayment: false, submissionId: 'def456', submission: { calc: 10, @@ -215,8 +214,8 @@ describe('sheduling service', () => { jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', + preventPayment: true, formSubmissionResult: { - preventPayment: true, submissionId: SUBMISSION_ID, submission: { calc: 10, @@ -263,7 +262,6 @@ describe('sheduling service', () => { isReschedule: false, }), ).toEqual({ - preventPayment: true, submissionId: SUBMISSION_ID, submission: { calc: 10, @@ -292,8 +290,8 @@ describe('sheduling service', () => { jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ paymentReceiptUrl: undefined, paymentFormUrl: 'FORM_URL', + preventPayment: false, formSubmissionResult: { - preventPayment: false, submissionId: SUBMISSION_ID, submission: { calc: 10, @@ -356,7 +354,6 @@ describe('sheduling service', () => { }, }, }, - preventPayment: false, payment: null, submissionTimestamp: '2025-01-17T03:09:25.559Z', isInPendingQueue: false, @@ -369,8 +366,8 @@ describe('sheduling service', () => { jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', + preventPayment: false, formSubmissionResult: { - preventPayment: false, submissionId: SUBMISSION_ID, submission: { calc: 10, @@ -434,7 +431,6 @@ describe('sheduling service', () => { }, }, payment: null, - preventPayment: false, submissionTimestamp: '2025-01-17T03:09:25.559Z', isInPendingQueue: false, isOffline: false, @@ -446,8 +442,8 @@ describe('sheduling service', () => { jest.mocked(getSchedulingSubmissionResult).mockResolvedValue({ paymentReceiptUrl: 'RECEIPT_URL', paymentFormUrl: 'FORM_URL', + preventPayment: false, formSubmissionResult: { - preventPayment: false, submissionId: SUBMISSION_ID, submission: { calc: 10, @@ -512,7 +508,6 @@ describe('sheduling service', () => { }, }, }, - preventPayment: false, payment: { amount: 10, paymentFormUrl: 'FORM_URL', From e8624700691af2ea525557ce2c98bf2243f17b0d Mon Sep 17 00:00:00 2001 From: David Porter Date: Mon, 20 Jan 2025 11:01:38 +1100 Subject: [PATCH 6/6] ON-46214 # add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8468fe61..40b6abce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - scheduled task properties to form store filtering +### Fixed + +- `preventPayment` not being evaluated when completing a clarification with a calendar booking and payment + ## [19.0.0] - 2025-01-12 ### Removed