-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from softrams/64-test
Password Utility Test
- Loading branch information
Showing
6 changed files
with
92 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { generateHash, updatePassword, compare } from './password.utility'; | ||
|
||
describe('password utility', () => { | ||
test('generateHash to work', async () => { | ||
const password = 'qwerty'; | ||
const hashedPassword = await generateHash(password); | ||
expect(hashedPassword).toBeDefined(); | ||
}); | ||
|
||
test('compare hash success', async (done) => { | ||
const oldPassword = await generateHash('qwerty'); | ||
const currentPassword = 'qwerty'; | ||
await expect(compare(currentPassword, oldPassword)).resolves.toBeTruthy(); | ||
done(); | ||
}); | ||
|
||
test('compare hash failure', async (done) => { | ||
const oldPassword = await generateHash('qwerty'); | ||
const currentPassword = 'qwerty2'; | ||
await expect(compare(currentPassword, oldPassword)).resolves.toBeFalsy(); | ||
done(); | ||
}); | ||
|
||
test('compare hash bcrypt failure', async (done) => { | ||
await expect(compare(null, 0)).rejects.toBe('Bcrypt comparison failure'); | ||
done(); | ||
}); | ||
|
||
test('password updated successfully', async () => { | ||
const currentPassword = 'qwerty'; | ||
const oldPassword = await generateHash(currentPassword); | ||
const newPassword = 'newQwerty'; | ||
const result = await updatePassword(oldPassword, currentPassword, newPassword); | ||
expect(result).toEqual(expect.anything()); | ||
}); | ||
|
||
test('password updated failure', async (done) => { | ||
const currentPassword = 'qwerty2'; | ||
const oldPassword = await generateHash('1234'); | ||
const newPassword = 'newQwerty'; | ||
await expect(updatePassword(oldPassword, currentPassword, newPassword)).rejects.toBe('Incorrect previous password'); | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters