"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 ramda_1 = require("ramda");
var react_hooks_1 = require("@testing-library/react-hooks");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var MdmModuleContext_1 = require("../../contexts/MdmModuleContext");
var useConfigPermissions_1 = require("./useConfigPermissions");
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { checkConfigPermission: jest.fn() })); });
var roles = ['UI_USER'];
var user = { roles: roles };
var config = { canRead: { roles: roles } };
var setUp = function () {
    var Providers = function (_a) {
        var children = _a.children;
        return react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: { user: user } }, children);
    };
    return (0, react_hooks_1.renderHook)(useConfigPermissions_1.useConfigPermissions, { wrapper: Providers }).result.current;
};
describe('useConfigPermissions behaviour', function () {
    var checkConfigPermissionMock = jest.fn();
    beforeAll(function () {
        mdm_sdk_1.checkConfigPermission.mockImplementation((0, ramda_1.curryN)(3, checkConfigPermissionMock));
    });
    it('should return correct functions', function () {
        var _a = setUp(), canCreate = _a.canCreate, canRead = _a.canRead, canUpdate = _a.canUpdate, canDelete = _a.canDelete;
        canCreate(config);
        expect(checkConfigPermissionMock).toHaveBeenCalledWith(mdm_sdk_1.ConfigPermissions.CREATE, roles, config);
        canRead(config);
        expect(checkConfigPermissionMock).toHaveBeenCalledWith(mdm_sdk_1.ConfigPermissions.READ, roles, config);
        canUpdate(config);
        expect(checkConfigPermissionMock).toHaveBeenCalledWith(mdm_sdk_1.ConfigPermissions.UPDATE, roles, config);
        canDelete(config);
        expect(checkConfigPermissionMock).toHaveBeenCalledWith(mdm_sdk_1.ConfigPermissions.DELETE, roles, config);
    });
});
