"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);
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
var nestedHelpers_1 = require("./nestedHelpers");
describe('from nested strategy test', function () {
    var metadata = {
        entityTypes: [
            {
                uri: 'configuration/entityTypes/EntityWithNestedAddress',
                geoLocationAttributes: [
                    {
                        latitude: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude',
                        longitude: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude'
                    }
                ],
                attributes: [
                    {
                        name: 'Location',
                        type: 'Nested',
                        uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location',
                        attributes: [
                            {
                                name: 'GeoLocation',
                                uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation',
                                type: 'Nested',
                                attributes: [
                                    {
                                        name: 'Latitude',
                                        type: 'String',
                                        uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude'
                                    },
                                    {
                                        name: 'Longitude',
                                        type: 'String',
                                        uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude'
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    };
    var entities = [
        {
            label: 'label',
            uri: 'entities/1SfTJYdD',
            ov: true,
            type: 'configuration/entityTypes/EntityWithNestedAddress',
            attributes: {
                Location: [
                    {
                        type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location',
                        ov: true,
                        uri: 'entities/1SfTJYdD/attributes/Location/3GXtYP63L',
                        value: {
                            GeoLocation: [
                                {
                                    type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation',
                                    uri: 'entities/1SfTJYdD/attributes/Location/3GXtYP63L/GeoLocation/3GXtYPAJb',
                                    ov: true,
                                    value: {
                                        Longitude: [
                                            {
                                                type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude',
                                                value: '123',
                                                ov: true,
                                                uri: 'entities/1SfTJYdD/attributes/Location/3GXtYP63L/GeoLocation/3GXtYPAJb/Longitude/3GXtYPEZr'
                                            }
                                        ],
                                        Latitude: [
                                            {
                                                type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude',
                                                value: '321',
                                                ov: true,
                                                uri: 'entities/1SfTJYdD/attributes/Location/3GXtYP63L/GeoLocation/3GXtYPAJb/Latitude/3GXtYPIq7'
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    },
                    {
                        type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location',
                        ov: true,
                        uri: 'entities/1SfTJYdD/attributes/Location/3GXtdfg3L',
                        value: {
                            GeoLocation: [
                                {
                                    type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation',
                                    uri: 'entities/1SfTJYdD/attributes/Location/3GXtdfg3L/GeoLocation/3GXcvb1234',
                                    ov: true,
                                    value: {
                                        Longitude: [
                                            {
                                                type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude',
                                                value: '456',
                                                ov: true,
                                                uri: 'entities/1SfTJYdD/attributes/Location/3GXtdfg3L/GeoLocation/3GXcvb1234/Longitude/3GedY1235'
                                            }
                                        ],
                                        Latitude: [
                                            {
                                                type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude',
                                                value: '654',
                                                ov: true,
                                                uri: 'entities/1SfTJYdD/attributes/Location/3GXtdfg3L/GeoLocation/3GXcvb1234/Latitude/3GXt4ki77'
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    },
                    {
                        type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location',
                        ov: false,
                        uri: 'entities/1SfTJYdD/attributes/Location/3GXektg3L',
                        value: {
                            GeoLocation: [
                                {
                                    type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation',
                                    uri: 'entities/1SfTJYdD/attributes/Location/3GXektg3L/GeoLocation/3Goke1234',
                                    ov: true,
                                    value: {
                                        Longitude: [
                                            {
                                                type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude',
                                                value: '456',
                                                ov: true,
                                                uri: 'entities/1SfTJYdD/attributes/Location/3GXektg3L/GeoLocation/3Goke1234/Longitude/3hedY1235'
                                            }
                                        ],
                                        Latitude: [
                                            {
                                                type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude',
                                                value: '654',
                                                ov: true,
                                                uri: 'entities/1SfTJYdD/attributes/Location/3GXektg3L/GeoLocation/3Goke1234/Latitude/6GXt4ki77'
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ];
    it('should get geo location attributes from nested address', function () {
        var points = (0, nestedHelpers_1.getPointsFromNested)(metadata, entities);
        expect(points.length).toBe(2);
        expect(points[0].entity).toEqual(entities[0]);
        expect(points[0].label).toBe('label');
        expect(points[0].point).toEqual({ lat: 321, lng: 123 });
        expect(points[1].entity).toEqual(entities[0]);
        expect(points[1].label).toBe('label');
        expect(points[1].point).toEqual({ lat: 654, lng: 456 });
        expect(points[0].id).not.toBe(points[1].id);
    });
    it('should add only uniq points', function () {
        var points = (0, nestedHelpers_1.getPointsFromNested)(metadata, [
            __assign(__assign({}, entities[0]), { attributes: __assign(__assign({}, entities[0].attributes), { Location: __spreadArray(__spreadArray([], entities[0].attributes.Location, true), entities[0].attributes.Location, true) }) })
        ]);
        expect(points.length).toBe(2);
    });
    it('should not fail if entity type is not found', function () {
        var points = (0, nestedHelpers_1.getPointsFromNested)(metadata, [{}]);
        expect(points.length).toBe(0);
    });
    it('should return empty array if geoLocationAttributes is not exists', function () {
        var points = (0, nestedHelpers_1.getPointsFromNested)({
            entityTypes: [
                {
                    uri: 'configuration/entityTypes/EntityWithNestedAddress',
                    attributes: [
                        {
                            name: 'Location',
                            type: 'Nested',
                            uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location',
                            attributes: [
                                {
                                    name: 'GeoLocation',
                                    uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation',
                                    type: 'Nested',
                                    attributes: [
                                        {
                                            name: 'Latitude',
                                            type: 'String',
                                            uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude'
                                        },
                                        {
                                            name: 'Longitude',
                                            type: 'String',
                                            uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude'
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }, entities);
        expect(points).toEqual([]);
    });
    it('should not consider attributes with masking while constructing point', function () {
        var maskedMetadata = JSON.parse(JSON.stringify(metadata));
        maskedMetadata.entityTypes[0].attributes[0].attributes[0].attributes[0].masking = { regex: '***' };
        var points = (0, nestedHelpers_1.getPointsFromNested)(maskedMetadata, entities);
        expect(points.length).toBe(0);
    });
});
