"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var mergeAddedAttributesWithDCRChanges_1 = require("./mergeAddedAttributesWithDCRChanges");
var createSimpleAttrType = function (overrides) {
    if (overrides === void 0) { overrides = {}; }
    return (__assign({ name: 'FirstName', uri: 'configuration/entityTypes/HCP/attributes/FirstName', label: 'First Name', type: 'String' }, overrides));
};
var createReferenceAttrType = function (overrides) {
    if (overrides === void 0) { overrides = {}; }
    return (__assign({ name: 'Address', uri: 'configuration/entityTypes/HCP/attributes/Address', label: 'Address', type: 'Reference', referencedEntityTypeURI: 'configuration/entityTypes/Location', relationshipTypeURI: 'configuration/relationTypes/HasAddress' }, overrides));
};
describe('mergeAddedAttributesWithDCRChanges', function () {
    var _a;
    var entityUri = 'entities/456';
    var baseChanges = (_a = {},
        _a[entityUri] = [
            {
                id: 'existingChange1',
                type: mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE,
                attributePath: 'Name/456',
                newValue: { value: 'New Name' },
                oldValue: { value: 'Old Name' }
            }
        ],
        _a);
    var enrichedBaseChange = {
        id: 'existingChange1',
        type: mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE,
        attributePath: 'Name/456',
        newValue: { value: 'New Name', lineIds: ['456/existingChange1/newValue'] },
        oldValue: { value: 'Old Name', lineIds: ['456/existingChange1/oldValue'] },
        lineIds: ['456/existingChange1']
    };
    it('should return enriched changes with lineIds when addedAttributes is empty', function () {
        var _a;
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(baseChanges, []);
        expect(result).toEqual((_a = {},
            _a[entityUri] = [enrichedBaseChange],
            _a));
    });
    it('should return original changes without enrichment when enrich is false and addedAttributes is empty', function () {
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(baseChanges, [], false);
        expect(result).toEqual(baseChanges);
    });
    it('should add INSERT_ATTRIBUTE change for simple root attribute', function () {
        var _a;
        var attrType = createSimpleAttrType();
        var added = [
            {
                id: 'added|abc',
                objectUri: entityUri,
                attributeType: attrType
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(baseChanges, added);
        expect(result).toEqual((_a = {},
            _a[entityUri] = [
                enrichedBaseChange,
                {
                    id: 'added|abc',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    attributePath: 'FirstName',
                    attributeType: 'configuration/entityTypes/HCP/attributes/FirstName',
                    newValue: { value: undefined, addedId: 'added|abc', lineIds: ['456/added|abc/newValue'] },
                    lineIds: ['456/added|abc']
                }
            ],
            _a));
    });
    it('should add INSERT_ATTRIBUTE with refEntity for reference attribute', function () {
        var _a;
        var attrType = createReferenceAttrType();
        var added = [
            {
                id: 'added|ref1',
                objectUri: entityUri,
                attributeType: attrType,
                refEntity: { entityUri: 'entities/789' }
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(baseChanges, added);
        expect(result).toEqual((_a = {},
            _a[entityUri] = [
                enrichedBaseChange,
                {
                    id: 'added|ref1',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    attributePath: 'Address',
                    attributeType: 'configuration/entityTypes/HCP/attributes/Address',
                    newValue: {
                        value: {},
                        addedId: 'added|ref1',
                        refEntity: { objectURI: 'entities/789' },
                        lineIds: ['456/added|ref1/newValue']
                    },
                    lineIds: ['456/added|ref1']
                }
            ],
            _a));
    });
    it('should add UPDATE_ROLES change for role attribute', function () {
        var _a;
        var added = [
            {
                id: 'added|role1',
                objectUri: entityUri,
                attributeType: mdm_sdk_1.EntityAttrTypes.roles
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(baseChanges, added);
        expect(result).toEqual((_a = {},
            _a[entityUri] = [
                enrichedBaseChange,
                {
                    id: 'added|role1',
                    type: mdm_sdk_1.DCRTypes.UPDATE_ROLES,
                    newValue: { value: [], addedId: 'added|role1', lineIds: ['456/added|role1/newValue'] },
                    lineIds: ['456/added|role1']
                }
            ],
            _a));
    });
    it('should add UPDATE_TAGS change for tag attribute', function () {
        var _a;
        var added = [
            {
                id: 'added|tag1',
                objectUri: entityUri,
                attributeType: mdm_sdk_1.EntityAttrTypes.tags
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(baseChanges, added);
        expect(result).toEqual((_a = {},
            _a[entityUri] = [
                enrichedBaseChange,
                {
                    id: 'added|tag1',
                    type: mdm_sdk_1.DCRTypes.UPDATE_TAGS,
                    newValue: { value: [], addedId: 'added|tag1', lineIds: ['456/added|tag1/newValue'] },
                    lineIds: ['456/added|tag1']
                }
            ],
            _a));
    });
    it('should add UPDATE_START_DATE change for start date attribute', function () {
        var _a;
        var added = [
            {
                id: 'added|sd1',
                objectUri: entityUri,
                attributeType: mdm_sdk_1.EntityAttrTypes.startDate
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(baseChanges, added);
        expect(result).toEqual((_a = {},
            _a[entityUri] = [
                enrichedBaseChange,
                {
                    id: 'added|sd1',
                    type: mdm_sdk_1.DCRTypes.UPDATE_START_DATE,
                    objectType: 'startDate',
                    newValue: { value: undefined, addedId: 'added|sd1', lineIds: ['456/added|sd1/newValue'] },
                    lineIds: ['456/added|sd1']
                }
            ],
            _a));
    });
    it('should add UPDATE_END_DATE change for end date attribute', function () {
        var _a;
        var added = [
            {
                id: 'added|ed1',
                objectUri: entityUri,
                attributeType: mdm_sdk_1.EntityAttrTypes.endDate
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(baseChanges, added);
        expect(result).toEqual((_a = {},
            _a[entityUri] = [
                enrichedBaseChange,
                {
                    id: 'added|ed1',
                    type: mdm_sdk_1.DCRTypes.UPDATE_END_DATE,
                    objectType: 'endDate',
                    newValue: { value: undefined, addedId: 'added|ed1', lineIds: ['456/added|ed1/newValue'] },
                    lineIds: ['456/added|ed1']
                }
            ],
            _a));
    });
    it('should attach child to existing parent node by parentId', function () {
        var _a;
        var parentAttrType = createSimpleAttrType({
            name: 'Parent',
            uri: 'configuration/entityTypes/HCP/attributes/Parent',
            type: 'Nested'
        });
        var childAttrType = createSimpleAttrType({
            name: 'Child',
            uri: 'configuration/entityTypes/HCP/attributes/Parent/attributes/Child'
        });
        var added = [
            {
                id: 'added|parent1',
                objectUri: entityUri,
                attributeType: parentAttrType
            },
            {
                id: 'added|parent1|child1',
                objectUri: entityUri,
                attributeType: childAttrType,
                parentId: 'added|parent1'
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(baseChanges, added);
        expect(result).toEqual((_a = {},
            _a[entityUri] = [
                enrichedBaseChange,
                {
                    id: 'added|parent1',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    attributePath: 'Parent',
                    attributeType: 'configuration/entityTypes/HCP/attributes/Parent',
                    newValue: {
                        value: {
                            Child: [
                                {
                                    value: undefined,
                                    addedId: 'added|parent1|child1',
                                    lineIds: ['456/added|parent1/newValue/value/Child/0']
                                }
                            ]
                        },
                        addedId: 'added|parent1',
                        lineIds: ['456/added|parent1/newValue']
                    },
                    lineIds: ['456/added|parent1']
                }
            ],
            _a));
    });
    it('should attach child to existing DCR node by parentLineId', function () {
        var _a, _b;
        var changes = (_a = {},
            _a[entityUri] = [
                {
                    id: 'existingNested',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    newValue: { value: { SubAttr: [{ value: 'test' }] } }
                }
            ],
            _a);
        var childAttrType = createSimpleAttrType({
            name: 'NewChild',
            uri: 'configuration/entityTypes/HCP/attributes/NestedAttr/attributes/NewChild'
        });
        var added = [
            {
                id: 'added|child2',
                objectUri: entityUri,
                attributeType: childAttrType,
                parentLineId: '456/existingNested/newValue'
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(changes, added);
        expect(result).toEqual((_b = {},
            _b[entityUri] = [
                {
                    id: 'existingNested',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    newValue: {
                        value: {
                            SubAttr: [{ value: 'test', lineIds: ['456/existingNested/newValue/value/SubAttr/0'] }],
                            NewChild: [
                                {
                                    value: undefined,
                                    addedId: 'added|child2',
                                    lineIds: ['456/existingNested/newValue/value/NewChild/0']
                                }
                            ]
                        },
                        lineIds: ['456/existingNested/newValue']
                    },
                    lineIds: ['456/existingNested']
                }
            ],
            _b));
    });
    it('should create INSERT_ATTRIBUTE with full path when changeOverrides is provided', function () {
        var _a;
        var changes = (_a = {},
            _a[entityUri] = [
                {
                    id: 'existingChange',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    attributePath: 'AddressNested/26fvrHXjx/PostalCode',
                    newValue: { value: '12345' },
                    attributeType: 'configuration/entityTypes/HCP/attributes/AddressNested/attributes/PostalCode'
                }
            ],
            _a);
        var childAttrType = createSimpleAttrType({
            name: 'City',
            uri: 'configuration/entityTypes/HCP/attributes/AddressNested/attributes/City'
        });
        var added = [
            {
                id: 'added|city1',
                objectUri: entityUri,
                attributeType: childAttrType,
                changeOverrides: { attributePath: 'AddressNested/26fvrHXjx/City' }
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(changes, added);
        expect(result[entityUri]).toHaveLength(2);
        expect(result[entityUri][1]).toEqual(expect.objectContaining({
            id: 'added|city1',
            type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
            attributePath: 'AddressNested/26fvrHXjx/City',
            newValue: expect.objectContaining({
                value: undefined,
                addedId: 'added|city1'
            })
        }));
    });
    it('should fill existing UPDATE_ROLES change with empty newValue instead of creating duplicate', function () {
        var _a, _b;
        var changes = (_a = {},
            _a[entityUri] = [
                {
                    id: 'existingRoles',
                    type: mdm_sdk_1.DCRTypes.UPDATE_ROLES,
                    oldValue: ['admin', 'user'],
                    newValue: undefined
                }
            ],
            _a);
        var added = [
            {
                id: 'added|role2',
                objectUri: entityUri,
                attributeType: mdm_sdk_1.EntityAttrTypes.roles
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(changes, added, false);
        expect(result).toEqual((_b = {},
            _b[entityUri] = [{ id: 'existingRoles', type: mdm_sdk_1.DCRTypes.UPDATE_ROLES, oldValue: ['admin', 'user'], newValue: [] }],
            _b));
    });
    it('should attach root attribute to existing CREATE_ENTITY change instead of creating INSERT_ATTRIBUTE', function () {
        var _a, _b;
        var createEntityChanges = (_a = {},
            _a[entityUri] = [
                {
                    id: 'createChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                    newValue: {
                        value: undefined,
                        attributes: {
                            ExistingAttr: [{ value: 'existing' }]
                        }
                    }
                }
            ],
            _a);
        var attrType = createSimpleAttrType();
        var added = [
            {
                id: 'added|abc',
                objectUri: entityUri,
                attributeType: attrType
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(createEntityChanges, added);
        expect(result).toEqual((_b = {},
            _b[entityUri] = [
                {
                    id: 'createChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                    newValue: {
                        value: undefined,
                        attributes: {
                            ExistingAttr: [
                                { value: 'existing', lineIds: ['456/createChange1/newValue/attributes/ExistingAttr/0'] }
                            ],
                            FirstName: [
                                {
                                    value: undefined,
                                    addedId: 'added|abc',
                                    lineIds: ['456/createChange1/newValue/attributes/FirstName/0']
                                }
                            ]
                        },
                        lineIds: ['456/createChange1/newValue']
                    },
                    lineIds: ['456/createChange1']
                }
            ],
            _b));
    });
    it('should attach root attribute to CREATE_RELATIONSHIP change', function () {
        var _a, _b;
        var createRelChanges = (_a = {},
            _a[entityUri] = [
                {
                    id: 'createRel1',
                    type: mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP,
                    newValue: {
                        value: undefined,
                        attributes: {}
                    }
                }
            ],
            _a);
        var attrType = createSimpleAttrType();
        var added = [
            {
                id: 'added|rel1',
                objectUri: entityUri,
                attributeType: attrType
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(createRelChanges, added);
        expect(result).toEqual((_b = {},
            _b[entityUri] = [
                {
                    id: 'createRel1',
                    type: mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP,
                    newValue: {
                        value: undefined,
                        attributes: {
                            FirstName: [
                                {
                                    value: undefined,
                                    addedId: 'added|rel1',
                                    lineIds: ['456/createRel1/newValue/attributes/FirstName/0']
                                }
                            ]
                        },
                        lineIds: ['456/createRel1/newValue']
                    },
                    lineIds: ['456/createRel1']
                }
            ],
            _b));
    });
    it('should attach roles to CREATE_ENTITY newValue instead of creating UPDATE_ROLES', function () {
        var _a, _b;
        var createEntityChanges = (_a = {},
            _a[entityUri] = [
                {
                    id: 'createChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                    newValue: {
                        value: undefined,
                        attributes: {}
                    }
                }
            ],
            _a);
        var added = [
            {
                id: 'added|role1',
                objectUri: entityUri,
                attributeType: mdm_sdk_1.EntityAttrTypes.roles
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(createEntityChanges, added);
        expect(result).toEqual((_b = {},
            _b[entityUri] = [
                {
                    id: 'createChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                    newValue: {
                        value: undefined,
                        attributes: {},
                        roles: { value: [], addedId: 'added|role1' },
                        lineIds: ['456/createChange1/newValue']
                    },
                    lineIds: ['456/createChange1']
                }
            ],
            _b));
    });
    it('should attach tags to CREATE_ENTITY newValue instead of creating UPDATE_TAGS', function () {
        var _a, _b;
        var createEntityChanges = (_a = {},
            _a[entityUri] = [
                {
                    id: 'createChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                    newValue: {
                        value: undefined,
                        attributes: {}
                    }
                }
            ],
            _a);
        var added = [
            {
                id: 'added|tag1',
                objectUri: entityUri,
                attributeType: mdm_sdk_1.EntityAttrTypes.tags
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(createEntityChanges, added);
        expect(result).toEqual((_b = {},
            _b[entityUri] = [
                {
                    id: 'createChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                    newValue: {
                        value: undefined,
                        attributes: {},
                        tags: { value: [], addedId: 'added|tag1' },
                        lineIds: ['456/createChange1/newValue']
                    },
                    lineIds: ['456/createChange1']
                }
            ],
            _b));
    });
    it('should attach startDate to CREATE_ENTITY newValue instead of creating UPDATE_START_DATE', function () {
        var _a, _b;
        var createEntityChanges = (_a = {},
            _a[entityUri] = [
                {
                    id: 'createChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                    newValue: {
                        value: undefined,
                        attributes: {}
                    }
                }
            ],
            _a);
        var added = [
            {
                id: 'added|sd1',
                objectUri: entityUri,
                attributeType: mdm_sdk_1.EntityAttrTypes.startDate
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(createEntityChanges, added);
        expect(result).toEqual((_b = {},
            _b[entityUri] = [
                {
                    id: 'createChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                    newValue: {
                        value: undefined,
                        attributes: {},
                        startDate: { addedId: 'added|sd1' },
                        lineIds: ['456/createChange1/newValue']
                    },
                    lineIds: ['456/createChange1']
                }
            ],
            _b));
    });
    it('should attach startDate to CREATE_RELATIONSHIP newValue instead of creating UPDATE_START_DATE', function () {
        var _a, _b;
        var relationUri = 'relations/rel345';
        var createRelChanges = (_a = {},
            _a[relationUri] = [
                {
                    id: 'createRelChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP,
                    newValue: {
                        attributes: { Status: [{ value: 'Active' }] },
                        type: 'configuration/relationTypes/HCPtoHCA',
                        uri: relationUri
                    }
                }
            ],
            _a);
        var added = [
            {
                id: 'added|sd1',
                objectUri: relationUri,
                parentLineId: 'rel345/createRelChange1',
                attributeType: mdm_sdk_1.EntityAttrTypes.startDate
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(createRelChanges, added);
        expect(result).toEqual((_b = {},
            _b[relationUri] = [
                {
                    id: 'createRelChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP,
                    newValue: {
                        attributes: {
                            Status: [
                                { value: 'Active', lineIds: ['rel345/createRelChange1/newValue/attributes/Status/0'] }
                            ]
                        },
                        type: 'configuration/relationTypes/HCPtoHCA',
                        uri: relationUri,
                        startDate: { addedId: 'added|sd1' },
                        lineIds: ['rel345/createRelChange1/newValue']
                    },
                    lineIds: ['rel345/createRelChange1']
                }
            ],
            _b));
    });
    it('should attach endDate to CREATE_RELATIONSHIP newValue instead of creating UPDATE_END_DATE', function () {
        var _a, _b;
        var relationUri = 'relations/rel345';
        var createRelChanges = (_a = {},
            _a[relationUri] = [
                {
                    id: 'createRelChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP,
                    newValue: {
                        attributes: {},
                        type: 'configuration/relationTypes/HCPtoHCA',
                        uri: relationUri
                    }
                }
            ],
            _a);
        var added = [
            {
                id: 'added|ed1',
                objectUri: relationUri,
                parentLineId: 'rel345/createRelChange1',
                attributeType: mdm_sdk_1.EntityAttrTypes.endDate
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(createRelChanges, added);
        expect(result).toEqual((_b = {},
            _b[relationUri] = [
                {
                    id: 'createRelChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP,
                    newValue: {
                        attributes: {},
                        type: 'configuration/relationTypes/HCPtoHCA',
                        uri: relationUri,
                        endDate: { addedId: 'added|ed1' },
                        lineIds: ['rel345/createRelChange1/newValue']
                    },
                    lineIds: ['rel345/createRelChange1']
                }
            ],
            _b));
    });
    it('should attach startDate to CREATE_RELATIONSHIP with addedId when enriched', function () {
        var _a, _b;
        var relationUri = 'relations/rel345';
        var createRelChanges = (_a = {},
            _a[relationUri] = [
                {
                    id: 'createRelChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP,
                    newValue: {
                        attributes: {},
                        type: 'configuration/relationTypes/HCPtoHCA',
                        uri: relationUri
                    }
                }
            ],
            _a);
        var added = [
            {
                id: 'added|sd1',
                objectUri: relationUri,
                parentLineId: 'rel345/createRelChange1',
                attributeType: mdm_sdk_1.EntityAttrTypes.startDate
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(createRelChanges, added, true);
        expect(result).toEqual((_b = {},
            _b[relationUri] = [
                {
                    id: 'createRelChange1',
                    type: mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP,
                    newValue: {
                        attributes: {},
                        type: 'configuration/relationTypes/HCPtoHCA',
                        uri: relationUri,
                        startDate: { addedId: 'added|sd1' },
                        lineIds: ['rel345/createRelChange1/newValue']
                    },
                    lineIds: ['rel345/createRelChange1']
                }
            ],
            _b));
    });
    it('should create separate UPDATE_START_DATE when no CREATE_RELATIONSHIP exists', function () {
        var _a, _b;
        var relationUri = 'relations/rel345';
        var existingRelChanges = (_a = {},
            _a[relationUri] = [
                {
                    id: 'updateChange1',
                    type: mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE,
                    newValue: { value: 'x' }
                }
            ],
            _a);
        var added = [
            {
                id: 'added|sd1',
                objectUri: relationUri,
                parentLineId: 'rel345/updateChange1',
                attributeType: mdm_sdk_1.EntityAttrTypes.startDate
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(existingRelChanges, added);
        expect(result).toEqual((_b = {},
            _b[relationUri] = [
                {
                    id: 'updateChange1',
                    type: mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE,
                    newValue: { value: 'x', lineIds: ['rel345/updateChange1/newValue'] },
                    lineIds: ['rel345/updateChange1']
                },
                {
                    id: 'added|sd1',
                    type: mdm_sdk_1.DCRTypes.UPDATE_START_DATE,
                    objectType: mdm_sdk_1.EntityAttrTypes.startDate.uri,
                    newValue: { value: undefined, addedId: 'added|sd1', lineIds: ['rel345/added|sd1/newValue'] },
                    lineIds: ['rel345/added|sd1']
                }
            ],
            _b));
    });
    it('should resolve objectUri from objectId when full URI is not in changes', function () {
        var changes = {
            'entities/someId123': [{ id: 'c1', type: mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE, newValue: { value: 'x' } }]
        };
        var attrType = createSimpleAttrType();
        var added = [
            {
                id: 'added|resolve1',
                objectUri: 'someId123',
                attributeType: attrType
            }
        ];
        var result = (0, mergeAddedAttributesWithDCRChanges_1.mergeAddedAttributesWithDCRChanges)(changes, added, false);
        expect(result).toEqual({
            'entities/someId123': [
                { id: 'c1', type: mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE, newValue: { value: 'x' } },
                {
                    id: 'added|resolve1',
                    type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                    attributePath: 'FirstName',
                    attributeType: 'configuration/entityTypes/HCP/attributes/FirstName',
                    newValue: { value: undefined }
                }
            ]
        });
    });
});
