|
1 | 1 | import test from 'ava'
|
2 | 2 |
|
3 |
| -import { verifySync, compareSync, verify, compare, hash } from '../index' |
| 3 | +import { verifySync, compareSync, verify, compare, hash, genSaltSync, genSalt } from '../index' |
4 | 4 |
|
5 | 5 | const { hashSync } = require('bcryptjs')
|
6 | 6 |
|
7 | 7 | const fx = Buffer.from('bcrypt-test-password')
|
8 | 8 |
|
9 | 9 | const hashedPassword = hashSync(fx.toString('utf8'), 10)
|
10 | 10 |
|
| 11 | +test('genSaltSync should return a string', (t) => { |
| 12 | + t.is(typeof genSaltSync(10), 'string') |
| 13 | + t.is(typeof genSaltSync(10, '2a'), 'string') |
| 14 | + t.is(typeof genSaltSync(10, '2b'), 'string') |
| 15 | + t.is(typeof genSaltSync(10, '2y'), 'string') |
| 16 | + t.is(typeof genSaltSync(10, '2x'), 'string') |
| 17 | + t.throws(() => genSaltSync(10, 'invalid' as any)) |
| 18 | +}) |
| 19 | + |
| 20 | +test('genSalt should return a string', async (t) => { |
| 21 | + t.is(typeof (await genSalt(10)), 'string') |
| 22 | + t.is(typeof (await genSalt(10, '2a')), 'string') |
| 23 | + t.is(typeof (await genSalt(10, '2b')), 'string') |
| 24 | + t.is(typeof (await genSalt(10, '2y')), 'string') |
| 25 | + t.is(typeof (await genSalt(10, '2x')), 'string') |
| 26 | + await t.throwsAsync(async () => genSalt(10, 'invalid' as any)) |
| 27 | +}) |
| 28 | + |
11 | 29 | test('verifySync hashed password from bcrypt should be true', (t) => {
|
12 | 30 | t.true(verifySync(fx, hashedPassword))
|
13 | 31 | })
|
|
0 commit comments