/**
* helpers.test.ts
* Tests for helper utility functions
*/
import { nullToUndefined } from './helpers.js';
describe('helpers', () => {
describe('nullToUndefined', () => {
it('should convert null values to undefined for specified fields', () => {
const obj = {
id: '123',
title: 'Test',
notes: null,
url: null,
dueDate: '2024-01-01',
};
const result = nullToUndefined(obj, ['notes', 'url']);
expect(result.id).toBe('123');
expect(result.title).toBe('Test');
expect(result.notes).toBeUndefined();
expect(result.url).toBeUndefined();
expect(result.dueDate).toBe('2024-01-01');
});
it('should not modify non-null values', () => {
const obj = {
id: '123',
notes: 'Some notes',
url: 'https://example.com',
};
const result = nullToUndefined(obj, ['notes', 'url']);
expect(result.notes).toBe('Some notes');
expect(result.url).toBe('https://example.com');
});
it('should not modify fields not in the list', () => {
const obj = {
id: '123',
notes: null,
otherField: null,
};
const result = nullToUndefined(obj, ['notes']);
expect(result.notes).toBeUndefined();
expect(result.otherField).toBeNull();
});
it('should handle empty fields array', () => {
const obj = {
id: '123',
notes: null,
};
const result = nullToUndefined(obj, []);
expect(result.notes).toBeNull();
});
it('should create a new object and not mutate the original', () => {
const obj = {
id: '123',
notes: null,
};
const result = nullToUndefined(obj, ['notes']);
expect(result).not.toBe(obj);
expect(obj.notes).toBeNull();
expect(result.notes).toBeUndefined();
});
});
});