From 85f76cc604ce3cd8fddfbdfc5b190fc97ce4bc92 Mon Sep 17 00:00:00 2001 From: Rodolfo Date: Tue, 20 Feb 2024 14:32:39 -0300 Subject: [PATCH] hotfix: fix tests --- src/index.ts | 3 ++- test/module.spec.ts | 8 +++++++- test/object.spec.ts | 10 +++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index bd4dbfc..9415092 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,7 +32,8 @@ export class Obfuscator { public blur(rawData: TTargetFieldType) { const rawDataType = typeof rawData; - if (!rawData) throw new Error('Blur data type null or undefined is not supported'); + if (rawData === null || rawData === undefined) + throw new Error('Blur data type null or undefined is not supported'); switch (rawDataType) { case 'object': diff --git a/test/module.spec.ts b/test/module.spec.ts index 2aeb6a8..1966810 100644 --- a/test/module.spec.ts +++ b/test/module.spec.ts @@ -53,9 +53,15 @@ describe('Testing Obfuscator module and structures', () => { expect(obf.blur('222.222.222-54')).not.toEqual('222.222.222-54'); }); + it('Obfuscator null should throw error', () => { + const obf = new Obfuscator(); + expect(obf.blur); + expect(obf.blur.bind((null as unknown) as TTargetFieldType)).toThrow(/Blur data type null or undefined is not supported/); + }); + it('Obfuscator with different type of input', () => { const obf = new Obfuscator(); expect(obf.blur); - expect(obf.blur.bind((true as unknown) as TTargetFieldType)).toThrow(/Data type not supported/); + expect(obf.blur.bind((true as unknown) as TTargetFieldType)).toThrow(/Blur data type null or undefined is not supported/); }); }); diff --git a/test/object.spec.ts b/test/object.spec.ts index e8275d4..9fed8d8 100644 --- a/test/object.spec.ts +++ b/test/object.spec.ts @@ -2,7 +2,7 @@ import { Obfuscator } from '../dist/cjs'; const replacerText = `NOT_VISIBLE`; -function generateText(defaultDirtyStringData: string | object) { +function generateText(defaultDirtyStringData: any) { const obf = new Obfuscator({ replacerText: replacerText, }); @@ -45,4 +45,12 @@ describe('Blur Value successfully from object', () => { }); expect(obf.blur({ obfuscator: 'teste' })).toEqual({ obfuscator: replacerText }); }); + + it('Validate null and undefined object value', () => { + const obf = new Obfuscator({ + replacerText: replacerText, + additionalObjectKeys: ['obfuscator'], + }); + expect(obf.blur({ obfuscator: 'teste', add: null, test: undefined })).toEqual({ obfuscator: replacerText, add: null, test: null }); + }); });