aboutsummaryrefslogtreecommitdiff
path: root/src/tools/string-obfuscator/string-obfuscator.model.test.ts
diff options
context:
space:
mode:
authorGravatar Corentin THOMASSET <corentin.thomasset74@gmail.com> 2023-08-16 23:43:45 +0200
committerGravatar GitHub <noreply@github.com> 2023-08-16 21:43:45 +0000
commitc58d6e34232e199406b39cb258e8106dc6b2f9c1 (patch)
tree3a21bcc5de88be2e260a852bf7d99acdd7b42da1 /src/tools/string-obfuscator/string-obfuscator.model.test.ts
parentf235dcd6c1aeaf92ad2e1e7125aac76367e85345 (diff)
downloadit-tools-c58d6e34232e199406b39cb258e8106dc6b2f9c1.tar.gz
it-tools-c58d6e34232e199406b39cb258e8106dc6b2f9c1.tar.zst
it-tools-c58d6e34232e199406b39cb258e8106dc6b2f9c1.zip
feat(new tool): string obfuscator (#575)
Diffstat (limited to 'src/tools/string-obfuscator/string-obfuscator.model.test.ts')
-rw-r--r--src/tools/string-obfuscator/string-obfuscator.model.test.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/tools/string-obfuscator/string-obfuscator.model.test.ts b/src/tools/string-obfuscator/string-obfuscator.model.test.ts
new file mode 100644
index 0000000..08d3fc2
--- /dev/null
+++ b/src/tools/string-obfuscator/string-obfuscator.model.test.ts
@@ -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*******');
+ });
+ });
+});