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",