Skip to content

Commit

Permalink
Merge pull request #8 from mild-blue/validate-birth-order
Browse files Browse the repository at this point in the history
Add birth order validation
  • Loading branch information
misslecter authored Nov 11, 2021
2 parents a1a9796 + def54ed commit 8766714
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/__tests__/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ test('Invalid personal numbers with invalid length', () => {
expect(validate('72090978')).toHaveProperty('detail', 'Second part of personal number must have 3 or 4 digits. Input value: 72090978. Second part: 78.');
});

test('Valid and invalid birth order', () => {
expect(validate('900203/000')).toHaveProperty('detail', 'Value of birth order is invalid. Given value: 0.');
expect(validate('900203/001')).toHaveProperty('isValid', true);
});

test('Invalid personal numbers with invalid second part', () => {
expect(validate('721909/1349')).toHaveProperty('detail', 'Given personal number does not satisfy modulo condition. Input value: 721909/1349.');
expect(validate('720939/1349')).toHaveProperty('detail', 'Given personal number does not satisfy modulo condition. Input value: 720939/1349.');
Expand Down
6 changes: 6 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export const parse = (value: string): ParsingResult => {

// Get birth order
const birthOrder = Number(secondPart.substr(0, 3));
if (Number(birthOrder) < 1) {
return {
result: undefined,
message: `Value of birth order is invalid. Given value: ${birthOrder}.`
};
}

// Get age
const age = getAge(dateOfBirth);
Expand Down

0 comments on commit 8766714

Please sign in to comment.