-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from satyam-seth/unit-test-utils
Unit test utils
- Loading branch information
Showing
4 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import { getOTPRegexForValueType, OTPValueType } from '../../src/ts/main'; | ||
|
||
describe('Test getOTPRegexForValueType function', () => { | ||
it('should return valid regex for valid value type', () => { | ||
const numericRegex = getOTPRegexForValueType(OTPValueType.NUMERIC); | ||
expect(numericRegex.toString()).to.equal('/[^0-9]/g'); | ||
|
||
const alphabeticRegex = getOTPRegexForValueType(OTPValueType.ALPHABETIC); | ||
expect(alphabeticRegex.toString()).to.equal('/[^A-Za-z]/g'); | ||
|
||
const alphabeticLowerRegex = getOTPRegexForValueType( | ||
OTPValueType.ALPHABETIC_LOWER | ||
); | ||
expect(alphabeticLowerRegex.toString()).to.equal('/[^a-z]/g'); | ||
|
||
const alphabeticUpperRegex = getOTPRegexForValueType( | ||
OTPValueType.ALPHABETIC_UPPER | ||
); | ||
expect(alphabeticUpperRegex.toString()).to.equal('/[^A-Z]/g'); | ||
|
||
const alphanumericRegex = getOTPRegexForValueType( | ||
OTPValueType.ALPHANUMERIC | ||
); | ||
expect(alphanumericRegex.toString()).to.equal('/[^A-Za-z0-9]/g'); | ||
|
||
const alphanumericLowerRegex = getOTPRegexForValueType( | ||
OTPValueType.ALPHANUMERIC_LOWER | ||
); | ||
expect(alphanumericLowerRegex.toString()).to.equal('/[^a-z0-9]/g'); | ||
|
||
const alphanumericUpperRegex = getOTPRegexForValueType( | ||
OTPValueType.ALPHANUMERIC_UPPER | ||
); | ||
expect(alphanumericUpperRegex.toString()).to.equal('/[^A-Z0-9]/g'); | ||
}); | ||
|
||
it('should throw error for invalid value type', () => { | ||
// @ts-ignore | ||
expect(() => getOTPRegexForValueType('invalid')).to.throw( | ||
Error, | ||
'Invalid OTP field value type' | ||
); | ||
}); | ||
}); |