2024-03-28 14:49:15 +08:00
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
|
2023-09-22 13:43:56 +08:00
|
|
|
import { generateStandardId, generateStandardSecret, generateStandardShortId } from './id.js';
|
2022-02-21 16:42:17 +08:00
|
|
|
|
2023-09-22 13:43:56 +08:00
|
|
|
describe('standard id generator', () => {
|
2022-02-21 16:42:17 +08:00
|
|
|
it('should match the input length', () => {
|
2023-09-22 13:43:56 +08:00
|
|
|
const id = generateStandardId();
|
|
|
|
expect(id.length).toEqual(21);
|
2022-02-21 16:42:17 +08:00
|
|
|
});
|
2023-09-22 13:43:56 +08:00
|
|
|
});
|
2022-02-21 16:42:17 +08:00
|
|
|
|
2023-09-22 13:43:56 +08:00
|
|
|
describe('standard short id generator', () => {
|
|
|
|
it('should match the input length', () => {
|
|
|
|
const id = generateStandardShortId();
|
|
|
|
expect(id.length).toEqual(12);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('standard secret generator', () => {
|
|
|
|
it('should match the input length', () => {
|
|
|
|
const id = generateStandardSecret();
|
|
|
|
expect(id.length).toEqual(32);
|
|
|
|
});
|
2022-02-21 16:42:17 +08:00
|
|
|
|
2023-09-22 13:43:56 +08:00
|
|
|
it('should generate id with uppercase', () => {
|
|
|
|
// If it can't generate uppercase, it will timeout
|
|
|
|
while (!/[A-Z]/.test(generateStandardSecret())) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2022-02-21 16:42:17 +08:00
|
|
|
});
|
|
|
|
});
|