@planning-inspectorate/dynamic-forms 3.4.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -4,10 +4,12 @@ import { body } from 'express-validator';
|
|
|
4
4
|
export default class DocumentUploadValidator extends BaseValidator {
|
|
5
5
|
/**
|
|
6
6
|
* @param {string} fieldName
|
|
7
|
+
* @param {string} errorMessage
|
|
7
8
|
*/
|
|
8
|
-
constructor(fieldName) {
|
|
9
|
+
constructor(fieldName, errorMessage = 'Upload an attachment') {
|
|
9
10
|
super();
|
|
10
11
|
this.fieldName = fieldName;
|
|
12
|
+
this.errorMessage = errorMessage;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
validate() {
|
|
@@ -17,7 +19,7 @@ export default class DocumentUploadValidator extends BaseValidator {
|
|
|
17
19
|
const parsed = JSON.parse(decodedJson);
|
|
18
20
|
|
|
19
21
|
if (parsed.length === 0) {
|
|
20
|
-
throw new Error(
|
|
22
|
+
throw new Error(this.errorMessage);
|
|
21
23
|
}
|
|
22
24
|
return true;
|
|
23
25
|
})
|
|
@@ -20,7 +20,7 @@ describe('./src/dynamic-forms/validator/document-upload-validator.js', () => {
|
|
|
20
20
|
assert.strictEqual(Object.keys(errors).length, 0);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
it('should return
|
|
23
|
+
it('should return default error message if documents have not been uploaded', async () => {
|
|
24
24
|
const req = {
|
|
25
25
|
body: {
|
|
26
26
|
myselfAttachments: 'W10='
|
|
@@ -33,6 +33,20 @@ describe('./src/dynamic-forms/validator/document-upload-validator.js', () => {
|
|
|
33
33
|
assert.strictEqual(Object.keys(errors).length, 1);
|
|
34
34
|
assert.strictEqual(errors[FIELD_NAME].msg, 'Upload an attachment');
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
it('should return custom error message if documents have not been uploaded', async () => {
|
|
38
|
+
const req = {
|
|
39
|
+
body: {
|
|
40
|
+
myselfAttachments: 'W10='
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const documentUploadValidator = new DocumentUploadValidator(FIELD_NAME, 'Please ensure you upload your documents');
|
|
44
|
+
|
|
45
|
+
const errors = await _validationMappedErrors(req, documentUploadValidator);
|
|
46
|
+
|
|
47
|
+
assert.strictEqual(Object.keys(errors).length, 1);
|
|
48
|
+
assert.strictEqual(errors[FIELD_NAME].msg, 'Please ensure you upload your documents');
|
|
49
|
+
});
|
|
36
50
|
});
|
|
37
51
|
|
|
38
52
|
const _validationMappedErrors = async (req, validator) => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export default class DocumentUploadValidator extends BaseValidator {
|
|
2
2
|
/**
|
|
3
3
|
* @param {string} fieldName
|
|
4
|
+
* @param {string} errorMessage
|
|
4
5
|
*/
|
|
5
|
-
constructor(fieldName: string);
|
|
6
|
+
constructor(fieldName: string, errorMessage?: string);
|
|
6
7
|
fieldName: string;
|
|
7
8
|
validate(): import("express-validator").ValidationChain[];
|
|
8
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-upload-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/document-upload-validator.js"],"names":[],"mappings":"AAGA;IACC
|
|
1
|
+
{"version":3,"file":"document-upload-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/document-upload-validator.js"],"names":[],"mappings":"AAGA;IACC;;;OAGG;IACH,uBAHW,MAAM,iBACN,MAAM,EAMhB;IAFA,kBAA0B;IAI3B,0DAYC;CACD;0BA3ByB,qBAAqB"}
|