Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions backend/tests/nameCountry.unit.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
3 changes: 3 additions & 0 deletions backend/utils/nameCountry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const countries = [
"Algeria",
"Andorra",
"Angola",
"Antigua and Barbuda",
"Argentina",
"Armenia",
"Australia",
Expand Down Expand Up @@ -36,11 +37,13 @@ const countries = [
"China",
"Colombia",
"Comoros",
"Congo",
"Costa Rica",
"Croatia",
"Cuba",
"Cyprus",
"Czechia",
"Democratic Republic of the Congo",
"Denmark",
"Djibouti",
"Dominica",
Expand Down
Loading