From 55a2fe8739a41f763fea35452c4d87c4ab0a20fa Mon Sep 17 00:00:00 2001 From: vasileios Date: Wed, 24 Jan 2024 16:25:01 +0100 Subject: [PATCH] [open-formulieren/open-forms#3797] Fixed submission id in pluginsAPIValidator --- src/formio/validators/plugins.js | 3 ++- .../validators/pluginapivalidator.spec.js | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/formio/validators/plugins.js b/src/formio/validators/plugins.js index 8d297618e..966bb7118 100644 --- a/src/formio/validators/plugins.js +++ b/src/formio/validators/plugins.js @@ -11,7 +11,8 @@ export const pluginsAPIValidator = { const plugins = component.component.validate.plugins; const {baseUrl} = component.currentForm?.options || component.options; - const {submissionUuid} = component.currentForm?.options.ofContext; + const {submissionUuid} = + component.currentForm?.options?.ofContext || component.options?.ofContext; const promises = plugins.map(plugin => { const url = `${baseUrl}validation/plugins/${plugin}`; diff --git a/src/jstests/formio/validators/pluginapivalidator.spec.js b/src/jstests/formio/validators/pluginapivalidator.spec.js index d02a9d9f3..e33234df0 100644 --- a/src/jstests/formio/validators/pluginapivalidator.spec.js +++ b/src/jstests/formio/validators/pluginapivalidator.spec.js @@ -35,6 +35,28 @@ describe('The OpenForms plugins validation', () => { } }); + test('tests expected errors are returned when currentForm is not part of the component', async () => { + mswServer.use( + phoneNumberValidations.mockInValidDutchPhonenumberPost, + phoneNumberValidations.mockInValidInternationalPhonenumberPost + ); + + const component = { + component: phoneNumberComponent, + options: { + baseUrl: BASE_URL, + ofContext: { + submissionUuid: 'dummy', + }, + }, + }; + + for (const sample of inValidSamples) { + const result = await pluginsAPIValidator.check(component, undefined, sample); + expect(result).toBe('Invalid international phone number
Invalid dutch phone number'); + } + }); + test('tests no errors are returned when phone number is valid', async () => { mswServer.use( phoneNumberValidations.mockValidDutchPhonenumberPost,