31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
const dotenv = require("dotenv");
|
|
const {verify, hash, generatePassword} = require("./password");
|
|
|
|
dotenv.config();
|
|
|
|
describe('Password.js Tests', () => {
|
|
const password = 'password';
|
|
test('hash should return a hashed password', async () => {
|
|
const hashedPassword = await hash(password);
|
|
expect(hashedPassword).not.toEqual(password);
|
|
});
|
|
|
|
test('verify should return true for a valid password', async () => {
|
|
const hashedPassword = await hash(password);
|
|
const result = await verify(password, hashedPassword);
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('verify should return false for an invalid password', async () => {
|
|
const hashedPassword = await hash(password);
|
|
const result = await verify(password + 'a', hashedPassword);
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test('generatePassword should return a valid password', async () => {
|
|
const generatedPassword = await generatePassword();
|
|
const hashedpass = await hash(generatedPassword);
|
|
const result = await verify(generatedPassword, hashedpass);
|
|
expect(result).toBe(true);
|
|
});
|
|
}); |