From 8afabc512884c7e4fe46ccab350c0f943dc1564c Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Wed, 4 Sep 2024 10:38:45 +0100 Subject: [PATCH 01/30] Created the validation message and imported to setting page --- eq-author/src/App/settings/SettingsPage.js | 1 + eq-author/src/constants/validationMessages.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/eq-author/src/App/settings/SettingsPage.js b/eq-author/src/App/settings/SettingsPage.js index eb78cd1675..02b0649811 100644 --- a/eq-author/src/App/settings/SettingsPage.js +++ b/eq-author/src/App/settings/SettingsPage.js @@ -24,6 +24,7 @@ import { SURVEY_ID_ERRORS, FORM_TYPE_ERRORS, EQ_ID_ERRORS, + SURVEY_ID_VALIDATION_ERRORS, } from "constants/validationMessages"; import { reduceMultipleSpaces } from "utils/reduceMultipleSpaces"; diff --git a/eq-author/src/constants/validationMessages.js b/eq-author/src/constants/validationMessages.js index 5c8013063a..f047302d97 100644 --- a/eq-author/src/constants/validationMessages.js +++ b/eq-author/src/constants/validationMessages.js @@ -348,6 +348,11 @@ export const SURVEY_ID_ERRORS = { ERR_INVALID: "Enter a survey ID in the correct format", }; +export const SURVEY_ID_VALIDATION_ERRORS = { + ERR_INVALID: + "The Survey ID does not match the linked supplementary data schema", +}; + export const FORM_TYPE_ERRORS = { ERR_VALID_REQUIRED: "Enter a form type", ERR_INVALID: "Enter a form type in the correct format", From 40f8ea604da34031eb95e16ccaffcac9efd61155 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Fri, 6 Sep 2024 10:42:21 +0100 Subject: [PATCH 02/30] added validation error codes for the survey ID --- eq-author-api/constants/validationErrorCodes.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eq-author-api/constants/validationErrorCodes.js b/eq-author-api/constants/validationErrorCodes.js index 1b549dd0a4..203646e079 100644 --- a/eq-author-api/constants/validationErrorCodes.js +++ b/eq-author-api/constants/validationErrorCodes.js @@ -38,6 +38,7 @@ const ERR_COUNT_OF_GREATER_THAN_AVAILABLE_OPTIONS = const ERR_VALID_PIPED_ANSWER_REQUIRED = "ERR_VALID_PIPED_ANSWER_REQUIRED"; const ERR_UNIQUE_PAGE_DESCRIPTION = "ERR_UNIQUE_PAGE_DESCRIPTION"; const ERR_NO_ANSWERS = "ERR_NO_ANSWERS"; +const ERR_INVALID_SURVEY_ID = "ERR_INVALID_SURVEY_ID"; module.exports = { ERR_INVALID, @@ -76,4 +77,5 @@ module.exports = { ERR_VALID_PIPED_ANSWER_REQUIRED, ERR_UNIQUE_PAGE_DESCRIPTION, ERR_NO_ANSWERS, + ERR_INVALID_SURVEY_ID, }; From 41e99866e39d3e16b8190c81959bd5e581238596 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Fri, 6 Sep 2024 11:00:09 +0100 Subject: [PATCH 03/30] changes the validation message for checking the surveyID --- eq-author/src/constants/validationMessages.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eq-author/src/constants/validationMessages.js b/eq-author/src/constants/validationMessages.js index f047302d97..484652bcb9 100644 --- a/eq-author/src/constants/validationMessages.js +++ b/eq-author/src/constants/validationMessages.js @@ -349,8 +349,8 @@ export const SURVEY_ID_ERRORS = { }; export const SURVEY_ID_VALIDATION_ERRORS = { - ERR_INVALID: - "The Survey ID does not match the linked supplementary data schema", + errorCode: "ERR_INVALID_SURVEY_ID", + message: "The Survey ID does not match the linked supplementary data schema", }; export const FORM_TYPE_ERRORS = { From f861e0eded629172b4bc80dc97a58d890e36d5a0 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Fri, 6 Sep 2024 14:17:02 +0100 Subject: [PATCH 04/30] added ajv code for surveyId --- .../customKeywords/validateSurveyID.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 eq-author-api/src/validation/customKeywords/validateSurveyID.js diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js new file mode 100644 index 0000000000..58ff18bd49 --- /dev/null +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -0,0 +1,39 @@ +const { + ERR_INVALID_SURVEY_ID, +} = require("../../../constants/validationErrorCodes"); +const createValidationError = require("../createValidationError"); + +module.exports = (ajv) => + ajv.addKeyword({ + keyword: "validateSurveyID", + $data: true, + validate: function isValid( + _schema, + surveyId, + _parentSchema, + { parentDataProperty: fieldName, instancePath, rootData: questionnaire } + ) { + const ctx = { + questionnaire, + }; + const surveyID = ctx.questionnaire.surveyId; + const SDS = ctx.questionnaire.supplementaryData; + const sdsSurveyID = ctx.questionnaire.supplementaryData.surveyId; + + if (SDS) { + if (surveyID !== sdsSurveyID) { + isValid.errors = [ + createValidationError( + instancePath, + fieldName, + ERR_INVALID_SURVEY_ID, + questionnaire + ), + ]; + return false; + } else { + return true; + } + } + }, + }); From cb28f4418cb37a22373dba3cc3a883d764f9c967 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Fri, 6 Sep 2024 14:29:55 +0100 Subject: [PATCH 05/30] debugging the surveyIDs error --- eq-author/src/App/settings/SettingsPage.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eq-author/src/App/settings/SettingsPage.js b/eq-author/src/App/settings/SettingsPage.js index 02b0649811..4c21e7a83b 100644 --- a/eq-author/src/App/settings/SettingsPage.js +++ b/eq-author/src/App/settings/SettingsPage.js @@ -148,6 +148,12 @@ const SettingsPage = ({ questionnaire }) => { const getValidationErrorMessage = (contentType) => { if (contentType === "surveyId") { + console.log(contentType); + const error = questionnaire.validationErrorInfo.errors; + console.log(error); + + error?.find(({ errorCode }) => errorCode); + return SURVEY_ID_ERRORS[ questionnaire?.validationErrorInfo?.errors?.find( ({ field }) => field === "surveyId" From 4e81937174fa7b0c22fd9a42fa5feb8fa51532e2 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Fri, 6 Sep 2024 15:31:06 +0100 Subject: [PATCH 06/30] added the error code in the survey id errors --- eq-author/src/App/settings/SettingsPage.js | 7 ------- eq-author/src/constants/validationMessages.js | 7 ++----- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/eq-author/src/App/settings/SettingsPage.js b/eq-author/src/App/settings/SettingsPage.js index 4c21e7a83b..eb78cd1675 100644 --- a/eq-author/src/App/settings/SettingsPage.js +++ b/eq-author/src/App/settings/SettingsPage.js @@ -24,7 +24,6 @@ import { SURVEY_ID_ERRORS, FORM_TYPE_ERRORS, EQ_ID_ERRORS, - SURVEY_ID_VALIDATION_ERRORS, } from "constants/validationMessages"; import { reduceMultipleSpaces } from "utils/reduceMultipleSpaces"; @@ -148,12 +147,6 @@ const SettingsPage = ({ questionnaire }) => { const getValidationErrorMessage = (contentType) => { if (contentType === "surveyId") { - console.log(contentType); - const error = questionnaire.validationErrorInfo.errors; - console.log(error); - - error?.find(({ errorCode }) => errorCode); - return SURVEY_ID_ERRORS[ questionnaire?.validationErrorInfo?.errors?.find( ({ field }) => field === "surveyId" diff --git a/eq-author/src/constants/validationMessages.js b/eq-author/src/constants/validationMessages.js index 484652bcb9..6e1a419290 100644 --- a/eq-author/src/constants/validationMessages.js +++ b/eq-author/src/constants/validationMessages.js @@ -346,11 +346,8 @@ export const destinationErrors = { export const SURVEY_ID_ERRORS = { ERR_VALID_REQUIRED: "Enter a survey ID", ERR_INVALID: "Enter a survey ID in the correct format", -}; - -export const SURVEY_ID_VALIDATION_ERRORS = { - errorCode: "ERR_INVALID_SURVEY_ID", - message: "The Survey ID does not match the linked supplementary data schema", + ERR_INVALID_SURVEY_ID: + "The Survey ID does not match the linked supplementary data schema", }; export const FORM_TYPE_ERRORS = { From f714edb3cbd9db466b7f8ca068f95db995f2a506 Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Fri, 6 Sep 2024 16:45:51 +0100 Subject: [PATCH 07/30] validateSurveyID Keyword added to the json schema --- .../constants/validationErrorCodes.js | 4 +- .../src/validation/customKeywords/index.js | 1 + .../customKeywords/validateSurveyID.js | 57 +++++++++---------- .../src/validation/schemas/questionnaire.json | 31 ++++++---- eq-author/src/constants/validationMessages.js | 2 +- 5 files changed, 51 insertions(+), 44 deletions(-) diff --git a/eq-author-api/constants/validationErrorCodes.js b/eq-author-api/constants/validationErrorCodes.js index 203646e079..880f769b32 100644 --- a/eq-author-api/constants/validationErrorCodes.js +++ b/eq-author-api/constants/validationErrorCodes.js @@ -38,7 +38,7 @@ const ERR_COUNT_OF_GREATER_THAN_AVAILABLE_OPTIONS = const ERR_VALID_PIPED_ANSWER_REQUIRED = "ERR_VALID_PIPED_ANSWER_REQUIRED"; const ERR_UNIQUE_PAGE_DESCRIPTION = "ERR_UNIQUE_PAGE_DESCRIPTION"; const ERR_NO_ANSWERS = "ERR_NO_ANSWERS"; -const ERR_INVALID_SURVEY_ID = "ERR_INVALID_SURVEY_ID"; +const ERR_SURVEY_ID_MISMATCH = "ERR_SURVEY_ID_MISMATCH"; module.exports = { ERR_INVALID, @@ -77,5 +77,5 @@ module.exports = { ERR_VALID_PIPED_ANSWER_REQUIRED, ERR_UNIQUE_PAGE_DESCRIPTION, ERR_NO_ANSWERS, - ERR_INVALID_SURVEY_ID, + ERR_SURVEY_ID_MISMATCH, }; diff --git a/eq-author-api/src/validation/customKeywords/index.js b/eq-author-api/src/validation/customKeywords/index.js index 4c325b9007..374983bc98 100644 --- a/eq-author-api/src/validation/customKeywords/index.js +++ b/eq-author-api/src/validation/customKeywords/index.js @@ -5,6 +5,7 @@ module.exports = (ajv) => { require("./calculatedSummaryPosition")(ajv); require("./validateLatestAfterEarliest")(ajv); require("./validateDuration")(ajv); + require("./validateSurveyID")(ajv); require("./validateMultipleChoiceCondition")(ajv); require("./validateExpression")(ajv); require("./validateRoutingDestination")(ajv); diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index 58ff18bd49..865f25398e 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -1,39 +1,38 @@ +const createValidationError = require("../createValidationError"); const { - ERR_INVALID_SURVEY_ID, + ERR_SURVEY_ID_MISMATCH, } = require("../../../constants/validationErrorCodes"); -const createValidationError = require("../createValidationError"); module.exports = (ajv) => ajv.addKeyword({ keyword: "validateSurveyID", - $data: true, - validate: function isValid( - _schema, - surveyId, - _parentSchema, - { parentDataProperty: fieldName, instancePath, rootData: questionnaire } - ) { - const ctx = { - questionnaire, - }; - const surveyID = ctx.questionnaire.surveyId; - const SDS = ctx.questionnaire.supplementaryData; - const sdsSurveyID = ctx.questionnaire.supplementaryData.surveyId; + validate: function isValid(_schema, data, _parentSchema, ctx) { + const { + instancePath, + parentDataProperty: fieldName, + rootData: questionnaire, + } = ctx; + + const surveyID = questionnaire.surveyId; + const SDS = questionnaire.supplementaryData; - if (SDS) { - if (surveyID !== sdsSurveyID) { - isValid.errors = [ - createValidationError( - instancePath, - fieldName, - ERR_INVALID_SURVEY_ID, - questionnaire - ), - ]; - return false; - } else { - return true; - } + // If supplementaryData exists, retrieve its surveyId + const sdsSurveyID = SDS ? SDS.surveyId : null; + + // If supplementaryData exists, compare surveyId values + if (SDS && surveyID !== sdsSurveyID) { + isValid.errors = [ + createValidationError( + instancePath, + fieldName, + ERR_SURVEY_ID_MISMATCH, + questionnaire + ), + ]; + return false; } + + // If supplementaryData is missing or surveyIds match, return true + return true; }, }); diff --git a/eq-author-api/src/validation/schemas/questionnaire.json b/eq-author-api/src/validation/schemas/questionnaire.json index 77a6bde3d1..c22782cd1f 100644 --- a/eq-author-api/src/validation/schemas/questionnaire.json +++ b/eq-author-api/src/validation/schemas/questionnaire.json @@ -26,18 +26,25 @@ "$ref": "submission.json" }, "surveyId": { - "if": { - "type": "string", - "minLength": 1 - }, - "then": { - "type": "string", - "pattern": "^\\d{3}$", - "errorMessage": "ERR_INVALID" - }, - "else": { - "$ref": "definitions.json#/definitions/populatedString" - } + "allOf": [ + { + "if": { + "type": "string", + "minLength": 1 + }, + "then": { + "type": "string", + "pattern": "^\\d{3}$", + "errorMessage": "ERR_INVALID" + }, + "else": { + "$ref": "definitions.json#/definitions/populatedString" + } + }, + { + "validateSurveyID": true + } + ] }, "formType": { "if": { diff --git a/eq-author/src/constants/validationMessages.js b/eq-author/src/constants/validationMessages.js index 484652bcb9..5894b8d0ef 100644 --- a/eq-author/src/constants/validationMessages.js +++ b/eq-author/src/constants/validationMessages.js @@ -349,7 +349,7 @@ export const SURVEY_ID_ERRORS = { }; export const SURVEY_ID_VALIDATION_ERRORS = { - errorCode: "ERR_INVALID_SURVEY_ID", + errorCode: "ERR_SURVEY_ID_MISMATCH", message: "The Survey ID does not match the linked supplementary data schema", }; From b59bae874007b0f17a4fcb7f0ef89455297da05a Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Fri, 6 Sep 2024 17:07:29 +0100 Subject: [PATCH 08/30] added validation message in the survey id errors --- eq-author/src/constants/validationMessages.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/eq-author/src/constants/validationMessages.js b/eq-author/src/constants/validationMessages.js index 5894b8d0ef..6c73cef311 100644 --- a/eq-author/src/constants/validationMessages.js +++ b/eq-author/src/constants/validationMessages.js @@ -346,11 +346,8 @@ export const destinationErrors = { export const SURVEY_ID_ERRORS = { ERR_VALID_REQUIRED: "Enter a survey ID", ERR_INVALID: "Enter a survey ID in the correct format", -}; - -export const SURVEY_ID_VALIDATION_ERRORS = { - errorCode: "ERR_SURVEY_ID_MISMATCH", - message: "The Survey ID does not match the linked supplementary data schema", + ERR_SURVEY_ID_MISMATCH: + "The Survey ID does not match the linked supplementary data schema", }; export const FORM_TYPE_ERRORS = { From cd593a4ad8e9f5c62db17680b6a4d769599ab45b Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Fri, 6 Sep 2024 17:15:28 +0100 Subject: [PATCH 09/30] Error messages updated --- eq-author/src/constants/validationMessages.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/eq-author/src/constants/validationMessages.js b/eq-author/src/constants/validationMessages.js index 5894b8d0ef..6c73cef311 100644 --- a/eq-author/src/constants/validationMessages.js +++ b/eq-author/src/constants/validationMessages.js @@ -346,11 +346,8 @@ export const destinationErrors = { export const SURVEY_ID_ERRORS = { ERR_VALID_REQUIRED: "Enter a survey ID", ERR_INVALID: "Enter a survey ID in the correct format", -}; - -export const SURVEY_ID_VALIDATION_ERRORS = { - errorCode: "ERR_SURVEY_ID_MISMATCH", - message: "The Survey ID does not match the linked supplementary data schema", + ERR_SURVEY_ID_MISMATCH: + "The Survey ID does not match the linked supplementary data schema", }; export const FORM_TYPE_ERRORS = { From 9d73b7c45b4b9adcfea72c0c9dcd06dd78ea6b75 Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Fri, 6 Sep 2024 23:13:53 +0100 Subject: [PATCH 10/30] Ajv code updated and debug statements added --- .../src/validation/createValidationError.js | 1 + .../customKeywords/validateSurveyID.js | 44 +++++++++++++------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/eq-author-api/src/validation/createValidationError.js b/eq-author-api/src/validation/createValidationError.js index 43622e419a..e2ec5cb6a3 100644 --- a/eq-author-api/src/validation/createValidationError.js +++ b/eq-author-api/src/validation/createValidationError.js @@ -4,6 +4,7 @@ module.exports = (dataPath, field, errorCode, questionnaire, errMessage) => { if (!dataPath || (typeof dataPath !== "string" && !Array.isArray(dataPath))) { throw new Error("Parameter 'dataPath' must be one of: String, Array"); } + console.log("errorcode", errorCode); if (!field) { throw new Error("Parameter 'field' must be supplied"); diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index 865f25398e..70462f1332 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -6,21 +6,40 @@ const { module.exports = (ajv) => ajv.addKeyword({ keyword: "validateSurveyID", - validate: function isValid(_schema, data, _parentSchema, ctx) { - const { - instancePath, - parentDataProperty: fieldName, - rootData: questionnaire, - } = ctx; + $data: true, + validate: function isValid( + schema, // schema true + data, // gives the data entered into the survey ID field + parentSchema, // parentSchema { validateSurveyID: true } + { + instancePath, // gives the path /surveyId + rootData: questionnaire, // gives the whole object of questionnaire + parentData, // gives the whole object of questionnaire + parentDataProperty: fieldName, // gives the field name surveyId + } + ) { + // console.log("instancePath", instancePath); + // console.log("schema", schema); + // console.log("parentSchema", parentSchema); + // console.log("data", data); + // console.log("questionnaire", questionnaire.supplementaryData.surveyId); + // Get the supplementary data from rootData + const supplementaryData = questionnaire.supplementaryData; // gives the supplementary data field + // console.log("supplementaryData", supplementaryData.surveyID); - const surveyID = questionnaire.surveyId; - const SDS = questionnaire.supplementaryData; + // const questionnaireSurveyId = questionnaire.surveyId; // gives the data entered into the survey ID field + // console.log("questionnaireSurveyId", questionnaireSurveyId); - // If supplementaryData exists, retrieve its surveyId - const sdsSurveyID = SDS ? SDS.surveyId : null; + // console.log("data", data); // gives the data entered into the survey ID field + // console.log("parentdata", parentData); // the whole questionnaire object - // If supplementaryData exists, compare surveyId values - if (SDS && surveyID !== sdsSurveyID) { + // If supplementaryData is not available or doesn't contain surveyId, or if surveyId doesn't match, throw an error + if ( + supplementaryData && + supplementaryData.surveyId && + data !== supplementaryData.surveyId + ) { + console.log("meow", ERR_SURVEY_ID_MISMATCH); isValid.errors = [ createValidationError( instancePath, @@ -32,7 +51,6 @@ module.exports = (ajv) => return false; } - // If supplementaryData is missing or surveyIds match, return true return true; }, }); From a0e7b150f43ae77e1f6e4012c23e941a773d4464 Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Sun, 8 Sep 2024 13:24:43 +0100 Subject: [PATCH 11/30] More debug statements added and the survey ID and supplementary data survey ID mismatch error being thrown working --- eq-author-api/src/validation/createValidationError.js | 2 +- .../src/validation/customKeywords/validateSurveyID.js | 9 +++++---- eq-author/src/App/settings/SettingsPage.js | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/eq-author-api/src/validation/createValidationError.js b/eq-author-api/src/validation/createValidationError.js index e2ec5cb6a3..ec53463803 100644 --- a/eq-author-api/src/validation/createValidationError.js +++ b/eq-author-api/src/validation/createValidationError.js @@ -4,7 +4,7 @@ module.exports = (dataPath, field, errorCode, questionnaire, errMessage) => { if (!dataPath || (typeof dataPath !== "string" && !Array.isArray(dataPath))) { throw new Error("Parameter 'dataPath' must be one of: String, Array"); } - console.log("errorcode", errorCode); + console.log("errorcode", dataPath, errorCode, field, errMessage); if (!field) { throw new Error("Parameter 'field' must be supplied"); diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index 70462f1332..ab4692f6c5 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -21,11 +21,11 @@ module.exports = (ajv) => // console.log("instancePath", instancePath); // console.log("schema", schema); // console.log("parentSchema", parentSchema); - // console.log("data", data); + console.log("data", data); // console.log("questionnaire", questionnaire.supplementaryData.surveyId); // Get the supplementary data from rootData const supplementaryData = questionnaire.supplementaryData; // gives the supplementary data field - // console.log("supplementaryData", supplementaryData.surveyID); + console.log("supplementaryData", supplementaryData.surveyId); // const questionnaireSurveyId = questionnaire.surveyId; // gives the data entered into the survey ID field // console.log("questionnaireSurveyId", questionnaireSurveyId); @@ -39,13 +39,14 @@ module.exports = (ajv) => supplementaryData.surveyId && data !== supplementaryData.surveyId ) { - console.log("meow", ERR_SURVEY_ID_MISMATCH); + // console.log("meow", ERR_SURVEY_ID_MISMATCH); isValid.errors = [ createValidationError( instancePath, fieldName, ERR_SURVEY_ID_MISMATCH, - questionnaire + questionnaire, + "ERR_SURVEY_ID_MISMATCH" ), ]; return false; diff --git a/eq-author/src/App/settings/SettingsPage.js b/eq-author/src/App/settings/SettingsPage.js index eb78cd1675..2e134bd098 100644 --- a/eq-author/src/App/settings/SettingsPage.js +++ b/eq-author/src/App/settings/SettingsPage.js @@ -147,6 +147,14 @@ const SettingsPage = ({ questionnaire }) => { const getValidationErrorMessage = (contentType) => { if (contentType === "surveyId") { + console.log( + SURVEY_ID_ERRORS[ + questionnaire?.validationErrorInfo?.errors?.find( + ({ field }) => field === "surveyId" + )?.errorCode + ] + ); + return SURVEY_ID_ERRORS[ questionnaire?.validationErrorInfo?.errors?.find( ({ field }) => field === "surveyId" From 3ccb4f2f73ed1af1389026f1e8cc9e706fd5a20d Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Sun, 8 Sep 2024 17:12:34 +0100 Subject: [PATCH 12/30] Code refactored --- eq-author-api/src/validation/customKeywords/validateSurveyID.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index ab4692f6c5..f38fb4e4d0 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -46,7 +46,7 @@ module.exports = (ajv) => fieldName, ERR_SURVEY_ID_MISMATCH, questionnaire, - "ERR_SURVEY_ID_MISMATCH" + ERR_SURVEY_ID_MISMATCH ), ]; return false; From 38bc8b979f506a433e2286efe002855bf3c8f647 Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Mon, 9 Sep 2024 13:49:56 +0100 Subject: [PATCH 13/30] Code cleaned up --- .../customKeywords/validateSurveyID.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index f38fb4e4d0..8ae94f4865 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -14,24 +14,13 @@ module.exports = (ajv) => { instancePath, // gives the path /surveyId rootData: questionnaire, // gives the whole object of questionnaire - parentData, // gives the whole object of questionnaire + // parentData, // gives the whole object of questionnaire parentDataProperty: fieldName, // gives the field name surveyId } ) { - // console.log("instancePath", instancePath); - // console.log("schema", schema); - // console.log("parentSchema", parentSchema); console.log("data", data); - // console.log("questionnaire", questionnaire.supplementaryData.surveyId); - // Get the supplementary data from rootData - const supplementaryData = questionnaire.supplementaryData; // gives the supplementary data field - console.log("supplementaryData", supplementaryData.surveyId); - - // const questionnaireSurveyId = questionnaire.surveyId; // gives the data entered into the survey ID field - // console.log("questionnaireSurveyId", questionnaireSurveyId); - - // console.log("data", data); // gives the data entered into the survey ID field - // console.log("parentdata", parentData); // the whole questionnaire object + // Get the supplementary data from the questionnaire object + const supplementaryData = questionnaire.supplementaryData; // If supplementaryData is not available or doesn't contain surveyId, or if surveyId doesn't match, throw an error if ( @@ -39,7 +28,6 @@ module.exports = (ajv) => supplementaryData.surveyId && data !== supplementaryData.surveyId ) { - // console.log("meow", ERR_SURVEY_ID_MISMATCH); isValid.errors = [ createValidationError( instancePath, From 98259fcfe72b67be31cd0bd48b3d33207cef94f2 Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Thu, 12 Sep 2024 19:19:01 +0100 Subject: [PATCH 14/30] Debugging statements removed --- eq-author-api/src/validation/createValidationError.js | 1 - eq-author-api/src/validation/customKeywords/validateSurveyID.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/eq-author-api/src/validation/createValidationError.js b/eq-author-api/src/validation/createValidationError.js index ec53463803..43622e419a 100644 --- a/eq-author-api/src/validation/createValidationError.js +++ b/eq-author-api/src/validation/createValidationError.js @@ -4,7 +4,6 @@ module.exports = (dataPath, field, errorCode, questionnaire, errMessage) => { if (!dataPath || (typeof dataPath !== "string" && !Array.isArray(dataPath))) { throw new Error("Parameter 'dataPath' must be one of: String, Array"); } - console.log("errorcode", dataPath, errorCode, field, errMessage); if (!field) { throw new Error("Parameter 'field' must be supplied"); diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index 8ae94f4865..e7877d1966 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -14,11 +14,9 @@ module.exports = (ajv) => { instancePath, // gives the path /surveyId rootData: questionnaire, // gives the whole object of questionnaire - // parentData, // gives the whole object of questionnaire parentDataProperty: fieldName, // gives the field name surveyId } ) { - console.log("data", data); // Get the supplementary data from the questionnaire object const supplementaryData = questionnaire.supplementaryData; From f455436dadaa3c592bd7d092459feb5e9643aef0 Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Fri, 13 Sep 2024 12:31:11 +0100 Subject: [PATCH 15/30] Debug statement removed and comments removed --- .../src/validation/customKeywords/validateSurveyID.js | 6 +++--- eq-author/src/App/settings/SettingsPage.js | 8 -------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index e7877d1966..962598b541 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -8,12 +8,12 @@ module.exports = (ajv) => keyword: "validateSurveyID", $data: true, validate: function isValid( - schema, // schema true + schema, data, // gives the data entered into the survey ID field - parentSchema, // parentSchema { validateSurveyID: true } + parentSchema, { instancePath, // gives the path /surveyId - rootData: questionnaire, // gives the whole object of questionnaire + rootData: questionnaire, // gives the whole questionnaire object of parentDataProperty: fieldName, // gives the field name surveyId } ) { diff --git a/eq-author/src/App/settings/SettingsPage.js b/eq-author/src/App/settings/SettingsPage.js index 2e134bd098..eb78cd1675 100644 --- a/eq-author/src/App/settings/SettingsPage.js +++ b/eq-author/src/App/settings/SettingsPage.js @@ -147,14 +147,6 @@ const SettingsPage = ({ questionnaire }) => { const getValidationErrorMessage = (contentType) => { if (contentType === "surveyId") { - console.log( - SURVEY_ID_ERRORS[ - questionnaire?.validationErrorInfo?.errors?.find( - ({ field }) => field === "surveyId" - )?.errorCode - ] - ); - return SURVEY_ID_ERRORS[ questionnaire?.validationErrorInfo?.errors?.find( ({ field }) => field === "surveyId" From cd57b4c5c2fe2c31426b9afbd03cd9ba00d0b1a9 Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Fri, 13 Sep 2024 12:31:26 +0100 Subject: [PATCH 16/30] Comment updated --- eq-author-api/src/validation/customKeywords/validateSurveyID.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index 962598b541..c46f6c9678 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -13,7 +13,7 @@ module.exports = (ajv) => parentSchema, { instancePath, // gives the path /surveyId - rootData: questionnaire, // gives the whole questionnaire object of + rootData: questionnaire, // gives the whole questionnaire object parentDataProperty: fieldName, // gives the field name surveyId } ) { From 46dd2f4f132d4327090c9064167ab75bb9b20113 Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Fri, 13 Sep 2024 14:07:04 +0100 Subject: [PATCH 17/30] $data: true option removed, schema, data and parentSchema made private/ internal --- .../src/validation/customKeywords/validateSurveyID.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index c46f6c9678..748e8d0a52 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -6,11 +6,10 @@ const { module.exports = (ajv) => ajv.addKeyword({ keyword: "validateSurveyID", - $data: true, validate: function isValid( - schema, - data, // gives the data entered into the survey ID field - parentSchema, + _schema, + _data, // gives the data entered into the survey ID field + _parentSchema, { instancePath, // gives the path /surveyId rootData: questionnaire, // gives the whole questionnaire object @@ -24,7 +23,7 @@ module.exports = (ajv) => if ( supplementaryData && supplementaryData.surveyId && - data !== supplementaryData.surveyId + _data !== supplementaryData.surveyId ) { isValid.errors = [ createValidationError( From b150107c55563fc9f58926c5bb07264030658e96 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Mon, 16 Sep 2024 11:50:19 +0100 Subject: [PATCH 18/30] changed the survery with lowercase 's' --- eq-author/src/constants/validationMessages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eq-author/src/constants/validationMessages.js b/eq-author/src/constants/validationMessages.js index 6c73cef311..c305e700b6 100644 --- a/eq-author/src/constants/validationMessages.js +++ b/eq-author/src/constants/validationMessages.js @@ -347,7 +347,7 @@ export const SURVEY_ID_ERRORS = { ERR_VALID_REQUIRED: "Enter a survey ID", ERR_INVALID: "Enter a survey ID in the correct format", ERR_SURVEY_ID_MISMATCH: - "The Survey ID does not match the linked supplementary data schema", + "The survey ID does not match the linked supplementary data schema", }; export const FORM_TYPE_ERRORS = { From b77f25f2d79db8cf4a3ecd5b86297cdace9d3fdc Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Mon, 16 Sep 2024 13:19:25 +0100 Subject: [PATCH 19/30] file name change --- eq-author-api/src/validation/customKeywords/validateSurveyID.js | 1 + 1 file changed, 1 insertion(+) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index 748e8d0a52..10364fd7ca 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -34,6 +34,7 @@ module.exports = (ajv) => ERR_SURVEY_ID_MISMATCH ), ]; + return false; } From a128d14741d6d520b78e50b01da7aa96c748bd1f Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Mon, 16 Sep 2024 13:22:35 +0100 Subject: [PATCH 20/30] rename file --- eq-author-api/src/validation/customKeywords/validateSurveyID.js | 1 - 1 file changed, 1 deletion(-) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index 10364fd7ca..748e8d0a52 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -34,7 +34,6 @@ module.exports = (ajv) => ERR_SURVEY_ID_MISMATCH ), ]; - return false; } From 795a2ce8beef94369b47c3fc00d25a644d800cd8 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Mon, 16 Sep 2024 13:29:06 +0100 Subject: [PATCH 21/30] attempt of file name change --- eq-author-api/src/validation/customKeywords/validateSurveyID.js | 1 + 1 file changed, 1 insertion(+) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index 748e8d0a52..ced7968557 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -35,6 +35,7 @@ module.exports = (ajv) => ), ]; return false; + console.log("hello"); } return true; From ce0343601fd3e66b8dc1cfecc0d8fdeef33ed239 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Mon, 16 Sep 2024 13:36:28 +0100 Subject: [PATCH 22/30] remove debug statements --- eq-author-api/src/validation/customKeywords/validateSurveyID.js | 1 - 1 file changed, 1 deletion(-) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js index ced7968557..748e8d0a52 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyID.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyID.js @@ -35,7 +35,6 @@ module.exports = (ajv) => ), ]; return false; - console.log("hello"); } return true; From 95f43d022247781bc62dbd4f8e05b0974db4298a Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Mon, 16 Sep 2024 13:41:10 +0100 Subject: [PATCH 23/30] renamed file --- .../customKeywords/{validateSurveyID.js => validateSurveyId.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename eq-author-api/src/validation/customKeywords/{validateSurveyID.js => validateSurveyId.js} (100%) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyId.js similarity index 100% rename from eq-author-api/src/validation/customKeywords/validateSurveyID.js rename to eq-author-api/src/validation/customKeywords/validateSurveyId.js From 998a0da808b4c9309649841fa03e7888424f9d68 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Mon, 16 Sep 2024 13:44:36 +0100 Subject: [PATCH 24/30] . --- .../customKeywords/{validateSurveyId.js => validateSurveyID.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename eq-author-api/src/validation/customKeywords/{validateSurveyId.js => validateSurveyID.js} (100%) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyId.js b/eq-author-api/src/validation/customKeywords/validateSurveyID.js similarity index 100% rename from eq-author-api/src/validation/customKeywords/validateSurveyId.js rename to eq-author-api/src/validation/customKeywords/validateSurveyID.js From 1c8c40e0e941ced88196531ef3a13e5b2b9b7575 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Mon, 16 Sep 2024 13:45:23 +0100 Subject: [PATCH 25/30] . --- .../customKeywords/{validateSurveyID.js => validateSurveyId.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename eq-author-api/src/validation/customKeywords/{validateSurveyID.js => validateSurveyId.js} (100%) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyID.js b/eq-author-api/src/validation/customKeywords/validateSurveyId.js similarity index 100% rename from eq-author-api/src/validation/customKeywords/validateSurveyID.js rename to eq-author-api/src/validation/customKeywords/validateSurveyId.js From 5c9b9628485181ce2abfb0a3c0eb06e5f7617cc0 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Mon, 16 Sep 2024 13:53:48 +0100 Subject: [PATCH 26/30] changed the _data to questionnaireSurveyId --- .../src/validation/customKeywords/validateSurveyId.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyId.js b/eq-author-api/src/validation/customKeywords/validateSurveyId.js index 748e8d0a52..1e789e7ee6 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyId.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyId.js @@ -8,7 +8,7 @@ module.exports = (ajv) => keyword: "validateSurveyID", validate: function isValid( _schema, - _data, // gives the data entered into the survey ID field + _questionnaireSurveyId, // gives the data entered into the survey ID field _parentSchema, { instancePath, // gives the path /surveyId @@ -23,7 +23,7 @@ module.exports = (ajv) => if ( supplementaryData && supplementaryData.surveyId && - _data !== supplementaryData.surveyId + _questionnaireSurveyId !== supplementaryData.surveyId ) { isValid.errors = [ createValidationError( From 32391a34ef98a5517f145fcc724a860ea4b53d40 Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Mon, 16 Sep 2024 14:23:34 +0100 Subject: [PATCH 27/30] updated the comment in the ajv file --- eq-author-api/src/validation/customKeywords/validateSurveyId.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyId.js b/eq-author-api/src/validation/customKeywords/validateSurveyId.js index 1e789e7ee6..5ad3b75b7f 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyId.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyId.js @@ -19,7 +19,7 @@ module.exports = (ajv) => // Get the supplementary data from the questionnaire object const supplementaryData = questionnaire.supplementaryData; - // If supplementaryData is not available or doesn't contain surveyId, or if surveyId doesn't match, throw an error + // If supplementaryData exists and contains a surveyId, and supplementaryData's surveyId doesn't match the questionnaire's surveyId, throw a validation error if ( supplementaryData && supplementaryData.surveyId && From ec8fa19e50981d5fec62763e24f27046450f54e6 Mon Sep 17 00:00:00 2001 From: sanjeevz3009 Date: Mon, 16 Sep 2024 19:15:45 +0100 Subject: [PATCH 28/30] validateSurveyId file casing corrected --- eq-author-api/src/validation/customKeywords/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eq-author-api/src/validation/customKeywords/index.js b/eq-author-api/src/validation/customKeywords/index.js index 374983bc98..ec77ba8e42 100644 --- a/eq-author-api/src/validation/customKeywords/index.js +++ b/eq-author-api/src/validation/customKeywords/index.js @@ -5,7 +5,7 @@ module.exports = (ajv) => { require("./calculatedSummaryPosition")(ajv); require("./validateLatestAfterEarliest")(ajv); require("./validateDuration")(ajv); - require("./validateSurveyID")(ajv); + require("./validateSurveyId")(ajv); require("./validateMultipleChoiceCondition")(ajv); require("./validateExpression")(ajv); require("./validateRoutingDestination")(ajv); From 98af1c35f86ced8ee1a502fca97391b8a74bf7bd Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Tue, 17 Sep 2024 11:28:58 +0100 Subject: [PATCH 29/30] removed underscore and changed ID to lowercase 'd' --- .../src/validation/customKeywords/validateSurveyId.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eq-author-api/src/validation/customKeywords/validateSurveyId.js b/eq-author-api/src/validation/customKeywords/validateSurveyId.js index 5ad3b75b7f..c3853d86ad 100644 --- a/eq-author-api/src/validation/customKeywords/validateSurveyId.js +++ b/eq-author-api/src/validation/customKeywords/validateSurveyId.js @@ -5,10 +5,10 @@ const { module.exports = (ajv) => ajv.addKeyword({ - keyword: "validateSurveyID", + keyword: "validateSurveyId", validate: function isValid( _schema, - _questionnaireSurveyId, // gives the data entered into the survey ID field + questionnaireSurveyId, // gives the data entered into the survey ID field _parentSchema, { instancePath, // gives the path /surveyId @@ -23,7 +23,7 @@ module.exports = (ajv) => if ( supplementaryData && supplementaryData.surveyId && - _questionnaireSurveyId !== supplementaryData.surveyId + questionnaireSurveyId !== supplementaryData.surveyId ) { isValid.errors = [ createValidationError( From bb231f16c341f347eb1014ed4ac600ff82d9fc2c Mon Sep 17 00:00:00 2001 From: Farhanam76 Date: Tue, 17 Sep 2024 12:35:37 +0100 Subject: [PATCH 30/30] updated the questionnire json --- eq-author-api/src/validation/schemas/questionnaire.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eq-author-api/src/validation/schemas/questionnaire.json b/eq-author-api/src/validation/schemas/questionnaire.json index c22782cd1f..85b46ca871 100644 --- a/eq-author-api/src/validation/schemas/questionnaire.json +++ b/eq-author-api/src/validation/schemas/questionnaire.json @@ -42,7 +42,7 @@ } }, { - "validateSurveyID": true + "validateSurveyId": true } ] },