34 lines
872 B
TypeScript
34 lines
872 B
TypeScript
import { assert, expect, test } from 'vitest'
|
|
import { comparePassword, hashPassword } from '../src/libs/AuthUtils'
|
|
|
|
// Edit an assertion and save to see HMR in action
|
|
|
|
test('Math.sqrt()', () => {
|
|
expect(Math.sqrt(4)).toBe(2);
|
|
expect(Math.sqrt(144)).toBe(12);
|
|
expect(Math.sqrt(2)).toBe(Math.SQRT2);
|
|
});
|
|
|
|
test('JSON', () => {
|
|
const input = {
|
|
foo: 'hello',
|
|
bar: 'world',
|
|
};
|
|
|
|
const output = JSON.stringify(input);
|
|
|
|
expect(output).eq('{"foo":"hello","bar":"world"}');
|
|
assert.deepEqual(JSON.parse(output), input, 'matches original');
|
|
});
|
|
|
|
test('auth util', async () => {
|
|
const password = 'pouet'
|
|
|
|
const out1 = await hashPassword(password)
|
|
expect(out1).not.toBe(password)
|
|
const out2 = await hashPassword(password)
|
|
expect(out2).not.toBe(out1)
|
|
expect(await comparePassword(password, out1)).toBe(true)
|
|
expect(await comparePassword(password, out2)).toBe(true)
|
|
})
|