import { describe, it, expect } from 'vitest';
import { fieldDiff } from './diff';

describe('fieldDiff', () => {
  it('returns empty list for equal objects', () => {
    expect(fieldDiff({ a: 1, b: 'x' }, { a: 1, b: 'x' })).toEqual([]);
  });

  it('detects changed values', () => {
    expect(fieldDiff({ a: 1 }, { a: 2 })).toEqual([{ path: 'a', oldValue: 1, newValue: 2 }]);
  });

  it('detects added keys', () => {
    expect(fieldDiff({}, { a: 1 })).toEqual([{ path: 'a', oldValue: undefined, newValue: 1 }]);
  });

  it('detects removed keys', () => {
    expect(fieldDiff({ a: 1 }, {})).toEqual([{ path: 'a', oldValue: 1, newValue: undefined }]);
  });

  it('walks nested objects', () => {
    const diff = fieldDiff({ resources: { mem: 512 } }, { resources: { mem: 1024 } });
    expect(diff).toEqual([{ path: 'resources.mem', oldValue: 512, newValue: 1024 }]);
  });

  it('compares arrays by position', () => {
    const diff = fieldDiff({ keys: ['a', 'b'] }, { keys: ['a', 'c'] });
    expect(diff).toEqual([{ path: 'keys[1]', oldValue: 'b', newValue: 'c' }]);
  });
});
