Skip to content

Commit

Permalink
hotfix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolfoviolac committed Feb 20, 2024
1 parent 0fc6754 commit 85f76cc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
8 changes: 7 additions & 1 deletion test/module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});
10 changes: 9 additions & 1 deletion test/object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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 });
});
});

0 comments on commit 85f76cc

Please sign in to comment.