feat(new tool): string obfuscator (#575)

This commit is contained in:
Corentin THOMASSET 2023-08-16 23:43:45 +02:00 committed by GitHub
parent f235dcd6c1
commit c58d6e3423
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 119 additions and 1 deletions

View file

@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest';
import { obfuscateString } from './string-obfuscator.model';
describe('string-obfuscator model', () => {
describe('obfuscateString', () => {
it('the characters in the middle of the string are replaced by the replacement character', () => {
expect(obfuscateString('1234567890')).toBe('1234******');
expect(obfuscateString('1234567890', { replacementChar: 'x' })).toBe('1234xxxxxx');
expect(obfuscateString('1234567890', { keepFirst: 5 })).toBe('12345*****');
expect(obfuscateString('1234567890', { keepFirst: 0, keepLast: 5 })).toBe('*****67890');
expect(obfuscateString('1234567890', { keepFirst: 5, keepLast: 5 })).toBe('1234567890');
expect(obfuscateString('1234567890', { keepFirst: 2, keepLast: 2, replacementChar: 'x' })).toBe('12xxxxxx90');
});
it('by default, the spaces are kept, they can be removed with the keepSpace option', () => {
expect(obfuscateString('12345 67890')).toBe('1234* *****');
expect(obfuscateString('12345 67890', { keepSpace: false })).toBe('1234*******');
});
});
});