Skip to content

Commit

Permalink
Fix NISN unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
magicjar committed Feb 27, 2024
1 parent ebee470 commit e898f4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/test/functions/_nomorIndukSiswaNasional.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { isValidNISN as isValid } from "../../ts/functions/index"
import { NISN_LENGTH, NISN_AGE_VALIDITY } from "../../ts/datas/nisn"

describe('NISN', () => {
var currentYear = new Date().getFullYear();
var twentyOneYearsAgo = currentYear - 21;
var tenYearsAgo = currentYear - 10;

it('cannot be empty', () => {
expect(isValid('')).to.be.false
})
Expand Down Expand Up @@ -35,14 +39,14 @@ describe('NISN', () => {
})

describe('is valid', () => {
it('if it contains ' + NISN_LENGTH + ' digit numbers', () => {
expect(isValid('0061231234')).to.be.true // Birth year => 2006
expect(isValid('9991231234')).to.be.true // Birth year => 1999
it('if it match with NISN length of ' + NISN_LENGTH + ' digit numbers', () => {
expect(isValid(twentyOneYearsAgo.toString().substring(1) + '1231234')).to.be.true // Birth year => 20 years ago
expect(isValid(tenYearsAgo.toString().substring(1) + '1231234')).to.be.true // Birth year => 10 years ago
})

it('if it still inside student periode of ' + NISN_AGE_VALIDITY + ' years', () => {
expect(isValid('0061231234')).to.be.true // Birth year => 2006
expect(isValid('9991231234')).to.be.true // Birth year => 1999
expect(isValid(twentyOneYearsAgo.toString().substring(1) + '1231234')).to.be.true // Birth year => 20 years ago
expect(isValid(tenYearsAgo.toString().substring(1) + '1231234')).to.be.true // Birth year => 10 years ago
})
})

Expand Down
6 changes: 3 additions & 3 deletions src/ts/functions/_nomorIndukSiswaNasional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class NomorIndukSiswaNasional implements IValid {

const validNISN = NISN_REGEX.exec(numbersOnly(nisn))

return validNISN !== null
&& this.isValidPeriod(validNISN[1])
return validNISN !== null
&& this.isValidPeriod(validNISN[1])
&& correctLength(0, validNISN[0].length, { minLength: NISN_LENGTH })
}

Expand All @@ -27,7 +27,7 @@ class NomorIndukSiswaNasional implements IValid {

if (birthYear > thisYear)
birthYear = birthYear - 1000

return birthYear < endYear ? false : true
}
}
Expand Down

0 comments on commit e898f4d

Please sign in to comment.