"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var common_1 = require("./common");
describe('common helpers', function () {
    it('getOperationType behaviour', function () {
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP)).toBe(mdm_sdk_1.DCROperationTypes.ADDED);
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE)).toBe(mdm_sdk_1.DCROperationTypes.ADDED);
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.UPDATE_TAGS)).toBe(mdm_sdk_1.DCROperationTypes.EDITED);
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.UPDATE_ROLES)).toBe(mdm_sdk_1.DCROperationTypes.EDITED);
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE)).toBe(mdm_sdk_1.DCROperationTypes.EDITED);
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.DELETE_ATTRIBUTE)).toBe(mdm_sdk_1.DCROperationTypes.DELETED);
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.DELETE_RELATIONSHIP)).toBe(mdm_sdk_1.DCROperationTypes.DELETED);
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.PIN_ATTRIBUTE, true)).toBe(mdm_sdk_1.DCROperationTypes.PINNED);
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.PIN_ATTRIBUTE, false)).toBe(mdm_sdk_1.DCROperationTypes.PIN_DELETED);
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.IGNORE_ATTRIBUTE, true)).toBe(mdm_sdk_1.DCROperationTypes.IGNORED);
        expect((0, common_1.getOperationType)(mdm_sdk_1.DCRTypes.IGNORE_ATTRIBUTE, false)).toBe(mdm_sdk_1.DCROperationTypes.IGNORE_DELETED);
    });
    it('getOperationLabel behaviour', function () {
        expect((0, common_1.getOperationLabel)(mdm_sdk_1.DCROperationTypes.ADDED)).toBe('added');
        expect((0, common_1.getOperationLabel)(mdm_sdk_1.DCROperationTypes.EDITED)).toBe('edited');
        expect((0, common_1.getOperationLabel)(mdm_sdk_1.DCROperationTypes.DELETED)).toBe('deleted');
        expect((0, common_1.getOperationLabel)(mdm_sdk_1.DCROperationTypes.PINNED)).toBe('pinned');
        expect((0, common_1.getOperationLabel)(mdm_sdk_1.DCROperationTypes.PIN_DELETED)).toBe('pin deleted');
        expect((0, common_1.getOperationLabel)(mdm_sdk_1.DCROperationTypes.IGNORED)).toBe('ignored');
        expect((0, common_1.getOperationLabel)(mdm_sdk_1.DCROperationTypes.IGNORE_DELETED)).toBe('ignore deleted');
        expect((0, common_1.getOperationLabel)('anyType')).toBe('');
    });
    describe('getAttributeDescription tests', function () {
        it('should return undefined parameters for empty arguments', function () {
            var attrType = {};
            var value = {};
            var entityUri = '';
            var objectsInfo = {};
            expect((0, common_1.getAttributeDescription)(attrType, value, entityUri, objectsInfo)).toEqual({
                objectUri: undefined,
                objectLabel: undefined,
                entityTypeUri: undefined
            });
        });
        it('should return parameters from relation if it exists', function () {
            var _a;
            var entityUri = 'entityUri1';
            var relationUri = 'relations/YduMTVk';
            var attrType = { referencedEntityTypeURI: 'configuration/entityTypes/HCA' };
            var value = {
                id: 'YduMTVk',
                refObjectURI: relationUri,
                value: { Phone: [{ id: 'uri$$123', newValue: { value: 123 } }] }
            };
            var objectsInfo = (_a = {},
                _a[entityUri] = {
                    isExist: true,
                    label: '12345 - Address Line 1 City',
                    secondaryLabel: '12345',
                    type: 'configuration/entityTypes/HCA'
                },
                _a[relationUri] = {
                    endObjectLabel: 'Address Line 1 City Zip6',
                    endObjectUri: 'entities/brJPdnD',
                    isExist: true,
                    startObjectLabel: '12345 - Address Line 1 City',
                    startObjectUri: entityUri,
                    type: 'configuration/relationTypes/HasAddress'
                },
                _a);
            expect((0, common_1.getAttributeDescription)(attrType, value, entityUri, objectsInfo)).toEqual({
                objectUri: objectsInfo[relationUri].endObjectUri,
                objectLabel: objectsInfo[relationUri].endObjectLabel
            });
        });
        it('should return parameters using refEntity', function () {
            var _a;
            var entityUri = 'entityUri1';
            var attrType = { referencedEntityTypeURI: 'configuration/entityTypes/HCA' };
            var value = {
                id: 'YduMTVk',
                refEntity: { objectURI: 'entities/brJPdnD' },
                value: { Phone: [{ newValue: { value: 123 } }] }
            };
            var objectsInfo = (_a = {},
                _a[entityUri] = {
                    isExist: true,
                    label: '12345 - Address Line 1 City',
                    secondaryLabel: '12345',
                    type: 'configuration/entityTypes/HCA'
                },
                _a['entities/brJPdnD'] = {
                    isExist: true,
                    label: 'New title',
                    secondaryLabel: '12345',
                    type: 'configuration/entityTypes/HCA'
                },
                _a);
            var expectedObjectUri = value.refEntity.objectURI;
            expect((0, common_1.getAttributeDescription)(attrType, value, entityUri, objectsInfo)).toEqual({
                objectUri: expectedObjectUri,
                objectLabel: objectsInfo[expectedObjectUri].label
            });
        });
    });
    describe('getDataTypeDefinition behaviour', function () {
        it('should set TYPE_URL if attributeValue is url', function () {
            var attributeValue = 'https://s3.amazonaws.com/reltio/source/image.jpg';
            var attributeType = {
                label: 'Full image url (S3)',
                name: 'Url',
                type: mdm_sdk_1.DataTypes.TYPE_STRING,
                uri: 'configuration/entityTypes/HCO/attributes/ImageGallery/attributes/Url'
            };
            expect((0, common_1.getDataTypeDefinition)(attributeType, attributeValue).type).toBe(mdm_sdk_1.DataTypes.TYPE_URL);
        });
        it('should not set TYPE_URL if attributeValue is not url', function () {
            var attributeValue = 'string value';
            var attributeType = {
                label: 'Address Line 1',
                name: 'AddressLine1',
                type: mdm_sdk_1.DataTypes.TYPE_STRING,
                uri: 'configuration/entityTypes/Location/attributes/AddressLine1'
            };
            expect((0, common_1.getDataTypeDefinition)(attributeType, attributeValue).type).toBe(mdm_sdk_1.DataTypes.TYPE_STRING);
        });
        it('should not change type if', function () {
            var attributeValue = 'https://s3.amazonaws.com/reltio/source/image.jpg';
            var attributeType = {
                label: 'Primary',
                name: 'Primary',
                type: mdm_sdk_1.DataTypes.TYPE_TEXT,
                uri: 'configuration/relationTypes/HasAddress/attributes/Primary'
            };
            expect((0, common_1.getDataTypeDefinition)(attributeType, attributeValue).type).toBe(mdm_sdk_1.DataTypes.TYPE_TEXT);
        });
    });
    it('getSuggestionsCount behaviour', function () {
        var changes = [{ label: '1', operation: 'added' }, { label: '2' }, { label: '3', operation: 'deleted' }];
        expect((0, common_1.getSuggestionsCount)(changes)).toBe(2);
        expect((0, common_1.getSuggestionsCount)([])).toBe(0);
    });
    describe('getDCRId behavior', function () {
        it('should work', function () {
            expect((0, common_1.getDCRId)(['entities/123', 'changeRequests/456'])).toBe('456');
            expect((0, common_1.getDCRId)(['changeRequests/123', 'relations/456'])).toBe('123');
        });
        it('should not fail if DCR uri is not found', function () {
            expect((0, common_1.getDCRId)(['entities/123', 'relations/456'])).toBe(undefined);
        });
    });
    describe('isOpenTask behavior', function () {
        it('should return true is argument is undefined', function () {
            expect((0, common_1.isOpenTask)(undefined)).toBe(true);
        });
        it('should return true is argument is true', function () {
            expect((0, common_1.isOpenTask)(true)).toBe(true);
        });
        it('should return false in other cases', function () {
            expect((0, common_1.isOpenTask)(false)).toBe(false);
        });
    });
});
