Skip to content

Commit

Permalink
Add a few unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Jan 10, 2025
1 parent a1267d2 commit 2ca61df
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions test/crypto.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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));

});
Expand All @@ -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}$/);

});

});

});

0 comments on commit 2ca61df

Please sign in to comment.