streamkeys.test.ts 875 B

1234567891011121314151617181920212223242526
  1. import { generateRndKey } from '../components/admin/config/server/StreamKeys';
  2. describe('generateRndKey', () => {
  3. test('should generate a key that matches the regular expression', () => {
  4. const key = generateRndKey();
  5. const regex = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#$^&*]).{8,192}$/;
  6. expect(regex.test(key)).toBe(true);
  7. });
  8. test('returns a string', () => {
  9. const result = generateRndKey();
  10. expect(typeof result).toBe('string');
  11. });
  12. test('should generate a key of length between 8 and 192 characters', () => {
  13. const key = generateRndKey();
  14. expect(key.length).toBeGreaterThanOrEqual(8);
  15. expect(key.length).toBeLessThanOrEqual(192);
  16. });
  17. test('should generate a unique key on each invocation', () => {
  18. const key1 = generateRndKey();
  19. const key2 = generateRndKey();
  20. expect(key1).not.toBe(key2);
  21. });
  22. });