import { customMerge } from 'store/utils/helper';

test('Test merge', () => {
  const object1 = {
    company: {
      id: '1',
      title: 'Name',
      subtitle: 'test',
      list: [
        {
          name: 'name',
          value: 'value',
        },
      ],
      projects: [
        {
          name: 'project 1',
          files: [
            {
              name: 'file 1',
              id: '1',
              objectives: ['value1', 'value2'],
            },
            {
              name: 'file 2',
              id: '2',
              objectives: ['value1', 'value2'],
            },
          ],
        },
        {
          name: 'project 2',
          files: [
            {
              name: 'file 1',
              id: '1',
              objectives: ['value1', 'value2'],
            },
            {
              name: 'file 2',
              id: '2',
              objectives: ['value1', 'value2'],
            },
          ],
        },
      ],
    },
  };

  const object2 = {
    company: {
      id: '2',
      title: 'Override Name',
      projects: [
        {
          name: 'Override project 1',
          files: [
            {
              name: 'Override file 1',
              id: 'Override 1',
              objectives: ['Override value1', 'value2', 'value3'],
            },
          ],
        },
      ],
    },
  };

  const merge1 = customMerge(object1, object2);

  const merge2 = customMerge(object2, object1);

  expect(JSON.stringify(merge1)).toBe(
    JSON.stringify({
      company: {
        id: '2',
        title: 'Override Name',
        subtitle: 'test',
        list: [
          {
            name: 'name',
            value: 'value',
          },
        ],
        projects: [
          {
            name: 'Override project 1',
            files: [
              {
                name: 'Override file 1',
                id: 'Override 1',
                objectives: ['Override value1', 'value2', 'value3'],
              },
            ],
          },
        ],
      },
    }),
  );

  expect(JSON.stringify(merge2)).toBe(
    JSON.stringify({
      company: {
        id: '1',
        title: 'Name',
        projects: [
          {
            name: 'project 1',
            files: [
              {
                name: 'file 1',
                id: '1',
                objectives: ['value1', 'value2'],
              },
              {
                name: 'file 2',
                id: '2',
                objectives: ['value1', 'value2'],
              },
            ],
          },
          {
            name: 'project 2',
            files: [
              {
                name: 'file 1',
                id: '1',
                objectives: ['value1', 'value2'],
              },
              {
                name: 'file 2',
                id: '2',
                objectives: ['value1', 'value2'],
              },
            ],
          },
        ],
        subtitle: 'test',
        list: [
          {
            name: 'name',
            value: 'value',
          },
        ],
      },
    }),
  );
});
