"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var helpers_1 = require("./helpers");
describe('helpers', function () {
    describe('prepareChangeData', function () {
        it('should return "true" as a string, if attribute is boolean', function () {
            var attributeValue = {
                value: 'false',
                uri: 'uri1'
            };
            var attributeType = {
                type: mdm_sdk_1.DataTypes.TYPE_BOOLEAN
            };
            expect((0, helpers_1.prepareChangeData)(attributeValue, attributeType, true)).toEqual({
                value: 'true',
                uri: attributeValue.uri,
                attributeType: attributeType
            });
        });
        it('should return "false" as a string, if attribute is boolean', function () {
            var attributeValue = {
                value: 'true',
                uri: 'uri1'
            };
            var attributeType = {
                type: mdm_sdk_1.DataTypes.TYPE_BOOLEAN
            };
            expect((0, helpers_1.prepareChangeData)(attributeValue, attributeType, false)).toEqual({
                value: 'false',
                uri: attributeValue.uri,
                attributeType: attributeType
            });
        });
        it('should return date as a string, if attribute is date', function () {
            var attributeValue = {
                value: '2018-07-12',
                uri: 'uri1'
            };
            var attributeType = {
                type: mdm_sdk_1.DataTypes.TYPE_DATE
            };
            expect((0, helpers_1.prepareChangeData)(attributeValue, attributeType, new Date('02-14-2019'))).toEqual({
                value: '2019-02-14',
                uri: attributeValue.uri,
                attributeType: attributeType
            });
        });
        it('should return empty string, if attribute is date and value is null', function () {
            var attributeValue = {
                value: '2018-07-12',
                uri: 'uri1'
            };
            var attributeType = {
                type: mdm_sdk_1.DataTypes.TYPE_DATE
            };
            expect((0, helpers_1.prepareChangeData)(attributeValue, attributeType, null)).toEqual({
                value: '',
                uri: attributeValue.uri,
                attributeType: attributeType
            });
        });
        it('should return timestamp as a string, if attribute is timestamp', function () {
            var attributeValue = {
                value: '2018-01-11T07:00:00.000+0000',
                uri: 'uri1'
            };
            var attributeType = {
                type: mdm_sdk_1.DataTypes.TYPE_TIMESTAMP
            };
            var value = (0, helpers_1.prepareChangeData)(attributeValue, attributeType, new Date('2019-02-14T03:20:40+04:00'));
            expect(value).toMatchObject({
                uri: attributeValue.uri,
                attributeType: attributeType,
                value: '2019-02-13T23:20:40Z'
            });
        });
        it('should return empty string, if attribute is timestamp and value is null', function () {
            var attributeValue = {
                value: '2018-01-11T07:00:00.000+0000',
                uri: 'uri1'
            };
            var attributeType = {
                type: mdm_sdk_1.DataTypes.TYPE_TIMESTAMP
            };
            expect((0, helpers_1.prepareChangeData)(attributeValue, attributeType, null)).toEqual({
                value: '',
                uri: attributeValue.uri,
                attributeType: attributeType
            });
        });
        it('should return new value as is, if attribute is lookup', function () {
            var attributeValue = {
                value: 'KT',
                uri: 'uri1'
            };
            var attributeType = {
                type: mdm_sdk_1.DataTypes.TYPE_STRING,
                lookupCode: 'Units Of Measures'
            };
            var newValue = {
                value: 'G',
                lookupCode: 'Units Of Measures'
            };
            expect((0, helpers_1.prepareChangeData)(attributeValue, attributeType, newValue)).toEqual({
                value: newValue,
                uri: attributeValue.uri,
                attributeType: attributeType
            });
        });
        it('should convert null to empty string for lookups', function () {
            var attributeValue = {
                value: 'KT',
                uri: 'uri1'
            };
            var attributeType = {
                type: mdm_sdk_1.DataTypes.TYPE_STRING,
                lookupCode: 'Units Of Measures'
            };
            var newValue = null;
            expect((0, helpers_1.prepareChangeData)(attributeValue, attributeType, newValue)).toEqual({
                value: '',
                uri: attributeValue.uri,
                attributeType: attributeType
            });
        });
    });
});
