@gov-cy/govcy-express-services 1.6.13 → 1.7.1

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": "@gov-cy/govcy-express-services",
3
- "version": "1.6.13",
3
+ "version": "1.7.1",
4
4
  "description": "An Express-based system that dynamically renders services using @gov-cy/govcy-frontend-renderer and posts data to a submission API.",
5
5
  "author": "DMRID - DSF Team",
6
6
  "license": "MIT",
@@ -78,7 +78,7 @@
78
78
  "mochawesome": "^7.1.4",
79
79
  "nodemon": "^3.0.2",
80
80
  "pa11y": "^8.0.0",
81
- "sinon": "^20.0.0"
81
+ "sinon": "^21.0.1"
82
82
  },
83
83
  "engines": {
84
84
  "node": ">=18.0.0"
@@ -16,7 +16,7 @@ import * as dataLayer from "../utils/govcyDataLayer.mjs";
16
16
  import { logger } from '../utils/govcyLogger.mjs';
17
17
  import { handleMiddlewareError, dateStringISOtoDMY } from "../utils/govcyUtils.mjs";
18
18
  import { govcyApiRequest } from "../utils/govcyApiRequest.mjs";
19
- import { isUnder18, isValidCypriotCitizen, validateFormElements } from "../utils/govcyValidator.mjs";
19
+ import { isAgeUnder, isValidCypriotCitizen, validateFormElements } from "../utils/govcyValidator.mjs";
20
20
  import { populateFormData, getFormData } from "../utils/govcyFormHandling.mjs";
21
21
  import { evaluatePageConditions } from "../utils/govcyExpressions.mjs";
22
22
  import { tempSaveIfConfigured } from "../utils/govcyTempSave.mjs";
@@ -107,8 +107,8 @@ export async function govcyUpdateMyDetailsHandler(req, res, next, page, serviceC
107
107
  return handleMiddlewareError(`updateMyDetailsAPIEndpoint - Missing response data`, 500, next);
108
108
  }
109
109
 
110
- // calculate if person in under 18 based on date of birth
111
- if (isUnder18(response.Data.dob)) {
110
+ // calculate if person in under 16 based on date of birth
111
+ if (isAgeUnder(response.Data.dob, 16)) {
112
112
  // --------------- Not eligible for Update my details ---------------
113
113
  // --------------- Page variant 1
114
114
  pageVariant = 1;
@@ -368,8 +368,8 @@ export function govcyUpdateMyDetailsPostHandler() {
368
368
  return handleMiddlewareError(`updateMyDetailsAPIEndpoint - Missing response data`, 500, next);
369
369
  }
370
370
 
371
- // calculate if person in under 18 based on date of birth
372
- if (isUnder18(response.Data.dob)) {
371
+ // calculate if person in under 16 based on date of birth
372
+ if (isAgeUnder(response.Data.dob, 16)) {
373
373
  // --------------- Not eligible for Update my details ---------------
374
374
  // --------------- Page variant 1:Manual form for non-eligible users
375
375
  pageVariant = 1;
@@ -1,20 +1,42 @@
1
1
  document.addEventListener("DOMContentLoaded", function () {
2
- // --- Show conditionals for checked radios ---
3
- // CHANGED: NodeList.prototype.forEach is not in IE11 → use Array.prototype.forEach.call
4
- // CHANGED: Arrow function → function
5
- Array.prototype.forEach.call(
6
- document.querySelectorAll('.govcy-radio-input[data-aria-controls]:checked'),
7
- function (radio) { // CHANGED: arrow → function
8
- // CHANGED: const → var (ES5)
9
- var targetId = radio.getAttribute('data-aria-controls');
10
- var targetElement = document.getElementById(targetId);
2
+ function updateConditionalRadios() {
3
+ // 1. Close ALL conditional blocks
4
+ Array.prototype.forEach.call(
5
+ document.querySelectorAll('.govcy-radio__conditional'),
6
+ function (el) {
7
+ el.classList.add('govcy-radio__conditional--hidden');
8
+ }
9
+ );
10
+
11
+ // 2. Re-open conditionals for CHECKED radios
12
+ // --- Show conditionals for checked radios ---
13
+ // CHANGED: NodeList.prototype.forEach is not in IE11 → use Array.prototype.forEach.call
14
+ // CHANGED: Arrow function → function
15
+ Array.prototype.forEach.call(
16
+ document.querySelectorAll('.govcy-radio-input[data-aria-controls]:checked'),
17
+ function (radio) { // CHANGED: arrow → function
18
+ // CHANGED: const → var (ES5)
19
+ var targetId = radio.getAttribute('data-aria-controls');
20
+ var targetElement = document.getElementById(targetId);
11
21
 
12
- if (targetElement) {
13
- targetElement.classList.remove('govcy-radio__conditional--hidden');
22
+ if (targetElement) {
23
+ targetElement.classList.remove('govcy-radio__conditional--hidden');
24
+ }
14
25
  }
26
+ );
27
+ }
28
+
29
+ // Attach to *all* radios to repair DS behaviour
30
+ Array.prototype.forEach.call(
31
+ document.querySelectorAll('.govcy-radio-input'),
32
+ function (radio) {
33
+ radio.addEventListener('change', updateConditionalRadios);
15
34
  }
16
35
  );
17
36
 
37
+ // Apply once on page load
38
+ updateConditionalRadios();
39
+
18
40
  // --- Disable submit button after form submission ---
19
41
  // CHANGED: NodeList.forEach → Array.prototype.forEach.call
20
42
  Array.prototype.forEach.call(document.querySelectorAll('form'), function (form) { // CHANGED
@@ -460,6 +460,18 @@ export function isValidForeignResident(user = {}) {
460
460
  * @throws {Error} If the date of birth is missing or invalid.
461
461
  * */
462
462
  export function isUnder18(dobString) {
463
+ return isAgeUnder(dobString, 18);
464
+ }
465
+
466
+
467
+ /**
468
+ * Checks if the user is under a specified minimum age based on their date of birth.
469
+ * @param {string} dobString - The date of birth in the format "YYYY-MM-DD".
470
+ * @param {number} minimumAge - The minimum age to check against (default is 16).
471
+ * @returns {boolean} True if the user is under the specified minimum age, otherwise false.
472
+ * @throws {Error} If the date of birth is missing or invalid.
473
+ * */
474
+ export function isAgeUnder(dobString, minimumAge = 16) {
463
475
  if (!dobString) throw new Error("DOB is missing");
464
476
  const dob = new Date(dobString);
465
477
  if (isNaN(dob)) throw new Error("Invalid DOB format");
@@ -470,7 +482,7 @@ export function isUnder18(dobString) {
470
482
  today.getMonth() > dob.getMonth() ||
471
483
  (today.getMonth() === dob.getMonth() && today.getDate() >= dob.getDate());
472
484
 
473
- return (hasHadBirthday ? ageDiff : ageDiff - 1) < 18;
485
+ return (hasHadBirthday ? ageDiff : ageDiff - 1) < minimumAge;
474
486
  }
475
487
 
476
488