From 384d1bd64f97b473a43c7f2ac72ce17b5a28b559 Mon Sep 17 00:00:00 2001 From: saisarans2007 Date: Fri, 23 Oct 2026 18:47:16 +0530 Subject: [PATCH] fix(profile): add missing UN member states to the country list isValidCountry rejected Antigua and Barbuda, Congo and the Democratic Republic of the Congo, so users from those countries couldn't save their country on the profile. --- backend/tests/nameCountry.unit.test.js | 22 ++++++++++++++++++++++ backend/utils/nameCountry.js | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 backend/tests/nameCountry.unit.test.js diff --git a/backend/tests/nameCountry.unit.test.js b/backend/tests/nameCountry.unit.test.js new file mode 100644 index 00000000..4bff7d3a --- /dev/null +++ b/backend/tests/nameCountry.unit.test.js @@ -0,0 +1,22 @@ +import { describe, it, expect } from 'vitest'; +const { isValidCountry } = require('../utils/nameCountry'); + +describe('isValidCountry', () => { + it.each([ + 'Antigua and Barbuda', + 'Congo', + 'Democratic Republic of the Congo', + ])('accepts UN member state %s', (country) => { + expect(isValidCountry(country)).toBe(true); + }); + + it('matches case-insensitively and ignores surrounding spaces', () => { + expect(isValidCountry(' democratic republic of the congo ')).toBe(true); + }); + + it('still rejects names that are not countries', () => { + expect(isValidCountry('Narnia')).toBe(false); + expect(isValidCountry('12345')).toBe(false); + expect(isValidCountry('')).toBe(false); + }); +}); diff --git a/backend/utils/nameCountry.js b/backend/utils/nameCountry.js index 39984dae..8a8b32b5 100644 --- a/backend/utils/nameCountry.js +++ b/backend/utils/nameCountry.js @@ -4,6 +4,7 @@ const countries = [ "Algeria", "Andorra", "Angola", + "Antigua and Barbuda", "Argentina", "Armenia", "Australia", @@ -36,11 +37,13 @@ const countries = [ "China", "Colombia", "Comoros", + "Congo", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia", + "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica",