"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var helpers_1 = require("./helpers");
describe('addLineIdToValue', function () {
    it('should add lineIds for a simple attribute', function () {
        var changes = {
            'entities/0FaSodQ': [
                {
                    id: '4pomtm9',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    newValue: { value: '434' }
                }
            ]
        };
        var result = (0, helpers_1.addLineIdToValue)(changes);
        expect(result).toEqual({
            'entities/0FaSodQ': [
                {
                    id: '4pomtm9',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    newValue: {
                        value: '434',
                        lineIds: ['0FaSodQ/4pomtm9/newValue']
                    },
                    lineIds: ['0FaSodQ/4pomtm9']
                }
            ]
        });
    });
    it('should add lineIds to the newValue of a UPDATE_TAGS change', function () {
        var changes = {
            'entities/0FaSodQ': [
                {
                    id: '0OSJEYr',
                    type: mdm_sdk_1.DCRTypes.UPDATE_TAGS,
                    newValue: ['www', 'qqq', 'sss'],
                    oldValue: ['aaa', 'bbb', 'ccc']
                }
            ]
        };
        var result = (0, helpers_1.addLineIdToValue)(changes);
        expect(result).toEqual({
            'entities/0FaSodQ': [
                {
                    id: '0OSJEYr',
                    type: mdm_sdk_1.DCRTypes.UPDATE_TAGS,
                    newValue: {
                        value: ['www', 'qqq', 'sss'],
                        lineIds: ['0FaSodQ/0OSJEYr/newValue']
                    },
                    oldValue: {
                        value: ['aaa', 'bbb', 'ccc'],
                        lineIds: ['0FaSodQ/0OSJEYr/oldValue']
                    },
                    lineIds: ['0FaSodQ/0OSJEYr']
                }
            ]
        });
    });
    it('should recursively add lineIds to nested attribute values', function () {
        var changes = {
            'entities/0FaSodQ': [
                {
                    id: '4ponaOj',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    newValue: {
                        value: {
                            TextField: [{ value: 'Test' }],
                            Int: [{ value: '42' }]
                        }
                    }
                }
            ]
        };
        var result = (0, helpers_1.addLineIdToValue)(changes);
        expect(result).toEqual({
            'entities/0FaSodQ': [
                {
                    id: '4ponaOj',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    newValue: {
                        value: {
                            TextField: [
                                {
                                    value: 'Test',
                                    lineIds: ['0FaSodQ/4ponaOj/newValue/value/TextField/0']
                                }
                            ],
                            Int: [
                                {
                                    value: '42',
                                    lineIds: ['0FaSodQ/4ponaOj/newValue/value/Int/0']
                                }
                            ]
                        },
                        lineIds: ['0FaSodQ/4ponaOj/newValue']
                    },
                    lineIds: ['0FaSodQ/4ponaOj']
                }
            ]
        });
    });
    it('should add lineIds to all attributes of CREATE_ENTITY changes', function () {
        var changes = {
            'entities/1PMfzz2w': [
                {
                    id: '36a3GSVm',
                    type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                    objectType: 'configuration/entityTypes/Location',
                    newValue: {
                        attributes: {
                            AddressLine1: [{ value: 'www' }],
                            CityTierName: [{ value: 'ALBY' }]
                        },
                        type: 'configuration/entityTypes/Location',
                        uri: 'entities/0T5H79G'
                    }
                }
            ]
        };
        var result = (0, helpers_1.addLineIdToValue)(changes);
        expect(result).toEqual({
            'entities/1PMfzz2w': [
                {
                    id: '36a3GSVm',
                    type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                    objectType: 'configuration/entityTypes/Location',
                    newValue: {
                        attributes: {
                            AddressLine1: [
                                {
                                    value: 'www',
                                    lineIds: ['1PMfzz2w/36a3GSVm/newValue/attributes/AddressLine1/0']
                                }
                            ],
                            CityTierName: [
                                {
                                    value: 'ALBY',
                                    lineIds: ['1PMfzz2w/36a3GSVm/newValue/attributes/CityTierName/0']
                                }
                            ]
                        },
                        type: 'configuration/entityTypes/Location',
                        uri: 'entities/0T5H79G',
                        lineIds: ['1PMfzz2w/36a3GSVm/newValue']
                    },
                    lineIds: ['1PMfzz2w/36a3GSVm']
                }
            ]
        });
    });
    it('should add lineIds to all attributes of CREATE_RELATIONSHIP changes', function () {
        var changes = {
            'relations/0lVSmtX': [
                {
                    id: '0G7u0JP',
                    type: mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP,
                    newValue: {
                        attributes: {
                            PrefOrActive: [{ value: 'yfhgvm' }],
                            AffiliationStatus: [{ value: 'Status 1' }],
                            PrimaryAffiliationIndicator: [{ value: 'true' }]
                        },
                        type: 'configuration/relationTypes/DirPharmacy',
                        uri: 'relations/0Mj0zAI'
                    }
                }
            ]
        };
        var result = (0, helpers_1.addLineIdToValue)(changes);
        expect(result).toEqual({
            'relations/0lVSmtX': [
                {
                    id: '0G7u0JP',
                    type: mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP,
                    newValue: {
                        attributes: {
                            PrefOrActive: [
                                {
                                    value: 'yfhgvm',
                                    lineIds: ['0lVSmtX/0G7u0JP/newValue/attributes/PrefOrActive/0']
                                }
                            ],
                            AffiliationStatus: [
                                {
                                    value: 'Status 1',
                                    lineIds: ['0lVSmtX/0G7u0JP/newValue/attributes/AffiliationStatus/0']
                                }
                            ],
                            PrimaryAffiliationIndicator: [
                                {
                                    value: 'true',
                                    lineIds: ['0lVSmtX/0G7u0JP/newValue/attributes/PrimaryAffiliationIndicator/0']
                                }
                            ]
                        },
                        type: 'configuration/relationTypes/DirPharmacy',
                        uri: 'relations/0Mj0zAI',
                        lineIds: ['0lVSmtX/0G7u0JP/newValue']
                    },
                    lineIds: ['0lVSmtX/0G7u0JP']
                }
            ]
        });
    });
    it('should add lineIds to both oldValue and newValue for UPDATE_ATTRIBUTE changes', function () {
        var changes = {
            'entities/0FaSodQ': [
                {
                    id: '4pomtm9',
                    type: mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE,
                    oldValue: { value: 'old' },
                    newValue: { value: 'new' }
                }
            ]
        };
        var result = (0, helpers_1.addLineIdToValue)(changes);
        expect(result).toEqual({
            'entities/0FaSodQ': [
                {
                    id: '4pomtm9',
                    type: mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE,
                    oldValue: {
                        value: 'old',
                        lineIds: ['0FaSodQ/4pomtm9/oldValue']
                    },
                    newValue: {
                        value: 'new',
                        lineIds: ['0FaSodQ/4pomtm9/newValue']
                    },
                    lineIds: ['0FaSodQ/4pomtm9']
                }
            ]
        });
    });
});
