import { describe, expect, it, beforeAll } from 'vitest'; import { setCryptoBackend } from './backend'; import { makeWasmTestBackend } from './testBackend'; import { generateRecoveryCode, normalizeRecoveryCode, RECOVERY_CODE_LEN } from './recoveryCode'; beforeAll(async () => { setCryptoBackend(await makeWasmTestBackend()); }); describe('recoveryCode', () => { it('generates a 24-char alphabet-restricted code grouped 4×6 with dashes', async () => { const code = await generateRecoveryCode(); expect(code).toHaveLength(27); const groups = code.split('-'); expect(groups).toHaveLength(4); for (const g of groups) expect(g).toMatch(/^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{6}$/); }); it('normalizeRecoveryCode strips dashes/spaces and uppercases', () => { expect(normalizeRecoveryCode(' abcdef-ghjklm-npqrst-uvwxyz ')).toBe('ABCDEFGHJKLMNPQRSTUVWXYZ'); }); it('normalizeRecoveryCode drops characters outside the alphabet', () => { expect(normalizeRecoveryCode('AB1OD-EF0H1J')).toBe('ABDEFHJ'); }); it('RECOVERY_CODE_LEN matches alphabet length', () => { expect(RECOVERY_CODE_LEN).toBe(24); }); });