From 52a6fe80aaba84320f500eccb2bfd92b35ba02d4 Mon Sep 17 00:00:00 2001 From: pezholio Date: Fri, 21 Feb 2025 10:42:35 +0000 Subject: [PATCH] Improve validation for rate amounts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This improves the rate validation to: - Ensure only 1 currency symbol is present - Make decimal points optional - Ensure bigger numbers have commas (as per the numbers guidance https://www.gov.uk/guidance/style-guide/a-to-z#numbers) I’ve also added a couple of extra rates to ensure the validation works as expected. --- .../content_block_pension/notification/schema.json | 2 +- .../content_block_pension/publisher_v2/schema.json | 2 +- .../content_block_pension/publisher_v2/example.json | 12 ++++++++++++ .../formats/content_block_pension.jsonnet | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/content_schemas/dist/formats/content_block_pension/notification/schema.json b/content_schemas/dist/formats/content_block_pension/notification/schema.json index 97d924c65..b2da1036c 100644 --- a/content_schemas/dist/formats/content_block_pension/notification/schema.json +++ b/content_schemas/dist/formats/content_block_pension/notification/schema.json @@ -403,7 +403,7 @@ "properties": { "amount": { "type": "string", - "pattern": "£[0-9]+\\.[0-9]+" + "pattern": "^£{1}[1-9]{1,3}(,\\d{3})*(\\.\\d{2})?" }, "cadence": { "type": "string", diff --git a/content_schemas/dist/formats/content_block_pension/publisher_v2/schema.json b/content_schemas/dist/formats/content_block_pension/publisher_v2/schema.json index 07bcd3b69..c5c2a9ec3 100644 --- a/content_schemas/dist/formats/content_block_pension/publisher_v2/schema.json +++ b/content_schemas/dist/formats/content_block_pension/publisher_v2/schema.json @@ -220,7 +220,7 @@ "properties": { "amount": { "type": "string", - "pattern": "£[0-9]+\\.[0-9]+" + "pattern": "^£{1}[1-9]{1,3}(,\\d{3})*(\\.\\d{2})?" }, "cadence": { "type": "string", diff --git a/content_schemas/examples/content_block_pension/publisher_v2/example.json b/content_schemas/examples/content_block_pension/publisher_v2/example.json index ed0a0b1f7..5f804a734 100644 --- a/content_schemas/examples/content_block_pension/publisher_v2/example.json +++ b/content_schemas/examples/content_block_pension/publisher_v2/example.json @@ -13,6 +13,18 @@ "amount": "£221.20", "cadence": "a week", "description": "Your weekly pension amount" + }, + "rate-2": { + "name": "Rate without decimal point", + "amount": "£221", + "cadence": "a week", + "description": "Your weekly pension amount" + }, + "rate-3": { + "name": "Rate with big value", + "amount": "£1,223", + "cadence": "a week", + "description": "Your weekly pension amount" } } }, diff --git a/content_schemas/formats/content_block_pension.jsonnet b/content_schemas/formats/content_block_pension.jsonnet index b44afe7de..4e2ec9416 100644 --- a/content_schemas/formats/content_block_pension.jsonnet +++ b/content_schemas/formats/content_block_pension.jsonnet @@ -14,7 +14,7 @@ local utils = import "shared/utils/content_block_utils.jsonnet"; { amount: { type: "string", - pattern: "£[0-9]+\\.[0-9]+", + pattern: "^£{1}[1-9]{1,3}(,\\d{3})*(\\.\\d{2})?", }, cadence: { type: "string",