"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
Object.defineProperty(exports, "__esModule", { value: true });
var helpers_1 = require("./helpers");
describe('helpers.ts tests', function () {
    var attributesUris = [
        'configuration/entityTypes/HCP/attributes/Phone',
        'configuration/entityTypes/HCP/attributes/Phone/attributes/Number',
        'configuration/entityTypes/HCP/attributes/Phone/attributes/Number/attributes/Number2',
        'configuration/entityTypes/HCP/attributes/Phone/attributes/Number/attributes/Number2/attributes/Number3',
        'configuration/entityTypes/HCP/attributes/Phone/attributes/Type',
        'configuration/entityTypes/HCP/attributes/Phone/attributes/Phone',
        'configuration/entityTypes/HCP/attributes/Phone/attributes/Phone/attributes/Phone2',
        'configuration/entityTypes/HCP/attributes/Phone/attributes/Phone/attributes/Phone3',
        'configuration/entityTypes/HCP/attributes/Phone/attributes/Address'
    ];
    describe('generatePivotingValue', function () {
        var pivotingAttributes = [{ uri: attributesUris[0], children: [attributesUris[1], attributesUris[4]] }];
        var attributeType = {
            uri: attributesUris[0],
            name: 'Phone',
            type: 'Nested',
            attributes: [
                {
                    uri: attributesUris[1],
                    name: 'Number',
                    type: 'Nested',
                    attributes: [
                        {
                            uri: attributesUris[2],
                            name: 'Number2',
                            type: 'Nested',
                            attributes: [{ uri: attributesUris[3], name: 'Number3', type: 'String' }]
                        }
                    ]
                },
                { uri: attributesUris[4], name: 'Type', type: 'String' }
            ]
        };
        var value = {
            Number: [
                {
                    type: attributesUris[1],
                    ov: true,
                    value: '123 456',
                    uri: 'entities/AkJzWnY/attributes/Phone/LIcWee3k/Number/LIcWemaG'
                }
            ],
            Type: [
                {
                    type: attributesUris[4],
                    ov: true,
                    value: 'Work',
                    lookupCode: 'W',
                    uri: 'entities/AkJzWnY/attributes/Phone/LIcWee3k/Type/LIcWeiK0'
                }
            ]
        };
        var metadata = {
            entityTypes: [
                {
                    attributes: [attributeType],
                    uri: 'configuration/entityTypes/HCP',
                    analyticsAttributes: []
                }
            ]
        };
        it('should generate correct value for NestedAttribute', function () {
            var _a, _b;
            expect((0, helpers_1.generatePivotingValue)(attributeType, value, pivotingAttributes, metadata)).toStrictEqual([
                (_a = {}, _a[attributesUris[1]] = ['123 456'], _a),
                (_b = {}, _b[attributesUris[4]] = ['W'], _b)
            ]);
        });
        it('should generate correct value for deep nested(3 level)', function () {
            var _a, _b, _c;
            var value1 = {
                Number: [
                    {
                        type: attributesUris[1],
                        ov: true,
                        value: {
                            Number2: [
                                {
                                    uri: 'entities/AkJzWnY/attributes/Phone/LIcWee3k/Number/LIcWemaG/Number2/dfsdfsdf',
                                    ov: true,
                                    type: attributesUris[2],
                                    value: '123 456'
                                }
                            ]
                        },
                        uri: 'entities/AkJzWnY/attributes/Phone/LIcWee3k/Number/LIcWemaG'
                    }
                ],
                Type: [
                    {
                        type: attributesUris[4],
                        ov: true,
                        value: 'Work',
                        lookupCode: 'W',
                        uri: 'entities/AkJzWnY/attributes/Phone/LIcWee3k/Type/LIcWeiK0'
                    }
                ]
            };
            expect((0, helpers_1.generatePivotingValue)(attributeType, value1, pivotingAttributes, metadata)).toStrictEqual([
                (_a = {}, _a[attributesUris[1]] = [(_b = {}, _b[attributesUris[2]] = ['123 456'], _b)], _a),
                (_c = {}, _c[attributesUris[4]] = ['W'], _c)
            ]);
        });
        it('should generate correct value for deep nested(4 level)', function () {
            var _a, _b, _c, _d;
            var value1 = {
                Number: [
                    {
                        type: attributesUris[1],
                        ov: true,
                        value: {
                            Number2: [
                                {
                                    uri: 'entities/AkJzWnY/attributes/Phone/LIcWee3k/Number/LIcWemaG/Number2/dfsdfsdf',
                                    ov: true,
                                    type: attributesUris[2],
                                    value: {
                                        Number3: [
                                            {
                                                uri: 'entities/AkJzWnY/attributes/Phone/LIcWee3k/Number/LIcWemaG/Number2/dfsdfsdf/Number3/aassddff',
                                                ov: true,
                                                type: attributesUris[3],
                                                value: '123 456'
                                            }
                                        ]
                                    }
                                }
                            ]
                        },
                        uri: 'entities/AkJzWnY/attributes/Phone/LIcWee3k/Number/LIcWemaG'
                    }
                ],
                Type: [
                    {
                        type: attributesUris[4],
                        ov: true,
                        value: 'Work',
                        lookupCode: 'W',
                        uri: 'entities/AkJzWnY/attributes/Phone/LIcWee3k/Type/LIcWeiK0'
                    }
                ]
            };
            expect((0, helpers_1.generatePivotingValue)(attributeType, value1, pivotingAttributes, metadata)).toStrictEqual([
                (_a = {}, _a[attributesUris[1]] = [(_b = {}, _b[attributesUris[2]] = [(_c = {}, _c[attributesUris[3]] = ['123 456'], _c)], _b)], _a),
                (_d = {}, _d[attributesUris[4]] = ['W'], _d)
            ]);
        });
    });
    describe('preparePivotingAttributeValue', function () {
        it.each(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n            value                             | attrType               | expected\n            ", "                   | ", "      | ", "\n            ", "                | ", " | ", "\n            ", " | ", " | ", "\n            ", "              | ", "    | ", "\n        "], ["\n            value                             | attrType               | expected\n            ", "                   | ", "      | ", "\n            ", "                | ", " | ", "\n            ", " | ", " | ", "\n            ", "              | ", "    | ", "\n        "])), '2021-05-25', { type: 'Date' }, 1621900800000, '1622031748997', { type: 'Timestamp' }, 1622031748997, '2020-02-20T07:00:00.000+0000', { type: 'Timestamp' }, 1582182000000, 'just some value', { type: 'Number' }, 'just some value')('return $expected if $value and $attrType', function (_a) {
            var value = _a.value, attrType = _a.attrType, expected = _a.expected;
            expect((0, helpers_1.preparePivotingAttributeValue)(value, attrType)).toEqual(expected);
        });
    });
    describe('convertSimpleAttributePivotingValue', function () {
        it('should work correctly', function () {
            var attrType1 = {
                name: 'CountryCode'
            };
            expect((0, helpers_1.convertSimpleAttributePivotingValue)(attrType1, 123456)).toEqual([{ CountryCode: 123456 }]);
            var attrType2 = {
                name: 'FirstName'
            };
            expect((0, helpers_1.convertSimpleAttributePivotingValue)(attrType2, 'Igor')).toEqual([{ FirstName: 'Igor' }]);
        });
    });
    describe('convertNestedAttributePivotingValue', function () {
        it('should work correctly', function () {
            var value = [
                {
                    'configuration/entityTypes/HCP/attributes/Specialities/attributes/SpecialityStatus': ['ACTI'],
                    'configuration/entityTypes/HCP/attributes/Specialities/attributes/PrimarySpecialityInd': ['true']
                },
                {
                    'configuration/entityTypes/HCP/attributes/CustomerTitle/attributes/Title': ['some value']
                }
            ];
            expect((0, helpers_1.convertNestedAttributePivotingValue)(value)).toEqual([
                {
                    SpecialityStatus: ['ACTI'],
                    PrimarySpecialityInd: ['true']
                },
                {
                    Title: ['some value']
                }
            ]);
        });
    });
});
var templateObject_1;
