208c0857ee
closes https://github.com/twentyhq/core-team-issues/issues/1629 To do before requesting review : - filter update Migration to come in an other PR Strat : 1/ Null transformation - [x] Transform NULL equivalent value to NULL in field validation in common api - pre-query - with feature flag - [ ] Same logic in ORM (Not done, complex to handle feature flag here) - [x] Transform NULL value to equivalent in data formatting in ORM - post-query 2/ Migration (in other PR) for fieldMetadata not nullable with default defaultValue (empty string, ...) - [ ] Remove NOT NULL db constraint - [ ] Update record value to NULL - [ ] Update field metadata : isNullable:true - [ ] Update uniqueIndex whereClause (also for standard uniqueIndex) - [ ] Activate feature flag 3/ Update metadata creation - [x] No more default default value - [x] Update standard field nullability - [x] Remove index default whereClause for standard field 4/ Update filter - [x] When filtering on NULL or empty string, be sure all records are returned (the one with NULL + the one with "") 5/ Test - [ ] Strat. to do
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
import { isEmptyObject } from '@/utils/validation/isEmptyObject';
|
|
|
|
describe('isEmptyObject', () => {
|
|
it('should return true for empty object', () => {
|
|
expect(isEmptyObject({})).toBe(true);
|
|
});
|
|
|
|
it('should return false for object with properties', () => {
|
|
expect(isEmptyObject({ key: 'value' })).toBe(false);
|
|
});
|
|
|
|
it('should return false for object with multiple properties', () => {
|
|
expect(isEmptyObject({ key1: 'value1', key2: 'value2' })).toBe(false);
|
|
});
|
|
|
|
it('should return false for null', () => {
|
|
expect(isEmptyObject(null)).toBe(false);
|
|
});
|
|
|
|
it('should return false for undefined', () => {
|
|
expect(isEmptyObject(undefined)).toBe(false);
|
|
});
|
|
|
|
it('should return false for string', () => {
|
|
expect(isEmptyObject('test')).toBe(false);
|
|
});
|
|
|
|
it('should return false for number', () => {
|
|
expect(isEmptyObject(42)).toBe(false);
|
|
});
|
|
|
|
it('should return false for boolean', () => {
|
|
expect(isEmptyObject(true)).toBe(false);
|
|
expect(isEmptyObject(false)).toBe(false);
|
|
});
|
|
|
|
it('should return true for empty array (as it has no enumerable keys)', () => {
|
|
expect(isEmptyObject([])).toBe(true);
|
|
});
|
|
|
|
it('should return false for non-empty array with enumerable properties', () => {
|
|
const arr = [1, 2, 3];
|
|
expect(isEmptyObject(arr)).toBe(false);
|
|
});
|
|
|
|
it('should return false for function', () => {
|
|
expect(isEmptyObject(() => {})).toBe(false);
|
|
});
|
|
|
|
it('should return true for Date object (as it has no enumerable keys)', () => {
|
|
expect(isEmptyObject(new Date())).toBe(true);
|
|
});
|
|
|
|
it('should return true for object created with Object.create(null)', () => {
|
|
expect(isEmptyObject(Object.create(null))).toBe(true);
|
|
});
|
|
|
|
it('should return true for object with inherited properties only', () => {
|
|
const parent = { parentProp: 'value' };
|
|
const child = Object.create(parent);
|
|
expect(isEmptyObject(child)).toBe(true); // Only checks own enumerable properties
|
|
});
|
|
|
|
it('should return true for object with non-enumerable properties only', () => {
|
|
const obj = {};
|
|
Object.defineProperty(obj, 'nonEnumerableProp', {
|
|
value: 'test',
|
|
enumerable: false,
|
|
});
|
|
expect(isEmptyObject(obj)).toBe(true); // Object.keys only returns enumerable properties
|
|
});
|
|
|
|
it('should return false for array with custom properties', () => {
|
|
const arr: any = [];
|
|
arr.customProp = 'value';
|
|
expect(isEmptyObject(arr)).toBe(false);
|
|
});
|
|
|
|
it('should return false for Date object with custom properties', () => {
|
|
const date: any = new Date();
|
|
date.customProp = 'value';
|
|
expect(isEmptyObject(date)).toBe(false);
|
|
});
|
|
});
|