Skip to content

Commit

Permalink
Merge pull request #8 from vellotis/bug-invalid-generated-isikukood
Browse files Browse the repository at this point in the history
Fix #7
  • Loading branch information
dknight authored Sep 21, 2016
2 parents d82bf0c + 80733a3 commit 8c6a4fc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "isikukood",
"version": "1.1.1",
"version": "1.1.2",
"homepage": "http://www.whoop.ee/posts/2014/02/17/validation-and-generation-of-estonian-personal-id.html",
"authors": [
"dknight <[email protected]>"
Expand Down
9 changes: 2 additions & 7 deletions isikukood.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,8 @@
if (params.birthDay) {
d = params.birthDay;
} else {
if (m === 2 && y % 4 !== 0 || y % 100 === 0 && y % 400 !== 0) {
d = Math.round(Math.random() * 29);
} else if (m === 2) {
d = Math.round(Math.random() * 28);
} else {
d = Math.round(Math.random() * 30);
}
var daysInMonth = new Date(y, m, 0).getDate();
d = Math.floor(Math.random() * daysInMonth) + 1;
}

// Set the gender
Expand Down
2 changes: 1 addition & 1 deletion isikukood.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "isikukood",
"version": "1.1.1",
"version": "1.1.2",
"description": "Estonian personal ID (isikukood) JavaScript module",
"main": "isikukood.js",
"directories": {
Expand Down
18 changes: 15 additions & 3 deletions test/spec/IsikukoodSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ describe('Generated Isikukood', function () {
expect(ik.getControlNumber()).toBeDefined();
expect(ik.getControlNumber()).toEqual(lastNumber);
});
it('should have correct day in range of 01 to 31 (#7)', function () {
for (var i = 0; i < 200; i++) {
expect(Isikukood.generate().substr(5, 2)).not.toBe('00');
}
});
describe('generated Isikukood (#7)', function () {
Array(200).fill(null).map(function (undef, i) {
return Isikukood.generate();
}).forEach(function (code) {
it( code + ' should be valid', function () {
var ik = new Isikukood(code);
expect(ik.validate()).toBe(true);
});
})
});
});

describe('Isikukood 35703150220', function () {
Expand Down Expand Up @@ -85,9 +100,6 @@ describe('Isikukood 49200186017', function () {
it('should not validate', function () {
expect(ik.validate()).toBe(false);
});
it('should return female as a gender', function () {
expect(ik.getGender()).toBe('female');
});
});

describe('Isikukood 60311213742 (#5)', function () {
Expand Down

0 comments on commit 8c6a4fc

Please sign in to comment.