import { expect } from 'chai'; import { generateSessionToken } from '../src/helpers'; describe('Helpers', () => { it('should generate a token of a correct length', () => { const length = 16; // Specify the length of the token to generate const token = generateSessionToken(length); // Since the token is hexadecimal, its string length should be twice the byte length expect(token).to.be.a('string'); expect(token.length).to.equal(length); }); it('should generate a unique token each time', () => { const tokens = new Set(); const tokenCount = 1000; // Generate a number of tokens to test uniqueness const length = 16; for (let i = 0; i < tokenCount; i++) { const token = generateSessionToken(length); tokens.add(token); } // If all tokens are unique, the set's size should match the number of generated tokens expect(tokens.size).to.equal(tokenCount); }); it('should throw an exception if an invalid length is provided', () => { const invalidLength = 0; // Zero or negative length or other invalid values could be tested expect(() => generateSessionToken(invalidLength)).to.throw(); }); });