Skip to content

Commit

Permalink
tests: add translations assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilan Kushnir committed Nov 27, 2024
1 parent 867b92c commit dc224d8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/unit/matchers.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'mocha';
import { expect } from 'chai';
import { uppercaseMatcher, lowercaseMatcher, numberMatcher, specialMatcher, minLengthMatcher } from '../../src';
import { customMatchersTranslations } from '../../src/translations';

describe('uppercaseMatcher', () => {
it('should return a match for missing uppercase letters', () => {
const result = uppercaseMatcher.Matching.prototype.match({ password: 'password123!' });
expect(result).to.deep.include({ pattern: 'uppercaseRequired', token: 'password123!', i: 0, j: 11 });
expect(customMatchersTranslations.warnings.uppercaseRequired).to.equal('At least one uppercase letter is required.');
expect(customMatchersTranslations.suggestions.uppercaseRequired).to.equal('Include at least one uppercase letter.');
});

it('should return a score of -100 for missing uppercase letters', () => {
Expand All @@ -19,6 +22,8 @@ describe('lowercaseMatcher', () => {
it('should return a match for missing lowercase letters', () => {
const result = lowercaseMatcher.Matching.prototype.match({ password: 'PASSWORD123!' });
expect(result).to.deep.include({ pattern: 'lowercaseRequired', token: 'PASSWORD123!', i: 0, j: 11 });
expect(customMatchersTranslations.warnings.lowercaseRequired).to.equal('At least one lowercase letter is required.');
expect(customMatchersTranslations.suggestions.lowercaseRequired).to.equal('Include at least one lowercase letter.');
});

it('should return a score of -100 for missing lowercase letters', () => {
Expand All @@ -32,6 +37,8 @@ describe('numberMatcher', () => {
it('should return a match for missing numbers', () => {
const result = numberMatcher.Matching.prototype.match({ password: 'Password!' });
expect(result).to.deep.include({ pattern: 'numberRequired', token: 'Password!', i: 0, j: 8 });
expect(customMatchersTranslations.warnings.numberRequired).to.equal('At least one number is required.');
expect(customMatchersTranslations.suggestions.numberRequired).to.equal('Include at least one number.');
});

it('should return a score of -100 for missing numbers', () => {
Expand All @@ -45,6 +52,8 @@ describe('specialMatcher', () => {
it('should return a match for missing special characters', () => {
const result = specialMatcher.Matching.prototype.match({ password: 'Password123' });
expect(result).to.deep.include({ pattern: 'specialRequired', token: 'Password123', i: 0, j: 10 });
expect(customMatchersTranslations.warnings.specialRequired).to.equal('At least one special character is required.');
expect(customMatchersTranslations.suggestions.specialRequired).to.equal('Include at least one special character.');
});

it('should return a score of -100 for missing special characters', () => {
Expand All @@ -61,6 +70,8 @@ describe('minLengthMatcher', () => {
it('should return a match for passwords shorter than the minimum length', () => {
const result = matcher.Matching.prototype.match({ password: 'short' });
expect(result).to.deep.include({ pattern: 'minLength', token: 'short', i: 0, j: 4 });
expect(customMatchersTranslations.warnings.minLength).to.equal('Password must be at least 12 characters long.');
expect(customMatchersTranslations.suggestions.minLength).to.equal('Password may not be shorter than 12 characters.');
});

it('should return no matches for passwords meeting the minimum length', () => {
Expand Down

0 comments on commit dc224d8

Please sign in to comment.