Skip to content

Commit

Permalink
Write unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: alumag <10659903+alumag@users.noreply.github.com>
  • Loading branch information
alumag committed Jan 13, 2023
1 parent e26a091 commit 03fbe2e
Show file tree
Hide file tree
Showing 19 changed files with 2,697 additions and 4 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const path = require('path');
const ETHNICITIES = ['jew', 'muslim', 'christian', 'druze', 'other'];
const GENDERS = ['male', 'female'];

const getFilePath = filename => path.join(__dirname, 'data', filename);
const environment = process.env.JEST_WORKER_ID ? 'testing' : 'production';

const getFilePath = filename => path.join(__dirname, environment === 'testing' ? 'test' : 'data', filename);

const FILES = {
'first:jew:male': getFilePath('jew.male.first'),
Expand Down Expand Up @@ -72,7 +74,7 @@ function getName(filename) {
return name
}
}
return "";
return '';
}

function getFirstName(ethnicity, gender) {
Expand Down
67 changes: 67 additions & 0 deletions index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const { getFirstName, getLastName, getFullName } = require('.');

describe('test hebrew-names', () => {
describe('getFirstName', () => {
test.each([
['christian', 'male', 'אליאס'],
['christian', 'female', 'מריה'],
['druze', 'male', 'סולימאן'],
['druze', 'female', 'נור'],
['jew', 'male', 'דוד'],
['jew', 'female', 'נועה'],
['muslim', 'male', 'מוחמד'],
['muslim', 'female', 'פאטמה'],
['other', 'male', 'דניאל'],
['other', 'female', 'ניקול'],
])('should get random first name for ethnicity=%s and gender=%s', (ethnicity, gender, expectedName) => {
expect(getFirstName(ethnicity, gender)).toMatch(expectedName);
});

test('should get random first name', () => {
expect(getFirstName()).toStrictEqual(expect.any(String));
});

test('should throw an error with unsupported gender', () => {
expect(() => getFirstName(undefined, 'unknown')).toThrow(TypeError);
});

test('should throw an error with unsupported ethnicity', () => {
expect(() => getFirstName('unknown', undefined)).toThrow(TypeError);
});
});

describe('getLastName', () => {
test.each([
['christian', "ח'ורי"],
['druze', 'חלבי'],
['jew', 'כהן'],
['muslim', 'אגבאריה'],
['other', ''],
])('should get random last name for ethnicity=%s', (ethnicity, expectedName) => {
expect(getLastName(ethnicity)).toMatch(expectedName);
});

test('should get random last name', () => {
expect(getLastName()).toStrictEqual(expect.any(String));
});


test('should throw an error with unsupported ethnicity', () => {
expect(() => getLastName('unknown')).toThrow(TypeError);
});
});

describe('getFullName', () => {
test('should get random full name', () => {
expect(getFullName()).toStrictEqual(expect.any(String));
});

test('should throw an error with unsupported gender', () => {
expect(() => getFullName(undefined, 'unknown')).toThrow(TypeError);
});

test('should throw an error with unsupported ethnicity', () => {
expect(() => getFullName('unknown', undefined)).toThrow(TypeError);
});
});
});
Loading

0 comments on commit 03fbe2e

Please # to comment.