import { PasswordContent } from './helpers/getPasswordContent/getPasswordContent.types' import passwordGenerator from './passwordGenerator' const LENGTH_PASSWORD_TEST = 5 describe('passwordGenerator()', () => { it('should return an error if the password length is 0', () => { try { passwordGenerator({ maxLength: 0 }) } catch (error) { expect(error.message).toBe('Could not generate the password. Please check the params!') } }) it('should return an error if all or one of the Content password parameter are false', () => { try { passwordGenerator({ maxLength: LENGTH_PASSWORD_TEST, isUpperCase: false }) } catch (error) { expect(error.message).toBe('Could not generate the password. Please check the params!') } }) it('should match upperCase password content', () => { const password = passwordGenerator({ maxLength: LENGTH_PASSWORD_TEST, isUpperCase: true }) const arrayPassword = Array.from(password) const isValueInPasswordContent = arrayPassword.every((value) => PasswordContent.UPPERCASE.includes(value)) expect(password.length).toBe(LENGTH_PASSWORD_TEST) expect(isValueInPasswordContent).toBe(true) }) it('should match lowerCase password content', () => { const password = passwordGenerator({ maxLength: LENGTH_PASSWORD_TEST, isLowerCase: true }) const arrayPassword = Array.from(password) const isValueInPasswordContent = arrayPassword.every((value) => PasswordContent.LOWERCASE.includes(value)) expect(password.length).toBe(LENGTH_PASSWORD_TEST) expect(isValueInPasswordContent).toBe(true) }) it('should match number password content', () => { const password = passwordGenerator({ maxLength: LENGTH_PASSWORD_TEST, isNumber: true }) const arrayPassword = Array.from(password) const isValueInPasswordContent = arrayPassword.every((value) => PasswordContent.NUMBER.includes(value)) expect(password.length).toBe(LENGTH_PASSWORD_TEST) expect(isValueInPasswordContent).toBe(true) }) it('should match symbol password content', () => { const password = passwordGenerator({ maxLength: LENGTH_PASSWORD_TEST, isSymbol: true }) const arrayPassword = Array.from(password) const isValueInPasswordContent = arrayPassword.every((value) => PasswordContent.BASIC_SYMBOL.includes(value)) expect(password.length).toBe(LENGTH_PASSWORD_TEST) expect(isValueInPasswordContent).toBe(true) }) it('should match upperCase and lowerCase password content', () => { const password = passwordGenerator({ maxLength: LENGTH_PASSWORD_TEST, isUpperCase: true, isLowerCase: true }) const arrayPassword = Array.from(password) const isValueInPasswordContent = arrayPassword.every( (value) => PasswordContent.UPPERCASE.includes(value) || PasswordContent.LOWERCASE.includes(value) ) expect(password.length).toBe(LENGTH_PASSWORD_TEST) expect(isValueInPasswordContent).toBe(true) }) it('should match number and symbol password content', () => { const password = passwordGenerator({ maxLength: LENGTH_PASSWORD_TEST, isNumber: true, isSymbol: true }) const arrayPassword = Array.from(password) const isValueInPasswordContent = arrayPassword.every( (value) => PasswordContent.NUMBER.includes(value) || PasswordContent.BASIC_SYMBOL.includes(value) ) expect(password.length).toBe(LENGTH_PASSWORD_TEST) expect(isValueInPasswordContent).toBe(true) }) it('should match upperCase, lowerCase, number and symbol password content', () => { const password = passwordGenerator({ maxLength: LENGTH_PASSWORD_TEST, isUpperCase: true, isLowerCase: true, isNumber: true, isSymbol: true }) const arrayPassword = Array.from(password) const isValueInPasswordContent = arrayPassword.every( (value) => PasswordContent.UPPERCASE.includes(value) || PasswordContent.LOWERCASE.includes(value) || PasswordContent.NUMBER.includes(value) || PasswordContent.BASIC_SYMBOL.includes(value) ) expect(password.length).toBe(LENGTH_PASSWORD_TEST) expect(isValueInPasswordContent).toBe(true) }) })