diff --git a/test/crypto.ts b/test/crypto.ts index 173f8aa8..9fbdbc68 100644 --- a/test/crypto.ts +++ b/test/crypto.ts @@ -1,4 +1,4 @@ -import { generateSecretToken, uuidUrn } from '../src/crypto.js'; +import { generateSecretToken, uuidUrn, generatePublicId, generatePassword, generateVerificationDigits } from '../src/crypto.js'; import { strict as assert } from 'node:assert'; import { describe, it } from 'node:test'; @@ -9,7 +9,6 @@ describe('Crypto utilities', () => { it('should generate a 32-byte secret token', async () => { const token = await generateSecretToken(); - assert.equal(token.length,Math.ceil(32 / 3 * 4)); }); @@ -35,4 +34,44 @@ describe('Crypto utilities', () => { }); + describe('generatePublicId()', () => { + + it('should generate a public id', async () => { + + const id = await generatePublicId(); + assert.equal(id.length, 11); + + }); + + }); + + describe('generatePassword()', () => { + + it('should generate a password', () => { + + const password = generatePassword(); + assert.match(password, /^[a-z-]{20,}$/); + + }); + + }); + + describe('generateVerificationDigits()', () => { + + it('should generate a verification code', () => { + + const code = generateVerificationDigits(); + assert.match(code, /^[0-9]{6}$/); + + }); + + it('should generate a verification code of the requested length', () => { + + const code = generateVerificationDigits(8); + assert.match(code, /^[0-9]{8}$/); + + }); + + }); + });