Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions functionsUnittests/objectFunctions/applyDefaults.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { applyDefaults } from '../../objectFunctions/applyDefaults';

describe('applyDefaults', () => {
// Test case 1: Apply defaults to an object with missing properties
it('1. should apply defaults to an object with missing properties', () => {
const obj = { a: 1 };
const defaults = { a: 0, b: 2 };
const result = applyDefaults(obj, defaults);
const expected = { a: 1, b: 2 };
expect(result).toEqual(expected);
});

// Test case 2: Apply defaults to an object with all properties present
it('2. should not overwrite existing properties with defaults', () => {
const obj = { a: 1, b: 2 };
const defaults = { a: 0, b: 3 };
const result = applyDefaults(obj, defaults);
const expected = { a: 1, b: 2 };
expect(result).toEqual(expected);
});

// Test case 3: Apply defaults to an empty object
it('3. should apply defaults to an empty object', () => {
const obj = {};
const defaults = { a: 1, b: 2 };
const result = applyDefaults(obj as any, defaults);

Check warning on line 26 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L26

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
const expected = { a: 1, b: 2 };
expect(result).toEqual(expected);
});

// Test case 4: Handle non-object input for the first parameter (number)
it('4. should throw a TypeError if the first input is a number', () => {
expect(() => applyDefaults(42 as any, { a: 1 })).toThrow(TypeError);

Check warning on line 33 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L33

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 5: Handle non-object input for the first parameter (string)
it('5. should throw a TypeError if the first input is a string', () => {
expect(() => applyDefaults('string' as any, { a: 1 })).toThrow(TypeError);

Check warning on line 38 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L38

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 6: Handle non-object input for the first parameter (boolean)
it('6. should throw a TypeError if the first input is a boolean', () => {
expect(() => applyDefaults(true as any, { a: 1 })).toThrow(TypeError);

Check warning on line 43 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L43

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 7: Handle non-object input for the first parameter (null)
it('7. should throw a TypeError if the first input is null', () => {
expect(() => applyDefaults(null as any, { a: 1 })).toThrow(TypeError);

Check warning on line 48 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L48

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 8: Handle non-object input for the first parameter (undefined)
it('8. should throw a TypeError if the first input is undefined', () => {
expect(() => applyDefaults(undefined as any, { a: 1 })).toThrow(TypeError);

Check warning on line 53 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L53

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 9: Handle non-object input for the second parameter (number)
it('9. should throw a TypeError if the second input is a number', () => {
expect(() => applyDefaults({ a: 1 }, 42 as any)).toThrow(TypeError);

Check warning on line 58 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L58

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 10: Handle non-object input for the second parameter (string)
it('10. should throw a TypeError if the second input is a string', () => {
expect(() => applyDefaults({ a: 1 }, 'string' as any)).toThrow(TypeError);

Check warning on line 63 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L63

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 11: Handle non-object input for the second parameter (boolean)
it('11. should throw a TypeError if the second input is a boolean', () => {
expect(() => applyDefaults({ a: 1 }, true as any)).toThrow(TypeError);

Check warning on line 68 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L68

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 12: Handle non-object input for the second parameter (null)
it('12. should throw a TypeError if the second input is null', () => {
expect(() => applyDefaults({ a: 1 }, null as any)).toThrow(TypeError);

Check warning on line 73 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L73

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 13: Handle non-object input for the second parameter (undefined)
it('13. should throw a TypeError if the second input is undefined', () => {
expect(() => applyDefaults({ a: 1 }, undefined as any)).toThrow(TypeError);

Check warning on line 78 in functionsUnittests/objectFunctions/applyDefaults.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/applyDefaults.test.ts#L78

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});
});
52 changes: 52 additions & 0 deletions functionsUnittests/objectFunctions/countProperties.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { countProperties } from '../../objectFunctions/countProperties';

describe('countProperties', () => {
// Test case 1: Count properties of a simple object
it('1. should count properties of a simple object', () => {
const obj = { a: 1, b: 2, c: 3 };
const result = countProperties(obj);
const expected = 3;
expect(result).toBe(expected);
});

// Test case 2: Count properties of a nested object
it('2. should count properties of a nested object', () => {
const obj = { a: 1, b: { c: 2, d: 3 }, e: 4 };
const result = countProperties(obj);
const expected = 3; // Only top-level properties are counted
expect(result).toBe(expected);
});

// Test case 3: Count properties of an empty object
it('3. should count properties of an empty object', () => {
const obj = {};
const result = countProperties(obj);
const expected = 0;
expect(result).toBe(expected);
});

// Test case 4: Handle non-object input (number)
it('4. should throw a TypeError if input is a number', () => {
expect(() => countProperties(42 as any)).toThrow(TypeError);

Check warning on line 30 in functionsUnittests/objectFunctions/countProperties.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/countProperties.test.ts#L30

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 5: Handle non-object input (string)
it('5. should throw a TypeError if input is a string', () => {
expect(() => countProperties('string' as any)).toThrow(TypeError);

Check warning on line 35 in functionsUnittests/objectFunctions/countProperties.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/countProperties.test.ts#L35

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 6: Handle non-object input (boolean)
it('6. should throw a TypeError if input is a boolean', () => {
expect(() => countProperties(true as any)).toThrow(TypeError);

Check warning on line 40 in functionsUnittests/objectFunctions/countProperties.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/countProperties.test.ts#L40

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 7: Handle non-object input (null)
it('7. should throw a TypeError if input is null', () => {
expect(() => countProperties(null as any)).toThrow(TypeError);

Check warning on line 45 in functionsUnittests/objectFunctions/countProperties.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/countProperties.test.ts#L45

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 8: Handle non-object input (undefined)
it('8. should throw a TypeError if input is undefined', () => {
expect(() => countProperties(undefined as any)).toThrow(TypeError);

Check warning on line 50 in functionsUnittests/objectFunctions/countProperties.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/countProperties.test.ts#L50

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});
});
80 changes: 80 additions & 0 deletions functionsUnittests/objectFunctions/getObjectDifference.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { getObjectDifference } from '../../objectFunctions/getObjectDifference';

describe('getObjectDifference', () => {
// Test case 1: Get difference between two objects with different values
it('1. should return the difference between two objects with different values', () => {
const obj1 = { a: 1, b: 2, c: 3 };
const obj2 = { a: 1, b: 3, c: 3 };
const result = getObjectDifference(obj1, obj2);
const expected = { b: 2 };
expect(result).toEqual(expected);
});

// Test case 2: Get difference between two identical objects
it('2. should return an empty object for two identical objects', () => {
const obj1 = { a: 1, b: 2, c: 3 };
const obj2 = { a: 1, b: 2, c: 3 };
const result = getObjectDifference(obj1, obj2);
const expected = {};
expect(result).toEqual(expected);
});

// Test case 3: Get difference between two objects with different keys
it('3. should return the difference for objects with different keys', () => {
const obj1 = { a: 1, b: 2 } as { [key: string]: number };
const obj2 = { a: 1, c: 3 } as { [key: string]: number };
const result = getObjectDifference(obj1, obj2);
const expected = { b: 2 };
expect(result).toEqual(expected);
});

// Test case 4: Handle non-object input (number)
it('4. should throw a TypeError if the first input is a number', () => {
expect(() => getObjectDifference(42 as any, { a: 1 })).toThrow(TypeError);

Check warning on line 33 in functionsUnittests/objectFunctions/getObjectDifference.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/getObjectDifference.test.ts#L33

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 5: Handle non-object input (string)
it('5. should throw a TypeError if the first input is a string', () => {
expect(() => getObjectDifference('string' as any, { a: 1 })).toThrow(TypeError);

Check warning on line 38 in functionsUnittests/objectFunctions/getObjectDifference.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/getObjectDifference.test.ts#L38

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 6: Handle non-object input (boolean)
it('6. should throw a TypeError if the first input is a boolean', () => {
expect(() => getObjectDifference(true as any, { a: 1 })).toThrow(TypeError);

Check warning on line 43 in functionsUnittests/objectFunctions/getObjectDifference.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/getObjectDifference.test.ts#L43

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 7: Handle non-object input (null)
it('7. should throw a TypeError if the first input is null', () => {
expect(() => getObjectDifference(null as any, { a: 1 })).toThrow(TypeError);

Check warning on line 48 in functionsUnittests/objectFunctions/getObjectDifference.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/getObjectDifference.test.ts#L48

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 8: Handle non-object input (undefined)
it('8. should throw a TypeError if the first input is undefined', () => {
expect(() => getObjectDifference(undefined as any, { a: 1 })).toThrow(TypeError);

Check warning on line 53 in functionsUnittests/objectFunctions/getObjectDifference.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/getObjectDifference.test.ts#L53

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 9: Handle non-object input for the second parameter (number)
it('9. should throw a TypeError if the second input is a number', () => {
expect(() => getObjectDifference({ a: 1 }, 42 as any)).toThrow(TypeError);

Check warning on line 58 in functionsUnittests/objectFunctions/getObjectDifference.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/getObjectDifference.test.ts#L58

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 10: Handle non-object input for the second parameter (string)
it('10. should throw a TypeError if the second input is a string', () => {
expect(() => getObjectDifference({ a: 1 }, 'string' as any)).toThrow(TypeError);

Check warning on line 63 in functionsUnittests/objectFunctions/getObjectDifference.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/getObjectDifference.test.ts#L63

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 11: Handle non-object input for the second parameter (boolean)
it('11. should throw a TypeError if the second input is a boolean', () => {
expect(() => getObjectDifference({ a: 1 }, true as any)).toThrow(TypeError);

Check warning on line 68 in functionsUnittests/objectFunctions/getObjectDifference.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/getObjectDifference.test.ts#L68

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 12: Handle non-object input for the second parameter (null)
it('12. should throw a TypeError if the second input is null', () => {
expect(() => getObjectDifference({ a: 1 }, null as any)).toThrow(TypeError);

Check warning on line 73 in functionsUnittests/objectFunctions/getObjectDifference.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/getObjectDifference.test.ts#L73

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 13: Handle non-object input for the second parameter (undefined)
it('13. should throw a TypeError if the second input is undefined', () => {
expect(() => getObjectDifference({ a: 1 }, undefined as any)).toThrow(TypeError);

Check warning on line 78 in functionsUnittests/objectFunctions/getObjectDifference.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/getObjectDifference.test.ts#L78

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});
});
75 changes: 75 additions & 0 deletions functionsUnittests/objectFunctions/keysToCamelCase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { keysToCamelCase } from '../../objectFunctions/keysToCamelCase';

describe('keysToCamelCase', () => {
// Test case 1: Convert keys of a simple object
it('1. should convert keys of a simple object to camelCase', () => {
const obj = { first_name: 'John', last_name: 'Doe' };
const result = keysToCamelCase(obj);
const expected = { firstName: 'John', lastName: 'Doe' };
expect(result).toEqual(expected);
});

// Test case 2: Convert keys of a nested object
it('2. should convert keys of a nested object to camelCase', () => {
const obj = { user_info: { first_name: 'John', last_name: 'Doe' } };
const result = keysToCamelCase(obj);
const expected = { userInfo: { firstName: 'John', lastName: 'Doe' } };
expect(result).toEqual(expected);
});

// Test case 3: Convert keys of an array of objects
it('3. should convert keys of an array of objects to camelCase', () => {
const arr = [{ first_name: 'John' }, { last_name: 'Doe' }];
const result = keysToCamelCase(arr);
const expected = [{ firstName: 'John' }, { lastName: 'Doe' }];
expect(result).toEqual(expected);
});

// Test case 4: Handle non-object input (number)
it('4. should return the input if it is a number', () => {
const input = 42;
const result = keysToCamelCase(input);
const expected = 42;
expect(result).toBe(expected);
});

// Test case 5: Handle non-object input (string)
it('5. should return the input if it is a string', () => {
const input = 'string';
const result = keysToCamelCase(input);
const expected = 'string';
expect(result).toBe(expected);
});

// Test case 6: Handle non-object input (boolean)
it('6. should return the input if it is a boolean', () => {
const input = true;
const result = keysToCamelCase(input);
const expected = true;
expect(result).toBe(expected);
});

// Test case 7: Handle non-object input (null)
it('7. should return the input if it is null', () => {
const input = null;
const result = keysToCamelCase(input);
const expected = null;
expect(result).toBe(expected);
});

// Test case 8: Handle non-object input (undefined)
it('8. should return the input if it is undefined', () => {
const input = undefined;
const result = keysToCamelCase(input);
const expected = undefined;
expect(result).toBe(expected);
});

// Test case 9: Convert keys with mixed cases
it('9. should convert keys with mixed cases to camelCase', () => {
const obj = { 'first-name': 'John', 'Last_Name': 'Doe' };
const result = keysToCamelCase(obj);
const expected = { firstName: 'John', lastName: 'Doe' };
expect(result).toEqual(expected);
});
});
75 changes: 75 additions & 0 deletions functionsUnittests/objectFunctions/keysToSnakeCase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { keysToSnakeCase } from '../../objectFunctions/keysToSnakeCase';

describe('keysToSnakeCase', () => {
// Test case 1: Convert keys of a simple object
it('1. should convert keys of a simple object to snake_case', () => {
const obj = { firstName: 'John', lastName: 'Doe' };
const result = keysToSnakeCase(obj);
const expected = { first_name: 'John', last_name: 'Doe' };
expect(result).toEqual(expected);
});

// Test case 2: Convert keys of a nested object
it('2. should convert keys of a nested object to snake_case', () => {
const obj = { userInfo: { firstName: 'John', lastName: 'Doe' } };
const result = keysToSnakeCase(obj);
const expected = { user_info: { first_name: 'John', last_name: 'Doe' } };
expect(result).toEqual(expected);
});

// Test case 3: Convert keys of an array of objects
it('3. should convert keys of an array of objects to snake_case', () => {
const arr = [{ firstName: 'John' }, { lastName: 'Doe' }];
const result = keysToSnakeCase(arr);
const expected = [{ first_name: 'John' }, { last_name: 'Doe' }];
expect(result).toEqual(expected);
});

// Test case 4: Handle non-object input (number)
it('4. should return the input if it is a number', () => {
const input = 42;
const result = keysToSnakeCase(input);
const expected = 42;
expect(result).toBe(expected);
});

// Test case 5: Handle non-object input (string)
it('5. should return the input if it is a string', () => {
const input = 'string';
const result = keysToSnakeCase(input);
const expected = 'string';
expect(result).toBe(expected);
});

// Test case 6: Handle non-object input (boolean)
it('6. should return the input if it is a boolean', () => {
const input = true;
const result = keysToSnakeCase(input);
const expected = true;
expect(result).toBe(expected);
});

// Test case 7: Handle non-object input (null)
it('7. should return the input if it is null', () => {
const input = null;
const result = keysToSnakeCase(input);
const expected = null;
expect(result).toBe(expected);
});

// Test case 8: Handle non-object input (undefined)
it('8. should return the input if it is undefined', () => {
const input = undefined;
const result = keysToSnakeCase(input);
const expected = undefined;
expect(result).toBe(expected);
});

// Test case 9: Convert keys with mixed cases
it('9. should convert keys with mixed cases to snake_case', () => {
const obj = { firstName: 'John', LastName: 'Doe' };
const result = keysToSnakeCase(obj);
const expected = { first_name: 'John', last_name: 'Doe' };
expect(result).toEqual(expected);
});
});
Loading
Loading