mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 10:23:54 +00:00
V2 types (#291)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { generateId } from './generateId.js';
|
||||
|
||||
test('generate a valid 5 digit id', () => {
|
||||
const id = generateId();
|
||||
expect(id.length).toBe(5);
|
||||
});
|
||||
|
||||
test('generate 100 with less than 110 attempts', () => {
|
||||
const ids = new Set<string>();
|
||||
let attempts = 1;
|
||||
while (ids.size < 100) {
|
||||
ids.add(generateId());
|
||||
attempts++;
|
||||
}
|
||||
|
||||
expect(attempts).toBeLessThan(105);
|
||||
});
|
||||
|
||||
test('generate 1000 with less than 1020 attempts', () => {
|
||||
const ids = new Set<string>();
|
||||
let attempts = 1;
|
||||
while (ids.size < 1000) {
|
||||
ids.add(generateId());
|
||||
attempts++;
|
||||
}
|
||||
|
||||
expect(attempts).toBeLessThan(1020);
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import { customAlphabet } from 'nanoid';
|
||||
|
||||
const nanoid = customAlphabet('1234567890abcdef', 5);
|
||||
|
||||
/**
|
||||
* Generates a random id from the defined alphabet
|
||||
*/
|
||||
export const generateId = (): string => nanoid();
|
||||
Reference in New Issue
Block a user