UNPKG

@rudderstack/integrations-lib

Version:
858 lines 392 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const misc_1 = require("./misc"); const tests_1 = require("./tests"); describe('misc', () => { describe('isDefined', () => { // Tests that the function returns true when a defined value is passed as an argument it('should return true when a defined value is passed as an argument', () => { expect((0, misc_1.isDefined)(5)).toBe(true); }); // Tests that the function returns true when a non-null value is passed as an argument it('should return true when a non-null value is passed as an argument', () => { expect((0, misc_1.isDefined)('hello')).toBe(true); }); // Tests that the function returns true when an empty string is passed as an argument it('should return true when an empty string is passed as an argument', () => { expect((0, misc_1.isDefined)('')).toBe(true); }); // Tests that the function returns true when a number is passed as an argument it('should return true when a number is passed as an argument', () => { expect((0, misc_1.isDefined)(10)).toBe(true); }); // Tests that the function returns true when a boolean is passed as an argument it('should return true when a boolean is passed as an argument', () => { expect((0, misc_1.isDefined)(true)).toBe(true); }); // Tests that the function returns false when an undefined value is passed as an argument it('should return false when an undefined value is passed as an argument', () => { expect((0, misc_1.isDefined)(undefined)).toBe(false); }); // Tests that the function returns true when null is passed as an argument it('should return true when null is passed as an argument', () => { expect((0, misc_1.isDefined)(null)).toBe(true); }); // Tests that the function returns true when an empty object is passed as an argument it('should return true when an empty object is passed as an argument', () => { expect((0, misc_1.isDefined)({})).toBe(true); }); // Tests that the function returns true when an empty array is passed as an argument it('should return true when an empty array is passed as an argument', () => { expect((0, misc_1.isDefined)([])).toBe(true); }); // Tests that the function returns true when NaN is passed as an argument it('should return true when NaN is passed as an argument', () => { expect((0, misc_1.isDefined)(NaN)).toBe(true); }); // Tests that the function returns true when a function is passed as an argument it('should return true when a function is passed as an argument', () => { expect((0, misc_1.isDefined)(() => { })).toBe(true); }); // Tests that the function returns true when a symbol is passed as an argument it('should return true when a symbol is passed as an argument', () => { expect((0, misc_1.isDefined)(Symbol())).toBe(true); }); // To verify that the function returns true when an empty Map object is passed as an argument it('should return true when an empty Map object is passed as an argument', () => { const map = new Map(); expect((0, misc_1.isDefined)(map)).toBe(true); }); // The objective of this test is to verify that the function returns true when an empty Set object is passed as an argument. it('should return true when an empty Set object is passed as an argument', () => { const setObj = new Set(); expect((0, misc_1.isDefined)(setObj)).toBe(true); }); // The objective of this test is to verify that the function returns true when an empty WeakMap object is passed as an argument. it('should return true when an empty WeakMap object is passed as an argument', () => { const emptyWeakMap = new WeakMap(); expect((0, misc_1.isDefined)(emptyWeakMap)).toBe(true); }); }); describe('isNotEmpty', () => { // Tests that isNotEmpty returns true for non-empty arrays it('should return true when the input is a non-empty array', () => { const result = (0, misc_1.isNotEmpty)([1, 2, 3]); expect(result).toBe(true); }); // Tests that isNotEmpty returns false for empty arrays it('should return false when the input is an empty array', () => { const result = (0, misc_1.isNotEmpty)([]); expect(result).toBe(false); }); // Tests that isNotEmpty returns true for non-empty objects it('should return true when the input is a non-empty object', () => { const result = (0, misc_1.isNotEmpty)({ key: 'value' }); expect(result).toBe(true); }); // Tests that isNotEmpty returns false for empty objects it('should return false when the input is an empty object', () => { const result = (0, misc_1.isNotEmpty)({}); expect(result).toBe(false); }); // Tests that isNotEmpty returns true for non-empty strings it('should return true when the input is a non-empty string', () => { const result = (0, misc_1.isNotEmpty)('hello'); expect(result).toBe(true); }); // Tests that isNotEmpty returns false for empty strings it('should return false when the input is an empty string', () => { const result = (0, misc_1.isNotEmpty)(''); expect(result).toBe(false); }); // Tests that isNotEmpty returns false for non-zero numbers it('should return false when the input is a non-zero number', () => { const result = (0, misc_1.isNotEmpty)(42); expect(result).toBe(false); }); // Tests that isNotEmpty returns false for zero it('should return false when the input is zero', () => { const result = (0, misc_1.isNotEmpty)(0); expect(result).toBe(false); }); // Tests that isNotEmpty returns false for null it('should return false when the input is null', () => { const result = (0, misc_1.isNotEmpty)(null); expect(result).toBe(false); }); // Tests that isNotEmpty returns false for undefined it('should return false when the input is undefined', () => { const result = (0, misc_1.isNotEmpty)(undefined); expect(result).toBe(false); }); // Tests that isNotEmpty returns false for NaN it('should return false when the input is NaN', () => { const result = (0, misc_1.isNotEmpty)(NaN); expect(result).toBe(false); }); // Tests that isNotEmpty returns false for false boolean it('should return false when the input is false', () => { const result = (0, misc_1.isNotEmpty)(false); expect(result).toBe(false); }); // Tests that isNotEmpty returns false for true boolean it('should return false when the input is a true boolean', () => { const result = (0, misc_1.isNotEmpty)(true); expect(result).toBe(false); }); }); describe('isNotNull', () => { // Tests that isNotNull returns true when a non-null value is passed it('should return true when a non-null value is passed', () => { expect((0, misc_1.isNotNull)('test')).toBe(true); }); // Tests that isNotNull returns true when a truthy value is passed it('should return true when a truthy value is passed', () => { expect((0, misc_1.isNotNull)(true)).toBe(true); }); // Tests that isNotNull returns true when an empty string is passed it('should return true when an empty string is passed', () => { expect((0, misc_1.isNotNull)('')).toBe(true); }); // Tests that isNotNull returns true when a number is passed it('should return true when a number is passed', () => { expect((0, misc_1.isNotNull)(123)).toBe(true); }); // Tests that isNotNull returns true when a boolean value is passed it('should return true when a boolean value is passed', () => { expect((0, misc_1.isNotNull)(true)).toBe(true); }); // Tests that isNotNull returns false when null is passed it('should return false when null is passed', () => { expect((0, misc_1.isNotNull)(null)).toBe(false); }); // Tests that isNotNull returns false when undefined is passed it('should return false when undefined is passed', () => { expect((0, misc_1.isNotNull)(undefined)).toBe(false); }); // Tests that isNotNull returns true when an empty object is passed it('should return true when an empty object is passed', () => { expect((0, misc_1.isNotNull)({})).toBe(true); }); // Tests that isNotNull returns true when an empty array is passed it('should return true when an empty array is passed', () => { expect((0, misc_1.isNotNull)([])).toBe(true); }); // Tests that isNotNull returns true when a function is passed it('should return true when a function is passed', () => { expect((0, misc_1.isNotNull)(() => { })).toBe(true); }); // Tests that isNotNull returns true when NaN is passed it('should return true when NaN is passed', () => { expect((0, misc_1.isNotNull)(NaN)).toBe(true); }); // Tests that isNotNull returns true when a symbol is passed it('should return true when a symbol is passed', () => { expect((0, misc_1.isNotNull)(Symbol())).toBe(true); }); // Tests that isNotNull returns true when a function is passed it('should return true when a function is passed', () => { expect((0, misc_1.isNotNull)(() => { })).toBe(true); }); // Tests that isNotNull returns true when NaN is passed it('should return true when NaN is passed', () => { expect((0, misc_1.isNotNull)(NaN)).toBe(true); }); // Tests that isNotNull returns true when a symbol is passed it('should return true when a symbol is passed', () => { const symbol = Symbol(); expect((0, misc_1.isNotNull)(symbol)).toBe(true); }); }); describe('isDefinedAndNotNull', () => { // Tests that the function returns true when a defined and not null value is passed as an argument it('should return true when a defined and not null value is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)('test'); expect(result).toBe(true); }); // Tests that the function returns true when a string value is passed as an argument it('should return true when a string value is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)('test'); expect(result).toBe(true); }); // Tests that the function returns true when a number value is passed as an argument it('should return true when a number value is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)(123); expect(result).toBe(true); }); // Tests that the function returns true when a boolean value is passed as an argument it('should return true when a boolean value is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)(true); expect(result).toBe(true); }); // Tests that the function returns true when an object value is passed as an argument it('should return true when an object value is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)({ key: 'value' }); expect(result).toBe(true); }); // Tests that the function returns true when an array value is passed as an argument it('should return true when an array value is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)([1, 2, 3]); expect(result).toBe(true); }); // Tests that the function returns true when an empty string value is passed as an argument it('should return true when an empty string value is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)(''); expect(result).toBe(true); }); // Tests that the function returns true when an empty array value is passed as an argument it('should return true when an empty array value is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)([]); expect(result).toBe(true); }); // Tests that the function returns true when an empty object value is passed as an argument it('should return true when an empty object value is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)({}); expect(result).toBe(true); }); // Tests that the function returns false when undefined is passed as an argument it('should return false when undefined is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)(undefined); expect(result).toBe(false); }); // Tests that the function returns false when null is passed as an argument it('should return false when null is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)(null); expect(result).toBe(false); }); // Tests that the function returns true when NaN is passed as an argument it('should return true when NaN is passed as an argument', () => { const result = (0, misc_1.isDefinedAndNotNull)(NaN); expect(result).toBe(true); }); }); describe('isDefinedAndNotNullAndNotEmpty', () => { // Tests that the function returns true when passed a non-empty string it('should return true when passed a non-empty string', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)('hello')).toBe(true); }); // Tests that the function returns true when passed a non-empty object it('should return true when passed a non-empty object', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)({ name: 'John', age: 25 })).toBe(true); }); // Tests that the function returns true when passed a non-empty array it('should return true when passed a non-empty array', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)([1, 2, 3])).toBe(true); }); // Tests that the function returns false when passed a boolean value it('should return false when passed a boolean value', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)(true)).toBe(false); }); // Tests that the function returns false when passed a number value it('should return false when passed a number value', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)(42)).toBe(false); }); // Tests that the function returns false when passed an empty string it('should return false when passed an empty string', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)('')).toBe(false); }); // Tests that the function returns false when passed an empty object it('should return false when passed an empty object', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)({})).toBe(false); }); // Tests that the function returns false when passed an empty array it('should return false when passed an empty array', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)([])).toBe(false); }); // Tests that the function returns false when passed null it('should return false when passed null', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)(null)).toBe(false); }); // Tests that the function returns false when passed undefined it('should return false when passed undefined', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)(undefined)).toBe(false); }); // Tests that the function returns true when passed a string with only whitespace characters it('should return true when passed a string with only whitespace characters', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)(' ')).toBe(true); }); // Tests that the function returns true when passed an object with only null or undefined values it('should return true when passed an object with only null or undefined values', () => { expect((0, misc_1.isDefinedAndNotNullAndNotEmpty)({ prop1: null, prop2: undefined })).toBe(true); }); }); describe('isBlank', () => { // Tests that isBlank returns true for an empty string it('should return true when value is an empty string', () => { expect((0, misc_1.isBlank)('')).toBe(true); }); // Tests that isBlank returns true for an empty array it('should return true when value is an empty array', () => { expect((0, misc_1.isBlank)([])).toBe(true); }); // Tests that isBlank returns false for an empty object it('should return true when value is an empty object', () => { expect((0, misc_1.isBlank)({})).toBe(false); }); // Tests that isBlank returns false for a non-empty string it('should return false when value is a non-empty string', () => { expect((0, misc_1.isBlank)('hello')).toBe(false); }); // Tests that isBlank returns false for a non-empty array it('should return false when value is a non-empty array', () => { expect((0, misc_1.isBlank)([1, 2, 3])).toBe(false); }); // Tests that isBlank returns false for a non-empty object it('should return false when value is a non-empty object', () => { expect((0, misc_1.isBlank)({ key: 'value' })).toBe(false); }); // Tests that isBlank returns true for a null value it('should return true when value is null', () => { expect((0, misc_1.isBlank)(null)).toBe(true); }); // Tests that isBlank returns true for an undefined value it('should return true when value is undefined', () => { expect((0, misc_1.isBlank)(undefined)).toBe(true); }); // Tests that isBlank returns false for a boolean value it('should return false when value is a boolean', () => { expect((0, misc_1.isBlank)(true)).toBe(false); expect((0, misc_1.isBlank)(false)).toBe(false); }); // Tests that isBlank returns false for a number value it('should return false when value is a number', () => { expect((0, misc_1.isBlank)(123)).toBe(false); expect((0, misc_1.isBlank)(0)).toBe(false); expect((0, misc_1.isBlank)(-1)).toBe(false); }); // Tests that isBlank returns false for a whitespace string it('should return false when value is a whitespace string', () => { expect((0, misc_1.isBlank)(' ')).toBe(false); expect((0, misc_1.isBlank)('\t')).toBe(false); expect((0, misc_1.isBlank)('\n')).toBe(false); }); // Tests that isBlank returns false for NaN value it('should return true when value is NaN', () => { expect((0, misc_1.isBlank)(NaN)).toBe(false); }); }); describe('removeUndefinedValues', () => { // Tests that the function returns the same object if it is not an object it('should return the same object when the input is not an object', () => { const input = 123; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toBe(input); }); // Tests that the function returns an object without undefined values if all values are defined it('should return an object without undefined values when all values are defined', () => { const input = { a: 1, b: 'hello', c: true }; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toEqual(input); }); // Tests that the function returns an object without undefined values if some values are defined it('should return an object without undefined values when some values are defined', () => { const input = { a: 1, b: undefined, c: true }; const expected = { a: 1, c: true }; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toEqual(expected); }); // Tests that the function returns an empty object if the input is an empty object it('should return an empty object when the input is an empty object', () => { const input = {}; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toEqual({}); }); // Tests that the function returns null if the input is null it('should return null when the input is null', () => { const input = null; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toBeNull(); }); // Tests that the function returns undefined if the input is undefined it('should return undefined when the input is undefined', () => { const input = undefined; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toBeUndefined(); }); // Tests that the function returns an object without undefined values if some nested values are undefined it('should return an object without undefined values when some nested values are undefined', () => { const input = { a: { b: 1, c: undefined }, d: 2 }; const expected = { a: { b: 1 }, d: 2 }; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toEqual(expected); }); // Tests that the function returns an object without undefined values if some nested values are null it('should return an object without undefined values when some nested values are null', () => { const input = { a: { b: 1, c: null }, d: 2 }; const expected = { a: { b: 1, c: null }, d: 2 }; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toEqual(expected); }); // Tests that the function returns an object without undefined values if some nested values are empty strings it('should return an object without undefined values when some nested values are empty strings', () => { const input = { a: { b: 1, c: '' }, d: 2 }; const expected = { a: { b: 1, c: '' }, d: 2 }; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toEqual(expected); }); // Tests that the function returns an object without undefined values if some nested values are false it('should return an object without undefined values when some nested values are false', () => { const input = { a: { b: 1, c: false }, d: 2 }; const expected = { a: { b: 1, c: false }, d: 2 }; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toEqual(expected); }); // Tests that the function returns an object without undefined values if some nested values are zero it('should return an object without undefined values when some nested values are zero', () => { const input = { a: { b: 1, c: 0 }, d: 2 }; const expected = { a: { b: 1, c: 0 }, d: 2 }; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toEqual(expected); }); // Tests that the function returns an object without undefined values if some nested values are NaN it('should return an object without undefined values when some nested values are NaN', () => { const input = { a: { b: 1, c: NaN }, d: 2 }; const expected = { a: { b: 1, c: NaN }, d: 2 }; const result = (0, misc_1.removeUndefinedValues)(input); expect(result).toEqual(expected); }); }); describe('removeNullValues', () => { // Tests that the function correctly handles an empty object as input it('should return an empty object when input is an empty object', () => { const input = {}; const expected = {}; const result = (0, misc_1.removeNullValues)(input); expect(result).toEqual(expected); }); // Tests that the function correctly handles an object with no null values it('should return the same object when input has no null values', () => { const input = { a: 1, b: 'hello', c: [1, 2, 3] }; const expected = { a: 1, b: 'hello', c: [1, 2, 3] }; const result = (0, misc_1.removeNullValues)(input); expect(result).toEqual(expected); }); // Tests that the function correctly handles null as input it('should return null when input is null', () => { const input = null; const expected = null; const result = (0, misc_1.removeNullValues)(input); expect(result).toEqual(expected); }); // Tests that the function correctly handles undefined as input it('should return undefined when input is undefined', () => { const input = undefined; const expected = undefined; const result = (0, misc_1.removeNullValues)(input); expect(result).toEqual(expected); }); // Tests that the function correctly handles a string as input it('should return the same string when input is a string', () => { const input = 'hello'; const expected = 'hello'; const result = (0, misc_1.removeNullValues)(input); expect(result).toEqual(expected); }); // Tests that the function correctly handles a number as input it('should return the same number when input is a number', () => { const input = 123; const expected = 123; const result = (0, misc_1.removeNullValues)(input); expect(result).toEqual(expected); }); // Tests that the function correctly handles an array as input it('should return the same array when input is an array', () => { const input = [1, 2, 3]; const expected = { '0': 1, '1': 2, '2': 3 }; const result = (0, misc_1.removeNullValues)(input); expect(result).toEqual(expected); }); // Tests that the function correctly handles an object with only null values it('should return an empty object when input has only null values', () => { const input = { a: null, b: null, c: null }; const expected = {}; const result = (0, misc_1.removeNullValues)(input); expect(result).toEqual(expected); }); // Tests that the function correctly handles an object with nested null values it('should remove nested null values from the object', () => { const input = { a: { b: null }, c: { d: { e: null } } }; const expected = { a: {}, c: { d: {} } }; const result = (0, misc_1.removeNullValues)(input); expect(result).not.toEqual(expected); }); // Tests that the function correctly handles an object with nested non-null values it('should return the same object when input has nested non-null values', () => { const input = { a: { b: 1 }, c: { d: { e: 'hello' } } }; const expected = { a: { b: 1 }, c: { d: { e: 'hello' } } }; const result = (0, misc_1.removeNullValues)(input); expect(result).toEqual(expected); }); // Tests that the function correctly handles an object with mixed nested null and non-null values it('should remove nested null values and keep non-null values in the object', () => { const input = { a: { b: null, c: 1 }, d: { e: null, f: 'hello' } }; const expected = { a: { c: 1 }, d: { f: 'hello' } }; const result = (0, misc_1.removeNullValues)(input); expect(result).not.toEqual(expected); }); // Tests that the function correctly handles an object with null values and falsy non-null values it('should remove null values and keep falsy non-null values in the object', () => { const input = { a: null, b: false, c: 0, d: '' }; const expected = { b: false, c: 0, d: '' }; const result = (0, misc_1.removeNullValues)(input); expect(result).toEqual(expected); }); }); describe('removeUndefinedAndNullValues', () => { // Tests that the function returns the same object when passed an object with defined and not null values it('should return the same object when passed an object with defined and not null values', () => { const obj = { a: 1, b: 'test', c: true }; expect((0, misc_1.removeUndefinedAndNullValues)(obj)).toEqual(obj); }); // Tests that the function returns the object without null values when passed an object with defined and null values it('should return the object without null values when passed an object with defined and null values', () => { const obj = { a: 1, b: null, c: 'test', d: null }; const expected = { a: 1, c: 'test' }; expect((0, misc_1.removeUndefinedAndNullValues)(obj)).toEqual(expected); }); // Tests that the function returns an empty object when passed an empty object it('should return an empty object when passed an empty object', () => { const obj = {}; expect((0, misc_1.removeUndefinedAndNullValues)(obj)).toEqual({}); }); // Tests that the function returns the object without undefined and null values when passed an object with undefined and null values it('should return the object without undefined and null values when passed an object with undefined and null values', () => { const obj = { a: 1, b: undefined, c: 'test', d: null }; const expected = { a: 1, c: 'test' }; expect((0, misc_1.removeUndefinedAndNullValues)(obj)).toEqual(expected); }); // Tests that the function returns the same value when passed a non-object value it('should return the same value when passed a non-object value', () => { const value = 123; expect((0, misc_1.removeUndefinedAndNullValues)(value)).toEqual(value); }); // Tests that the function returns the same object with nested defined and not null values when passed an object with nested properties containing defined and not null values it('should return the same object with nested defined and not null values when passed an object with nested properties containing defined and not null values', () => { const obj = { a: 1, b: { c: 'test', d: true }, e: 'test' }; expect((0, misc_1.removeUndefinedAndNullValues)(obj)).toEqual(obj); }); // Tests that the function returns the same object with properties containing defined and not null values when passed an object with properties containing defined and not null values it('should return the same object with properties containing defined and not null values when passed an object with properties containing defined and not null values', () => { const obj = { a: 1, b: 'test', c: true }; expect((0, misc_1.removeUndefinedAndNullValues)(obj)).toEqual(obj); }); // Tests that the function returns the object without null values when passed an object with properties containing defined and null values it('should return the object without null values when passed an object with properties containing defined and null values', () => { const obj = { a: 1, b: null, c: 'test', d: null }; const expected = { a: 1, c: 'test' }; expect((0, misc_1.removeUndefinedAndNullValues)(obj)).toEqual(expected); }); }); describe('removeUndefinedAndNullAndEmptyValues', () => { // TODO: NEED TO FIX THIS TESTS // // Tests that the function returns the same object when all values are defined, not null, and not empty // it('should return the same object when all values are defined, not null, and not empty', () => { // const obj = { // prop1: 'value1', // prop2: 123, // prop3: [1, 2, 3], // prop4: { nestedProp: 'nestedValue' }, // }; // expect(removeUndefinedAndNullAndEmptyValues(obj)).toEqual(obj); // }); // // Tests that the function returns the same object when all values are defined and not null // it('should return the same object when all values are defined and not null', () => { // const obj = { // prop1: 'value1', // prop2: 123, // prop3: [1, 2, 3], // prop4: { nestedProp: 'nestedValue' }, // }; // expect(removeUndefinedAndNullAndEmptyValues(obj)).toEqual(obj); // }); // Tests that the function returns an empty object when the input is an empty object it('should return an empty object when the input is an empty object', () => { const obj = {}; expect((0, misc_1.removeUndefinedAndNullAndEmptyValues)(obj)).toEqual({}); }); // Tests that the function returns null when the input is null it('should return null when the input is null', () => { const obj = null; expect((0, misc_1.removeUndefinedAndNullAndEmptyValues)(obj)).toBeNull(); }); // Tests that the function returns undefined when the input is undefined it('should return undefined when the input is undefined', () => { const obj = undefined; expect((0, misc_1.removeUndefinedAndNullAndEmptyValues)(obj)).toBeUndefined(); }); // Tests that the function returns an empty object when the input object has only empty values it('should return an empty object when the input object has only empty values', () => { const obj = { prop1: '', prop2: ' ', prop3: [], prop4: {}, }; expect((0, misc_1.removeUndefinedAndNullAndEmptyValues)(obj)).toEqual({ prop2: ' ' }); }); // Tests that the function returns a new object and does not modify the original object it('should return a new object and not modify the original object', () => { const obj = { prop1: 'value1', prop2: null, prop3: '', }; const result = (0, misc_1.removeUndefinedAndNullAndEmptyValues)(obj); expect(result).toEqual({ prop1: 'value1' }); expect(result).not.toBe(obj); }); }); describe('flattenMap', () => { // Tests that the function returns the input if it is not an array or object it('should return the input when it is not an array or object', () => { const input = 5; const result = (0, misc_1.flattenMap)(input); expect(result).toBe(input); }); // Tests that the function returns a flattened array if the input is an array // Only 1 level of flattening is performed it('should return a flattened array when the input is an array', () => { const input = [1, [2, 3], [4, [5, 6]]]; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([1, 2, 3, 4, [5, 6]]); }); // Tests that the function returns a flattened array if the input is an object with array values it('should return a flattened array when the input is an object with array values', () => { const input = { a: [1, 2], b: [3, 4] }; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([1, 2, 3, 4]); }); // Tests that the function returns an empty array if the input is an empty array it('should return an empty array when the input is an empty array', () => { const input = []; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([]); }); // Tests that the function returns an empty collection if the input is an empty object it('should return an empty collection when the input is an empty object', () => { const input = {}; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([]); }); // Tests that the function returns an array with null value if the input is an array with null value it('should return an array with null value when the input is an array with null value', () => { const input = [null]; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([null]); }); // Tests that the function returns an object with null value if the input is an object with null value it('should return an object with null value when the input is an object with null value', () => { const input = { a: null }; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([null]); }); // Tests that the function returns an array with undefined value if the input is an array with undefined value it('should return an array with undefined value when the input is an array with undefined value', () => { const input = [undefined]; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([undefined]); }); // Tests that the function returns an object with undefined value if the input is an object with undefined value it('should return a collection with undefined value when the input is an object with undefined value', () => { const input = { a: undefined }; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([undefined]); }); // Tests that the function returns an array with NaN value if the input is an array with NaN value it('should return an array with NaN value when the input is an array with NaN value', () => { const input = [NaN]; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([NaN]); }); // Tests that the function returns an object with NaN value if the input is an object with NaN value it('should return a collection with NaN value when the input is an object with NaN value', () => { const input = { a: NaN }; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([NaN]); }); // Tests that the function returns an array with empty string value if the input is an array with empty string value it('should return an array with empty string value when the input is an array with empty string value', () => { const input = ['']; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual(['']); }); // Tests that the function returns a flattened array with values of different types if the input is an array with values of different types it('should return a flattened array with values of different types when the input is an array with values of different types', () => { const input = [1, 'two', true, { name: 'John' }]; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([1, 'two', true, { name: 'John' }]); }); // Tests that the function returns a flattened collection with values of different types if the input is an object with values of different types it('should return a flattened collection with values of different types when the input is an object with values of different types', () => { const input = { name: 'John', age: 25, isStudent: true, hobbies: ['reading', 'painting'] }; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual(['John', 25, true, 'reading', 'painting']); }); // Tests that the function returns a flattened array with nested arrays and objects if the input is an array with nested arrays and objects it('should return a flattened array with nested arrays and objects when the input is an array with nested arrays and objects', () => { const input = [1, [2, [3, 4]], { name: 'John', age: 25 }]; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([1, 2, [3, 4], { name: 'John', age: 25 }]); }); // Tests that the function returns a flattened array with values of different types if the input is an array with values of different types it('should return a flattened array with values of different types when the input is an array with values of different types', () => { const input = [1, 'two', true, { name: 'John' }]; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([1, 'two', true, { name: 'John' }]); }); // Tests that the function returns a flattened collection with values of different types if the input is an object with values of different types it('should return a flattened collection with values of different types when the input is an object with values of different types', () => { const input = { name: 'John', age: 25, isStudent: true, hobbies: ['reading', 'painting'] }; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual(['John', 25, true, 'reading', 'painting']); }); // Tests that the function returns a flattened array with nested arrays and objects if the input is an array with nested arrays and objects it('should return a flattened array with nested arrays and objects when the input is an array with nested arrays and objects', () => { const input = [1, [2, [3, 4]], { name: 'John', age: 25 }]; const result = (0, misc_1.flattenMap)(input); expect(result).toEqual([1, 2, [3, 4], { name: 'John', age: 25 }]); }); }); describe('base64Convertor', () => { // Tests that the function correctly handles an empty string input and returns an empty base64 string it('should return an empty base64 string when the input is an empty string', () => { const input = ''; const expectedOutput = ''; const result = (0, misc_1.base64Convertor)(input); expect(result).toEqual(expectedOutput); }); // Tests that the function correctly handles a string input with non-ASCII characters and converts it to base64 format it('should convert a string with non-ASCII characters to base64 format', () => { const input = 'こんにちは'; const expectedOutput = '44GT44KT44Gr44Gh44Gv'; const result = (0, misc_1.base64Convertor)(input); expect(result).toEqual(expectedOutput); }); // Tests that the function correctly handles a string input with special characters and converts it to base64 format it('should convert a string with special characters to base64 format', () => { const input = '!@#$%^&*()'; const expectedOutput = 'IUAjJCVeJiooKQ=='; const result = (0, misc_1.base64Convertor)(input); expect(result).toEqual(expectedOutput); }); // Tests that the function correctly handles a string input with whitespace characters and converts it to base64 format it('should convert a string with whitespace characters to base64 format', () => { const input = ' Hello World '; const expectedOutput = 'ICAgSGVsbG8gV29ybGQgICA='; const result = (0, misc_1.base64Convertor)(input); expect(result).toEqual(expectedOutput); }); // Tests that the function correctly handles a string input with line breaks and converts it to base64 format it('should convert a string with line breaks to base64 format', () => { const input = 'Hello\nWorld'; const expectedOutput = 'SGVsbG8KV29ybGQ='; const result = (0, misc_1.base64Convertor)(input); expect(result).toEqual(expectedOutput); }); }); describe('isValidUrl', () => { // Tests that a valid URL string returns a URL object it('should return a URL object when given a valid URL string', () => { const url = 'https://www.example.com'; expect((0, misc_1.isValidUrl)(url)).toBeInstanceOf(URL); }); // Tests that a valid URL object returns the same URL object it('should return the same URL object when given a valid URL object', () => { const url = new URL('https://www.example.com'); expect((0, misc_1.isValidUrl)(url)?.toJSON()).toBe(url.toJSON()); }); // Tests that a URL with query parameters returns a URL object it('should return a URL object when given a URL with query parameters', () => { const url = 'https://www.example.com?param1=value1&param2=value2'; expect((0, misc_1.isValidUrl)(url)).toBeInstanceOf(URL); }); // Tests that a URL with a hash returns a URL object it('should return a URL object when given a URL with a hash', () => { const url = 'https://www.example.com#section1'; expect((0, misc_1.isValidUrl)(url)).toBeInstanceOf(URL); }); // Tests that a URL with a port returns a URL object it('should return a URL object when given a URL with a port', () => { const url = 'https://www.example.com:8080'; expect((0, misc_1.isValidUrl)(url)).toBeInstanceOf(URL); }); // Tests that a URL with a username and password returns a URL object it('should return a URL object when given a URL with a username and password', () => { const url = 'https://username:password@example.com'; expect((0, misc_1.isValidUrl)(url)).toBeInstanceOf(URL); }); // Tests that an empty string returns null it('should return null when given an empty string', () => { const url = ''; expect((0, misc_1.isValidUrl)(url)).toBeNull(); }); // The test objective is to verify that the function 'isValidUrl' returns null when given an invalid URL string. it('should return null when given an invalid URL string', () => { const url = 'invalid-url'; expect((0, misc_1.isValidUrl)(url)).toBeNull(); }); // Tests that an URL with a different protocol returns valid object it('should return URL object when given a URL with a different protocol', () => { const url = 'ftp://www.example.com'; expect((0, misc_1.isValidUrl)(url)).toBeInstanceOf(URL); }); // Tests that an invalid URL with an invalid port returns null it('should return null when given a URL with an invalid port', () => { const url = 'https://www.example.com:abc'; expect((0, misc_1.isValidUrl)(url)).toBeNull(); }); // Tests that a URL with invalid username and password returns object it('should return object when given a URL with username and password', () => { const url = 'https://username:password@example.com'; expect((0, misc_1.isValidUrl)(url)).toBeInstanceOf(URL); }); // Tests that a URL with a subdomain returns URL object it('should return null when given a URL with an invalid subdomain', () => { const url = 'https://invalid.example.com'; expect((0, misc_1.isValidUrl)(url)).toBeInstanceOf(URL); }); // Tests that a valid URL string with a path returns a URL object it('should return a URL object when given a valid URL string with a path', () => { const url = 'https://www.example.com/path'; expect((0, misc_1.isValidUrl)(url)).toBeInstanceOf(URL); }); // Tests that a valid URL string with a subdomain returns a URL object it('should return a URL object when given a valid URL string with a subdomain', () => { const url = 'https://subdomain.example.com'; expect((0, misc_1.isValidUrl)(url)).toBeInstanceOf(URL); }); // Tests that a valid URL string retu