@ukhomeoffice/cop-react-form-renderer 4.28.0 → 4.29.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.
@@ -37,7 +37,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
37
37
  * @returns The first encountered error with the component.
38
38
  */
39
39
  var validateComponent = function validateComponent(component, outerData, formData) {
40
- var _component$data$optio;
40
+ var _fd$keycloakContext, _component$data$optio;
41
41
 
42
42
  var fd = formData || outerData;
43
43
 
@@ -64,7 +64,8 @@ var validateComponent = function validateComponent(component, outerData, formDat
64
64
  return (0, _validateCollection.default)(component, value, fd);
65
65
 
66
66
  case _models.ComponentTypes.EMAIL:
67
- error = (0, _validateEmail.default)(value, component.label);
67
+ var userEmail = fd === null ? '' : (_fd$keycloakContext = fd.keycloakContext) === null || _fd$keycloakContext === void 0 ? void 0 : _fd$keycloakContext.email;
68
+ error = (0, _validateEmail.default)(value, component.label, userEmail);
68
69
  break;
69
70
 
70
71
  case _models.ComponentTypes.DATE:
@@ -15,20 +15,28 @@ var HODS_EMAIL_REGEX = /^[a-z0-9._-]+@(digital\.)?homeoffice.gov.uk$/i;
15
15
  * validateRequired (Validate.required) for that sort of validation.
16
16
  * @param {*} value The value to validate.
17
17
  * @param {string} label The label to use in any error message.
18
+ * @param {string} userEmail The user email to use for validation.
18
19
  * @returns An error if the email address is invalid.
19
20
  */
20
21
 
21
22
  var validateEmail = function validateEmail(value) {
22
23
  var label = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
24
+ var userEmail = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
23
25
 
24
26
  if (!!value) {
27
+ var name = label ? label.toLowerCase() : 'email address';
28
+
25
29
  if (typeof value === 'string') {
30
+ // The following is an interim fix pending a mechanism for validating against specific values
31
+ if (['Line manager email', 'Delegate email address'].includes(label) && value === userEmail) {
32
+ return "".concat(label, " cannot be the same as the user email address");
33
+ }
34
+
26
35
  if (HODS_EMAIL_REGEX.test(value)) {
27
36
  return undefined;
28
37
  }
29
38
  }
30
39
 
31
- var name = label ? label.toLowerCase() : 'email address';
32
40
  return "Enter ".concat(name, " in the correct format, like jane.doe@homeoffice.gov.uk");
33
41
  }
34
42
 
@@ -52,6 +52,14 @@ describe('utils', function () {
52
52
  var DEFAULT_ERROR = 'Enter email address in the correct format, like jane.doe@homeoffice.gov.uk';
53
53
  expect((0, _validateEmail.default)(['bob'], undefined)).toEqual(DEFAULT_ERROR);
54
54
  });
55
+ it('should return an error when line manager email is same as user email', function () {
56
+ var USER_EMAIL_ERROR = 'Line manager email cannot be the same as the user email address';
57
+ expect((0, _validateEmail.default)('joe.bloggs@digital.homeoffice.gov.uk', 'Line manager email', 'joe.bloggs@digital.homeoffice.gov.uk')).toEqual(USER_EMAIL_ERROR);
58
+ });
59
+ it('should return an error when delegate email is same as user email', function () {
60
+ var USER_EMAIL_ERROR = 'Delegate email address cannot be the same as the user email address';
61
+ expect((0, _validateEmail.default)('joe.bloggs@digital.homeoffice.gov.uk', 'Delegate email address', 'joe.bloggs@digital.homeoffice.gov.uk')).toEqual(USER_EMAIL_ERROR);
62
+ });
55
63
  });
56
64
  });
57
65
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.28.0",
3
+ "version": "4.29.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",