import { calculateDCRChanges } from './calculateDCRChanges';
import { DCRTypes } from '@reltio/mdm-sdk';
describe('calculateDCRChanges', function () {
    var metadata = {
        entityTypes: [
            {
                uri: 'configuration/entityTypes/HCP',
                label: 'HCP',
                attributes: [
                    {
                        label: 'Name',
                        name: 'Name',
                        type: 'String',
                        uri: 'configuration/entityTypes/HCP/attributes/Name'
                    },
                    {
                        label: 'City',
                        name: 'City',
                        type: 'String',
                        uri: 'configuration/entityTypes/HCP/attributes/City'
                    },
                    {
                        label: 'Tags',
                        name: 'Tags',
                        type: 'String',
                        uri: 'configuration/entityTypes/HCP/attributes/Tags'
                    }
                ]
            }
        ]
    };
    var groupedObjects = [
        {
            entity: {
                uri: 'entities/123',
                label: 'Entity 123',
                type: 'configuration/entityTypes/HCP',
                isExist: true,
                secondaryLabel: 'Test Secondary Label'
            },
            relations: []
        }
    ];
    it('should count "added" changes correctly', function () {
        var changes = {
            'entities/123': [
                {
                    id: 'change1',
                    type: DCRTypes.UPDATE_TAGS,
                    oldValue: ['tag1', 'tag2'],
                    newValue: ['tag1', 'tag2', 'tag3']
                },
                {
                    id: 'change2',
                    type: DCRTypes.UPDATE_ROLES,
                    oldValue: ['role1'],
                    newValue: ['role1', 'role2']
                },
                {
                    id: 'change3',
                    attributePath: 'Name',
                    type: DCRTypes.INSERT_ATTRIBUTE,
                    objectType: 'configuration/entityTypes/HCP',
                    newValue: {
                        value: {
                            Name: [{ value: 'John' }]
                        }
                    }
                }
            ]
        };
        var result = calculateDCRChanges(metadata, changes, groupedObjects);
        expect(result).toEqual({
            added: 3
        });
    });
    it('should count multiple change types correctly', function () {
        var changes = {
            'entities/123': [
                {
                    id: 'change1',
                    type: DCRTypes.UPDATE_TAGS,
                    oldValue: ['tag1'],
                    newValue: ['tag1', 'tag2', 'tag3']
                },
                {
                    id: 'change2',
                    type: DCRTypes.UPDATE_ROLES,
                    oldValue: ['role1', 'role2'],
                    newValue: ['role1']
                },
                {
                    id: 'change3',
                    attributePath: 'City',
                    type: DCRTypes.INSERT_ATTRIBUTE,
                    objectType: 'configuration/entityTypes/HCP',
                    newValue: { value: { City: [{ value: 'New York' }] } }
                },
                {
                    id: 'change4',
                    attributePath: 'Name/21vmKank',
                    attributeType: 'configuration/entityTypes/HCP/attributes/Name',
                    type: DCRTypes.UPDATE_ATTRIBUTE,
                    objectType: 'configuration/entityTypes/HCP',
                    oldValue: { value: 'John' },
                    newValue: { value: 'Mike' }
                }
            ]
        };
        var result = calculateDCRChanges(metadata, changes, groupedObjects);
        expect(result).toEqual({
            added: 2,
            deleted: 1,
            edited: 1
        });
    });
    it('should handle empty changes', function () {
        var changes = {};
        var result = calculateDCRChanges(metadata, changes, groupedObjects);
        expect(result).toEqual({});
    });
});
