"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 __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var react_hooks_1 = require("@testing-library/react-hooks");
var MdmModuleContext_1 = require("../../contexts/MdmModuleContext");
var useMatchesLoader_1 = require("./useMatchesLoader");
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getTransitiveMatches: jest.fn() })); });
describe('Test useMatchesLoader hook', function () {
    var defaultProps = {
        enabled: true,
        filter: '',
        entity: {
            uri: 'entities/0tHogNC',
            type: 'configuration/entityTypes/HCP',
            attributes: {}
        },
        options: { showTransitiveMatches: false },
        page: 0,
        rowsPerPage: 3
    };
    var getMetadata = function () { return ({
        uri: 'configuration',
        entityTypes: [
            {
                uri: 'configuration/entityTypes/HCP',
                attributes: [
                    {
                        uri: 'configuration/entityTypes/HCP/attributes/Name',
                        type: 'String',
                        label: 'Name',
                        name: 'Name'
                    }
                ]
            }
        ]
    }); };
    var defaultMdmValues = { metadata: getMetadata() };
    var setUp = function (_a) {
        var _b = _a === void 0 ? {} : _a, _c = _b.props, props = _c === void 0 ? defaultProps : _c, _d = _b.mdmValues, mdmValues = _d === void 0 ? defaultMdmValues : _d;
        var Providers = function (_a) {
            var children = _a.children;
            return react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues }, children);
        };
        return __assign({}, (0, react_hooks_1.renderHook)(useMatchesLoader_1.useMatchesLoader, { initialProps: props, wrapper: Providers }));
    };
    afterEach(function () {
        jest.clearAllMocks();
    });
    describe('Data masking behaviour', function () {
        it('should call transitive endpoint without options if metadata doesnt have masked attribute', function () {
            setUp();
            expect(mdm_sdk_1.getTransitiveMatches).toHaveBeenCalledTimes(1);
            expect(mdm_sdk_1.getTransitiveMatches).not.toHaveBeenCalledWith(expect.objectContaining({ options: expect.anything() }));
        });
        it('should call transitive endpoint with sendMasked option if metadata has masked attribute', function () {
            var metadata = getMetadata();
            metadata.entityTypes[0].attributes[0].masking = { regexPattern: '.{4}$' };
            setUp({ mdmValues: { metadata: metadata } });
            expect(mdm_sdk_1.getTransitiveMatches).toHaveBeenCalledTimes(1);
            expect(mdm_sdk_1.getTransitiveMatches).toHaveBeenCalledWith(expect.objectContaining({ options: 'sendMasked,showAccess' }));
        });
        it('should not add sendMasked or showAccess option if showMasking configuration property is false', function () {
            var metadata = getMetadata();
            metadata.entityTypes[0].attributes[0].masking = { regexPattern: '.{4}$' };
            setUp({ mdmValues: { metadata: metadata, showMasking: false } });
            expect(mdm_sdk_1.getTransitiveMatches).toHaveBeenCalledTimes(1);
            expect(mdm_sdk_1.getTransitiveMatches).not.toHaveBeenCalledWith(expect.objectContaining({ options: expect.anything() }));
        });
    });
});
