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

describe('getArrayDiff', () => {
  it.each([
    [[2, 3], [1, 2, 3], [], [1]],
    [[1, 2, 3], [2, 3], [1], []],
    [[1, 2], [2, 3], [1], [3]],
    [[1, 2], [], [1, 2], []],
    [[], [1, 2], [], [1, 2]],
    [[1, 2, 3], [1, 2, 3], [], []],
  ])(
    'finds differences in primitive type array correctly',
    (current, initial, added, removed) => {
      expect(getArrayDiff(current, initial)).toEqual({
        added,
        removed,
        updated: [],
      });
    },
  );

  it.each([
    [
      [{ id: 2 }, { id: 3 }],
      [{ id: 1 }, { id: 2 }, { id: 3 }],
      [],
      [{ id: 1 }],
      [],
    ],
    [
      [{ id: 1 }, { id: 2 }, { id: 3 }],
      [{ id: 2 }, { id: 3 }],
      [{ id: 1 }],
      [],
      [],
    ],
    [
      [
        { id: 1, key: 'value1' },
        { id: 2, key: 'value' },
      ],
      [
        { id: 1, key: 'value' },
        { id: 2, key: 'value' },
      ],
      [],
      [],
      [{ id: 1, key: 'value1' }],
    ],
  ])(
    'finds differences in object array correctly',
    (current, initial, added, removed, updated) => {
      expect(getArrayDiff(current, initial, 'id')).toEqual({
        added,
        removed,
        updated,
      });
    },
  );
});
