|
| 1 | +import test from 'ava' |
| 2 | +import {generatePassword} from '../src' |
| 3 | + |
| 4 | +test('returns a string', t => { |
| 5 | + const expected = 'string' |
| 6 | + const actual = typeof generatePassword(10) |
| 7 | + t.deepEqual(actual, expected) |
| 8 | +}) |
| 9 | + |
| 10 | +test('returns an empty string', t => { |
| 11 | + const expected = '' |
| 12 | + const actual = generatePassword(0, 0, 0, 0, 0) |
| 13 | + t.deepEqual(actual, expected) |
| 14 | +}) |
| 15 | + |
| 16 | +test('Returns a password of the correct length', t => { |
| 17 | + const expected = 10 |
| 18 | + const actual = generatePassword(10).length |
| 19 | + t.deepEqual(actual, expected) |
| 20 | +}) |
| 21 | + |
| 22 | +test('Returns a password of the default length', t => { |
| 23 | + const expected = 8 |
| 24 | + const actual = generatePassword().length |
| 25 | + t.deepEqual(actual, expected) |
| 26 | +}) |
| 27 | + |
| 28 | +test('Returns a password with CAPITALS', t => { |
| 29 | + const expected = 'X' |
| 30 | + const regex = /[A-Z]{10}/ |
| 31 | + const actual = generatePassword(10, 10, 0, 0, 0).replace(regex, 'X') |
| 32 | + t.deepEqual(actual, expected) |
| 33 | +}) |
| 34 | + |
| 35 | +test('Returns a password with lowercase', t => { |
| 36 | + const expected = 'X' |
| 37 | + const regex = /[a-z]{10}/ |
| 38 | + const actual = generatePassword(10, 0, 10, 0, 0).replace(regex, 'X') |
| 39 | + t.deepEqual(actual, expected) |
| 40 | +}) |
| 41 | + |
| 42 | +test('Returns a password with digits', t => { |
| 43 | + const expected = 'X' |
| 44 | + const regex = /[0-9]{10}/ |
| 45 | + const actual = generatePassword(10, 0, 0, 0, 10).replace(regex, 'X') |
| 46 | + t.deepEqual(actual, expected) |
| 47 | +}) |
| 48 | + |
| 49 | +test('Returns a password with specialchars', t => { |
| 50 | + const expected = 'X' |
| 51 | + const regex = /[!@#$%^&*()_+{}:"<>?\\|\[\];',./`~]{10}/ |
| 52 | + const actual = generatePassword(10, 0, 0, 10, 0).replace(regex, 'X') |
| 53 | + t.deepEqual(actual, expected) |
| 54 | +}) |
0 commit comments