@planning-inspectorate/dynamic-forms 2.0.2 → 2.0.4
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planning-inspectorate/dynamic-forms",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "This package is for building GDS forms using a configuration-based approach.",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/Planning-Inspectorate/dynamic-forms.git"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"commitlint": "commitlint --from=$(git cherry origin/main | head -n 1 | cut -c 3-)",
|
|
12
|
+
"commitlint": "commitlint --from=$(git rev-parse $(git cherry origin/main | head -n 1 | cut -c 3-)^1)",
|
|
13
13
|
"lint": "npx eslint .",
|
|
14
14
|
"format": "prettier --write .",
|
|
15
15
|
"format-check": "prettier --check .",
|
|
@@ -21,8 +21,8 @@ export const townCityMaxLength = 250;
|
|
|
21
21
|
export const townCityMinLength = 0;
|
|
22
22
|
export const countyMaxLength = 250;
|
|
23
23
|
export const countyMinLength = 0;
|
|
24
|
-
export const postcodeMaxLength =
|
|
25
|
-
export const postcodeMinLength =
|
|
24
|
+
export const postcodeMaxLength = 8;
|
|
25
|
+
export const postcodeMinLength = 5;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* enforces address fields are within allowed parameters
|
|
@@ -143,7 +143,7 @@ export default class AddressValidator extends BaseValidator {
|
|
|
143
143
|
return validator
|
|
144
144
|
.isLength({ min: postcodeMinLength, max: postcodeMaxLength })
|
|
145
145
|
.bail()
|
|
146
|
-
.withMessage(`Postcode must be
|
|
146
|
+
.withMessage(`Postcode must be between ${postcodeMinLength} and ${postcodeMaxLength} characters`)
|
|
147
147
|
.custom((postcode) => {
|
|
148
148
|
return validatePostcode(postcode);
|
|
149
149
|
});
|
|
@@ -6,6 +6,7 @@ import AddressValidator, {
|
|
|
6
6
|
addressLine1MaxLength,
|
|
7
7
|
addressLine2MaxLength,
|
|
8
8
|
postcodeMaxLength,
|
|
9
|
+
postcodeMinLength,
|
|
9
10
|
townCityMaxLength
|
|
10
11
|
} from './address-validator.js';
|
|
11
12
|
|
|
@@ -107,7 +108,90 @@ describe('AddressValidator', () => {
|
|
|
107
108
|
`Address line 2 must be ${addressLine2MaxLength} characters or less`
|
|
108
109
|
);
|
|
109
110
|
assert.strictEqual(errors.testField_townCity.msg, `Town or city must be ${townCityMaxLength} characters or less`);
|
|
110
|
-
assert.strictEqual(
|
|
111
|
+
assert.strictEqual(
|
|
112
|
+
errors.testField_postcode.msg,
|
|
113
|
+
`Postcode must be between ${postcodeMinLength} and ${postcodeMaxLength} characters`
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
it('should validate a valid 8-character postcode without errors', async () => {
|
|
117
|
+
const question = {
|
|
118
|
+
fieldName: 'testField'
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const req = {
|
|
122
|
+
body: {
|
|
123
|
+
testField_addressLine1: 'A Building',
|
|
124
|
+
testField_addressLine2: 'A Street',
|
|
125
|
+
testField_townCity: 'Test town',
|
|
126
|
+
testField_postcode: 'DN55 1PT'
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const errors = await _validationMappedErrors(req, question);
|
|
131
|
+
|
|
132
|
+
assert.deepStrictEqual(errors, {});
|
|
133
|
+
});
|
|
134
|
+
// New postcode tests
|
|
135
|
+
it('should validate a valid 5-character postcode without a space', async () => {
|
|
136
|
+
const question = { fieldName: 'testField' };
|
|
137
|
+
const req = {
|
|
138
|
+
body: {
|
|
139
|
+
testField_addressLine1: 'A Building',
|
|
140
|
+
testField_addressLine2: 'A Street',
|
|
141
|
+
testField_townCity: 'Test town',
|
|
142
|
+
testField_postcode: 'M11AA'
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const errors = await _validationMappedErrors(req, question);
|
|
146
|
+
assert.deepStrictEqual(errors, {});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should reject a postcode with multiple spaces', async () => {
|
|
150
|
+
const question = { fieldName: 'testField' };
|
|
151
|
+
const req = {
|
|
152
|
+
body: {
|
|
153
|
+
testField_addressLine1: 'A Building',
|
|
154
|
+
testField_addressLine2: 'A Street',
|
|
155
|
+
testField_townCity: 'Test town',
|
|
156
|
+
testField_postcode: 'AB1 2CD'
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const errors = await _validationMappedErrors(req, question);
|
|
160
|
+
assert.strictEqual(errors.testField_postcode.msg, 'Enter a valid postcode');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('should reject a postcode shorter than 5 characters', async () => {
|
|
164
|
+
const question = { fieldName: 'testField' };
|
|
165
|
+
const req = {
|
|
166
|
+
body: {
|
|
167
|
+
testField_addressLine1: 'A Building',
|
|
168
|
+
testField_addressLine2: 'A Street',
|
|
169
|
+
testField_townCity: 'Test town',
|
|
170
|
+
testField_postcode: 'A1 1'
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const errors = await _validationMappedErrors(req, question);
|
|
174
|
+
assert.strictEqual(
|
|
175
|
+
errors.testField_postcode.msg,
|
|
176
|
+
`Postcode must be between ${postcodeMinLength} and ${postcodeMaxLength} characters`
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('should reject a postcode longer than 8 characters', async () => {
|
|
181
|
+
const question = { fieldName: 'testField' };
|
|
182
|
+
const req = {
|
|
183
|
+
body: {
|
|
184
|
+
testField_addressLine1: 'A Building',
|
|
185
|
+
testField_addressLine2: 'A Street',
|
|
186
|
+
testField_townCity: 'Test town',
|
|
187
|
+
testField_postcode: 'DN55 1PTA'
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const errors = await _validationMappedErrors(req, question);
|
|
191
|
+
assert.strictEqual(
|
|
192
|
+
errors.testField_postcode.msg,
|
|
193
|
+
`Postcode must be between ${postcodeMinLength} and ${postcodeMaxLength} characters`
|
|
194
|
+
);
|
|
111
195
|
});
|
|
112
196
|
});
|
|
113
197
|
|