feat: remove diff

This commit is contained in:
Shivam Mishra
2025-03-12 22:18:41 +05:30
parent 5f61e043d3
commit 086b1b763e
3 changed files with 1 additions and 192 deletions
@@ -5,7 +5,6 @@ import {
filterByTeam,
filterByLabel,
filterByUnattended,
deepObjectDiff,
} from '../../conversations/helpers';
const conversationList = [
@@ -173,129 +172,3 @@ describe('#filterByUnattended', () => {
expect(filterByUnattended(true, 'mentions', 123)).toEqual(true);
});
});
describe('#deepObjectDiff', () => {
it('should detect added properties', () => {
const original = { name: 'John', age: 30 };
const updated = { name: 'John', age: 30, email: 'john@example.com' };
const result = deepObjectDiff(original, updated);
expect(result.added).toEqual({ email: 'john@example.com' });
expect(result.removed).toEqual({});
expect(result.modified).toEqual({});
});
it('should detect removed properties', () => {
const original = { name: 'John', age: 30, email: 'john@example.com' };
const updated = { name: 'John', age: 30 };
const result = deepObjectDiff(original, updated);
expect(result.added).toEqual({});
expect(result.removed).toEqual({ email: 'john@example.com' });
expect(result.modified).toEqual({});
});
it('should detect modified properties', () => {
const original = { name: 'John', age: 30 };
const updated = { name: 'John', age: 31 };
const result = deepObjectDiff(original, updated);
expect(result.added).toEqual({});
expect(result.removed).toEqual({});
expect(result.modified).toEqual({ age: { from: 30, to: 31 } });
});
it('should handle nested objects', () => {
const original = {
name: 'John',
address: { city: 'New York', country: 'USA' },
};
const updated = {
name: 'John',
address: { city: 'Boston', country: 'USA' },
};
const result = deepObjectDiff(original, updated);
expect(result.added).toEqual({});
expect(result.removed).toEqual({});
expect(result.modified).toEqual({
'address.city': { from: 'New York', to: 'Boston' },
});
});
it('should respect maxDepth parameter', () => {
const original = {
user: {
details: {
address: { city: 'New York', country: 'USA' },
},
},
};
const updated = {
user: {
details: {
address: { city: 'Boston', country: 'USA' },
},
},
};
// With maxDepth of 2
const result2 = deepObjectDiff(original, updated, 2);
expect(result2.modified).toEqual({
'user.details': {
from: {
address: { city: 'New York', country: 'USA' },
},
to: {
address: { city: 'Boston', country: 'USA' },
},
},
});
// With maxDepth of 4 (enough to reach the deepest level)
const result4 = deepObjectDiff(original, updated, 4);
expect(result4.modified).toEqual({
'user.details.address.city': { from: 'New York', to: 'Boston' },
});
});
it('should handle arrays correctly', () => {
const original = { tags: ['important', 'urgent'] };
const updated = { tags: ['important', 'normal'] };
const result = deepObjectDiff(original, updated);
expect(result.modified).toEqual({
tags: {
from: ['important', 'urgent'],
to: ['important', 'normal'],
},
});
});
it('should handle empty objects', () => {
const original = {};
const updated = {};
const result = deepObjectDiff(original, updated);
expect(result.added).toEqual({});
expect(result.removed).toEqual({});
expect(result.modified).toEqual({});
});
it('should handle completely different objects', () => {
const original = { a: 1, b: 2 };
const updated = { c: 3, d: 4 };
const result = deepObjectDiff(original, updated);
expect(result.added).toEqual({ c: 3, d: 4 });
expect(result.removed).toEqual({ a: 1, b: 2 });
expect(result.modified).toEqual({});
});
});