mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-08-03 20:45:18 +02:00
feat(tool): added token generator
This commit is contained in:
parent
25a8659786
commit
40dec52c84
5 changed files with 189 additions and 46 deletions
98
src/tools/token-generator/token-generator.service.test.ts
Normal file
98
src/tools/token-generator/token-generator.service.test.ts
Normal file
|
@ -0,0 +1,98 @@
|
|||
import { expect, describe, it } from 'vitest';
|
||||
import { createToken } from './token-generator.service';
|
||||
|
||||
describe('token-generator', () => {
|
||||
describe('createToken', () => {
|
||||
it('should generate an empty string when all params are false', () => {
|
||||
const token = createToken({
|
||||
withLowercase: false,
|
||||
withUppercase: false,
|
||||
withNumbers: false,
|
||||
withSymbols: false,
|
||||
length: 10,
|
||||
});
|
||||
|
||||
expect(token).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should generate a random string with the specified length', () => {
|
||||
const createTokenWithLength = (length: number) =>
|
||||
createToken({
|
||||
withLowercase: true,
|
||||
withUppercase: true,
|
||||
withNumbers: true,
|
||||
withSymbols: true,
|
||||
length,
|
||||
});
|
||||
|
||||
expect(createTokenWithLength(5)).toHaveLength(5);
|
||||
expect(createTokenWithLength(10)).toHaveLength(10);
|
||||
expect(createTokenWithLength(100)).toHaveLength(100);
|
||||
});
|
||||
|
||||
it('should generate a random string with just uppercase if only withUppercase is set', () => {
|
||||
const token = createToken({
|
||||
withLowercase: false,
|
||||
withUppercase: true,
|
||||
withNumbers: false,
|
||||
withSymbols: false,
|
||||
length: 256,
|
||||
});
|
||||
|
||||
expect(token).toHaveLength(256);
|
||||
expect(token).toMatch(/^[A-Z]+$/);
|
||||
});
|
||||
|
||||
it('should generate a random string with just lowercase if only withLowercase is set', () => {
|
||||
const token = createToken({
|
||||
withLowercase: true,
|
||||
withUppercase: false,
|
||||
withNumbers: false,
|
||||
withSymbols: false,
|
||||
length: 256,
|
||||
});
|
||||
|
||||
expect(token).toHaveLength(256);
|
||||
expect(token).toMatch(/^[a-z]+$/);
|
||||
});
|
||||
|
||||
it('should generate a random string with just numbers if only withNumbers is set', () => {
|
||||
const token = createToken({
|
||||
withLowercase: false,
|
||||
withUppercase: false,
|
||||
withNumbers: true,
|
||||
withSymbols: false,
|
||||
length: 256,
|
||||
});
|
||||
|
||||
expect(token).toHaveLength(256);
|
||||
expect(token).toMatch(/^[0-9]+$/);
|
||||
});
|
||||
|
||||
it('should generate a random string with just symbols if only withSymbols is set', () => {
|
||||
const token = createToken({
|
||||
withLowercase: false,
|
||||
withUppercase: false,
|
||||
withNumbers: false,
|
||||
withSymbols: true,
|
||||
length: 256,
|
||||
});
|
||||
|
||||
expect(token).toHaveLength(256);
|
||||
expect(token).toMatch(/^[.,;:!?./\-"'#{([-|\\@)\]=}*+]+$/);
|
||||
});
|
||||
|
||||
it('should generate a random string with just letters (case incensitive) with withLowercase and withUppercase', () => {
|
||||
const token = createToken({
|
||||
withLowercase: true,
|
||||
withUppercase: true,
|
||||
withNumbers: false,
|
||||
withSymbols: false,
|
||||
length: 256,
|
||||
});
|
||||
|
||||
expect(token).toHaveLength(256);
|
||||
expect(token).toMatch(/^[a-zA-Z]+$/);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue