Skip to content

Commit 70d3594

Browse files
fix: ENG-3901 Adds additional postcode validation (#437)
[ENG-3901] On both RND 2025 and 2026 we found there's an inconsistency between the regex used by our storybook's PostcodeLookup component, and the backend of serverless-giftaid. We found that the backend was stricter than storybook in its validation of the outcode (the first half of a postcode) - the postcode `cro 7tp` was being allowed by the frontend, but rejected by the backend. The goal here is to make the FE & BE* are stick to the same regex rule. *(the backend itself doesn't validate, it defers to a function in data-models. So really we're matching that.) There's a few tests updated and removed: ones that disallowed not having a space, or not using capital letters. The backend/data-models normalises what it's given, so postcodes like bn16aa will get transformed into BN1 6AA. To test it works, we should NOT be able to use the above postcode in either form (the main page, or the /update page) Last point: I did this a year ago when I had an IDE rule that strips whitespace. While I don't have that rule enabled anymore, I do still want to keep the many whitespace removal changes here. A noisier diff, but it is correct as that is errant whitespace and it shouldn't be here. I will die on this hill [ENG-3901]: https://comicrelief.atlassian.net/browse/ENG-3901?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Krupa Pammi <k.pammi@comicrelief.com>
1 parent 5dee113 commit 70d3594

9 files changed

Lines changed: 143 additions & 134 deletions

File tree

playwright-local/tests/submit/addressValidation.spec.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,31 @@ test.describe('Address validation', () => {
55

66
test.beforeEach(async ({ page }) => {
77
await page.goto('/', { timeout: 30000 });
8-
8+
99
await page.waitForLoadState('domcontentloaded');
1010
await page.locator('#field-label--giftaid').click();
1111
await page.locator('#field-input--mobile').fill('07123456789');
1212
await page.locator('input#field-input--firstname').fill('test');
1313
await page.locator('input#field-input--lastname').fill('user');
1414
});
15-
15+
1616
test('empty postcode should show error message', async ({ page }) => {
1717
await page.locator('input#field-input--postcode').fill('');
1818
await page.locator('button[type=submit]').click();
1919
await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter your postcode');
2020
await page.close();
2121
});
22-
22+
2323
test('invalid postcodes should show error messages', async ({ page }) => {
2424
await page.locator('input#field-input--postcode').fill('12SE17TP');
2525
await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.');
2626
await page.locator('input#field-input--postcode').fill('comic relief');
2727
await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.');
28+
await page.locator('input#field-input--postcode').fill('cro 7tp');
29+
await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.');
2830
await page.close();
2931
});
30-
32+
3133
test('enter postcode but submit without selecting address should show error message', async ({ page }) => {
3234
await page.locator('input#field-input--postcode').fill('SE1 7TP');
3335
await page.locator('#postcode_button').click();
@@ -36,7 +38,7 @@ test.describe('Address validation', () => {
3638
await expect(page.locator('div#field-error--addressSelect > span')).toHaveText('Please select your address');
3739
await page.close();
3840
});
39-
41+
4042
test('clicking on manual address link should show address fields', async ({ page }) => {
4143
await page.locator('input#field-input--postcode').fill('SE1 7TP');
4244
await expect(page.locator('a[aria-describedby=field-error--addressDetails]')).toBeVisible();
@@ -48,17 +50,17 @@ test.describe('Address validation', () => {
4850
await expect(page.locator('select#field-select--country')).toBeVisible();
4951
await page.close();
5052
});
51-
53+
5254
test('validate address fields', async ({ page }) => {
5355
await page.locator('input#field-input--postcode').fill('SE1 7TP');
5456
await page.locator('a[aria-describedby=field-error--addressDetails]').click();
55-
57+
5658
// Should see error message for address1 when inout with special characters is entered
5759
await page.locator('#field-input--address1').fill('@£%3dComic Relief');
5860
await expect(page.locator('#field-error--address1 > span')).toHaveText("This field only accepts alphanumeric characters and ' . - & _ /");
5961
await page.locator('#field-input--town').fill(' Comic Relief');
6062
await expect(page.locator('#field-error--town > span')).toHaveText("This field only accepts alphanumeric characters and ' . - & _ /");
61-
63+
6264
await page.close();
6365
});
6466
});

playwright-local/tests/submit/postcodeLookup.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ test.describe('Postcode validation', () => {
1616
test('Postcode formatting errors', async ({ page }) => {
1717
const postcodes = [
1818
{ code: 'S E 1 7 T P', message: 'Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.' },
19-
{ code: 'se17tp', message: 'Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.' },
20-
{ code: 'SE17TP', message: 'Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.' },
2119
{ code: 'SE$%TP', message: 'Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.' }
2220
];
2321

0 commit comments

Comments
 (0)