template-web-astro/tests/basic.test.ts
Florian Bouillon ae1b7f9ec4 feat: v0
Signed-off-by: Avior <github@avior.me>
2023-06-22 00:50:42 +02:00

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)
})