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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
    return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
import { useAttributeActions } from './useAttributeActions';
import { renderHook, act } from '@testing-library/react-hooks';
import { createAttribute, entityCumulativeDelete, entityCumulativeUpdate, ignoreAttribute, pinAttribute, removeRelation, updateAttribute } from '@reltio/mdm-sdk';
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { entityCumulativeDelete: jest.fn(), entityCumulativeUpdate: jest.fn(), ignoreAttribute: jest.fn(), pinAttribute: jest.fn(), removeRelation: jest.fn(), updateAttribute: jest.fn(), createAttribute: jest.fn() })); });
describe('useAttributeActions', function () {
    var initialProps = {
        onSuccess: jest.fn(),
        onError: jest.fn(),
        onLoad: jest.fn()
    };
    var getActions = function () {
        return renderHook(useAttributeActions, { initialProps: initialProps }).result.current;
    };
    var resolveSuccess, resolveError;
    entityCumulativeDelete.mockImplementation(function () {
        return new Promise(function (_resolve, _reject) {
            resolveSuccess = function () { return _resolve({ uri: 'entities/1', type: 'configuration/entityTypes/HCP' }); };
            resolveError = function () { return _reject({ errorMessage: 'Some error' }); };
        });
    });
    entityCumulativeUpdate.mockImplementation(function () {
        return new Promise(function (_resolve, _reject) {
            resolveSuccess = function () { return _resolve({ uri: 'relations/03xNaHt', type: 'configuration/relationTypes/HCPtoHCA' }); };
            resolveError = function () { return _reject({ errorMessage: 'Some error' }); };
        });
    });
    removeRelation.mockImplementation(function () {
        return new Promise(function (_resolve, _reject) {
            resolveSuccess = function () { return _resolve({ status: 'success' }); };
            resolveError = function () { return _reject({ errorMessage: 'Some error' }); };
        });
    });
    ignoreAttribute.mockImplementation(function () {
        return new Promise(function (_resolve, _reject) {
            resolveSuccess = function (attributeValue) { return _resolve(attributeValue); };
            resolveError = function () { return _reject({ errorMessage: 'Some error' }); };
        });
    });
    pinAttribute.mockImplementation(function () {
        return new Promise(function (_resolve, _reject) {
            resolveSuccess = function (attributeValue) { return _resolve(attributeValue); };
            resolveError = function () { return _reject({ errorMessage: 'Some error' }); };
        });
    });
    updateAttribute.mockImplementation(function () {
        return new Promise(function (_resolve, _reject) {
            resolveSuccess = function (attributeValue) { return _resolve(attributeValue); };
            resolveError = function () { return _reject({ errorMessage: 'Some error' }); };
        });
    });
    createAttribute.mockImplementation(function () {
        return new Promise(function (_resolve, _reject) {
            resolveSuccess = function (attributeValue) { return _resolve(attributeValue); };
            resolveError = function () { return _reject({ errorMessage: 'Some error' }); };
        });
    });
    afterEach(function () {
        jest.clearAllMocks();
    });
    it('should return correct delete action for simple attribute', function () { return __awaiter(void 0, void 0, void 0, function () {
        var deleteAttribute, deleteEvent, requestParams;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    deleteAttribute = getActions().deleteAttribute;
                    deleteEvent = {
                        attributeValue: {
                            uri: 'entities/1/attributes/CountryCode/1',
                            type: 'configuration/entityTypes/HCP/attributes/CountryCode',
                            value: 'Italy',
                            lookupCode: 'IT',
                            ov: true
                        },
                        attributeType: {
                            label: 'Country Code',
                            name: 'CountryCode',
                            type: 'String',
                            uri: 'configuration/entityTypes/HCP/attributes/CountryCode'
                        },
                        crosswalks: [
                            {
                                uri: 'entities/j8K1vc9/crosswalks/12jf9nL05',
                                type: 'configuration/sources/Reltio',
                                value: 'nQpZyQt',
                                reltioLoadDate: '2021-06-11T08:24:31.726Z',
                                createDate: '2018-11-19T12:14:00.735Z',
                                updateDate: '2018-11-19T12:14:00.735Z',
                                attributes: ['entities/1/attributes/CountryCode/1', 'entities/1/attributes/Date/1'],
                                singleAttributeUpdateDates: {
                                    'entities/1/attributes/Date/1': '2018-11-29T05:39:56.445Z'
                                }
                            }
                        ]
                    };
                    requestParams = {
                        uri: 'entities/1',
                        diff: [
                            {
                                crosswalk: {
                                    value: 'nQpZyQt',
                                    type: 'configuration/sources/Reltio'
                                },
                                type: 'DELETE_ATTRIBUTE',
                                uri: 'entities/1/attributes/CountryCode/1'
                            }
                        ]
                    };
                    deleteAttribute(deleteEvent);
                    expect(entityCumulativeDelete).toHaveBeenCalledWith(requestParams);
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess();
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    deleteAttribute(deleteEvent);
                    expect(entityCumulativeDelete).toHaveBeenCalledWith(requestParams);
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should return correct delete action for simple attribute with several crosswalks', function () { return __awaiter(void 0, void 0, void 0, function () {
        var deleteAttribute, deleteEvent, requestParams;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    deleteAttribute = getActions().deleteAttribute;
                    deleteEvent = {
                        attributeValue: {
                            uri: 'entities/1/attributes/CountryCode/1',
                            type: 'configuration/entityTypes/HCP/attributes/CountryCode',
                            value: 'Italy',
                            lookupCode: 'IT',
                            ov: true
                        },
                        attributeType: {
                            label: 'Country Code',
                            name: 'CountryCode',
                            type: 'String',
                            uri: 'configuration/entityTypes/HCP/attributes/CountryCode'
                        },
                        crosswalks: [
                            {
                                uri: 'entities/j8K1vc9/crosswalks/12jf9nL05',
                                type: 'configuration/sources/Reltio',
                                value: 'nQpZyQt',
                                reltioLoadDate: '2021-06-11T08:24:31.726Z',
                                createDate: '2018-11-19T12:14:00.735Z',
                                updateDate: '2018-11-19T12:14:00.735Z',
                                attributes: ['entities/1/attributes/CountryCode/1', 'entities/1/attributes/Date/1'],
                                singleAttributeUpdateDates: {
                                    'entities/1/attributes/Date/1': '2018-11-29T05:39:56.445Z'
                                },
                                sourceTable: 'sourceTable'
                            },
                            {
                                uri: 'entities/j8K1vc9/crosswalks/12jf9nL06',
                                type: 'configuration/sources/AHA',
                                value: 'nQpZyQ6',
                                reltioLoadDate: '2021-06-11T08:24:31.726Z',
                                createDate: '2018-11-19T12:14:00.735Z',
                                updateDate: '2018-11-19T12:14:00.735Z',
                                attributes: ['entities/1/attributes/CountryCode/1', 'entities/1/attributes/Date/1'],
                                singleAttributeUpdateDates: {
                                    'entities/1/attributes/Date/1': '2018-11-29T05:39:56.445Z'
                                },
                                sourceTable: 'sourceTable1'
                            }
                        ]
                    };
                    requestParams = {
                        uri: 'entities/1',
                        diff: [
                            {
                                crosswalk: {
                                    value: 'nQpZyQt',
                                    type: 'configuration/sources/Reltio',
                                    sourceTable: 'sourceTable'
                                },
                                type: 'DELETE_ATTRIBUTE',
                                uri: 'entities/1/attributes/CountryCode/1'
                            },
                            {
                                crosswalk: {
                                    value: 'nQpZyQ6',
                                    type: 'configuration/sources/AHA',
                                    sourceTable: 'sourceTable1'
                                },
                                type: 'DELETE_ATTRIBUTE',
                                uri: 'entities/1/attributes/CountryCode/1'
                            }
                        ]
                    };
                    deleteAttribute(deleteEvent);
                    expect(entityCumulativeDelete).toHaveBeenCalledWith(requestParams);
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess();
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    deleteAttribute(deleteEvent);
                    expect(entityCumulativeDelete).toHaveBeenCalledWith(requestParams);
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should return correct delete action for reference attribute', function () { return __awaiter(void 0, void 0, void 0, function () {
        var deleteAttribute, deleteEvent;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    deleteAttribute = getActions().deleteAttribute;
                    deleteEvent = {
                        attributeValue: {
                            label: 'Granada Aveue Santa Clara 1',
                            relationshipLabel: 'Office',
                            value: {
                                Status: [
                                    {
                                        type: 'configuration/relationTypes/HasAddress/attributes/Status',
                                        ov: true,
                                        value: 'Some status',
                                        uri: 'entities/1/attributes/Address/1/Status/1'
                                    }
                                ]
                            },
                            ov: true,
                            uri: 'entities/1/attributes/Address/1',
                            refEntity: {
                                type: 'configuration/entityTypes/Location',
                                crosswalks: [
                                    {
                                        uri: 'entities/1/crosswalks/1YWdmjzf.3VKnDCovj',
                                        type: 'configuration/sources/HMS',
                                        value: 'cww1',
                                        createDate: '2020-09-02T16:19:12.943Z',
                                        updateDate: '2020-09-02T16:19:12.943Z',
                                        attributeURIs: [
                                            'entities/1/attributes/Address/1/AddressLine1/1',
                                            'entities/1/attributes/Address/1'
                                        ]
                                    }
                                ],
                                objectURI: 'entities/1'
                            },
                            refRelation: {
                                type: 'configuration/relationTypes/HasAddress',
                                crosswalks: [
                                    {
                                        uri: 'entities/1/crosswalks/uAGtqeB.3VKnDCtBz',
                                        type: 'configuration/sources/HMS',
                                        value: 'cww2',
                                        createDate: '2020-09-02T16:19:12.943Z',
                                        updateDate: '2020-09-02T16:19:12.943Z',
                                        attributeURIs: [
                                            'entities/1/attributes/Address/1/Status/1',
                                            'entities/1/attributes/Address/1'
                                        ]
                                    }
                                ],
                                startRefPinned: false,
                                endRefPinned: false,
                                startRefIgnored: false,
                                endRefIgnored: false,
                                objectURI: 'relations/1'
                            },
                            startObjectCrosswalks: [
                                {
                                    type: 'configuration/sources/HMS',
                                    value: 'cww1'
                                }
                            ]
                        },
                        attributeType: {
                            label: 'Address',
                            name: 'Address',
                            type: 'Reference',
                            uri: 'configuration/entityTypes/HCP/attributes/Address',
                            referencedAttributeURIs: [
                                'configuration/entityTypes/Location/attributes/AddressLine1',
                                'configuration/relationTypes/HasAddress/attributes/Status'
                            ],
                            relationshipTypeURI: 'configuration/relationTypes/HasAddress'
                        },
                        crosswalks: [
                            {
                                uri: 'entities/1/crosswalks/uAGtqeB.3VKnDCtBz',
                                type: 'configuration/sources/HMS',
                                value: 'cww2',
                                createDate: '2020-09-02T16:19:12.943Z',
                                updateDate: '2020-09-02T16:19:12.943Z',
                                attributeURIs: ['entities/1/attributes/Address/1/Status/1', 'entities/1/attributes/Address/1']
                            }
                        ]
                    };
                    deleteAttribute(deleteEvent);
                    expect(removeRelation).toHaveBeenCalledWith('relations/1');
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess();
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    deleteAttribute(deleteEvent);
                    expect(removeRelation).toHaveBeenCalledWith('relations/1');
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should return correct delete action for relation attribute', function () { return __awaiter(void 0, void 0, void 0, function () {
        var deleteAttribute, deleteEvent, requestParams;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    deleteAttribute = getActions().deleteAttribute;
                    deleteEvent = {
                        attributeType: {
                            name: 'Int',
                            type: 'Int',
                            uri: 'configuration/relationTypes/HCPtoHCA/attributes/Int'
                        },
                        attributeValue: {
                            type: 'configuration/relationTypes/HCPtoHCA/attributes/Int',
                            ov: true,
                            value: '123',
                            uri: 'relations/03xNaHt/attributes/Int/10DnwKGs'
                        },
                        crosswalks: [
                            {
                                uri: 'relations/03xNaHt/crosswalks/n7HybxF',
                                type: 'configuration/sources/Reltio',
                                value: '03xNaHt',
                                createDate: '2024-02-02T14:11:10.208Z',
                                updateDate: '2024-02-02T14:11:10.208Z',
                                attributes: [
                                    'relations/03xNaHt/attributes/HierarchyCode/10DnwOX8',
                                    'relations/03xNaHt/attributes/Int/10DnwKGs'
                                ],
                                singleAttributeUpdateDates: {
                                    'relations/03xNaHt/attributes/HierarchyCode/10DnwOX8': '2024-05-07T08:24:58.683Z',
                                    'relations/03xNaHt/attributes/Int/10DnwKGs': '2024-05-07T08:24:58.683Z'
                                }
                            }
                        ]
                    };
                    deleteAttribute(deleteEvent);
                    requestParams = {
                        diff: [
                            {
                                crosswalk: { type: 'configuration/sources/Reltio', value: '03xNaHt' },
                                type: 'DELETE_ATTRIBUTE',
                                uri: 'relations/03xNaHt/attributes/Int/10DnwKGs'
                            }
                        ],
                        uri: 'relations/03xNaHt'
                    };
                    expect(entityCumulativeUpdate).toHaveBeenCalledWith(requestParams);
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    expect(initialProps.onSuccess).not.toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess();
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    deleteAttribute(deleteEvent);
                    expect(entityCumulativeUpdate).toHaveBeenCalledWith(requestParams);
                    expect(initialProps.onError).not.toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should return correct pin action for attribute', function () { return __awaiter(void 0, void 0, void 0, function () {
        var pinAttributeAction, attributeValue;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    pinAttributeAction = getActions().pinAttribute;
                    attributeValue = {
                        uri: 'entities/1/attributes/CountryCode/1',
                        type: 'configuration/entityTypes/HCP/attributes/CountryCode',
                        value: 'Italy',
                        lookupCode: 'IT',
                        ov: true
                    };
                    pinAttributeAction({ attributeValue: attributeValue });
                    expect(pinAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/CountryCode/1',
                        value: true
                    });
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess(__assign(__assign({}, attributeValue), { pin: true }));
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    pinAttributeAction({
                        attributeValue: __assign(__assign({}, attributeValue), { pin: true })
                    });
                    expect(pinAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/CountryCode/1',
                        value: false
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should return correct ignore action for attribute', function () { return __awaiter(void 0, void 0, void 0, function () {
        var ignoreAttributeAction, attributeValue;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    ignoreAttributeAction = getActions().ignoreAttribute;
                    attributeValue = {
                        uri: 'entities/1/attributes/CountryCode/1',
                        type: 'configuration/entityTypes/HCP/attributes/CountryCode',
                        value: 'Italy',
                        lookupCode: 'IT',
                        ov: true
                    };
                    ignoreAttributeAction({ attributeValue: attributeValue });
                    expect(ignoreAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/CountryCode/1',
                        value: true
                    });
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess(__assign(__assign({}, attributeValue), { ignored: true }));
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    ignoreAttributeAction({
                        attributeValue: __assign(__assign({}, attributeValue), { ignored: true })
                    });
                    expect(ignoreAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/CountryCode/1',
                        value: false
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should return correct update action for not lookup attribute', function () { return __awaiter(void 0, void 0, void 0, function () {
        var updateAttributeAction, editEvent;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    updateAttributeAction = getActions().updateAttribute;
                    editEvent = {
                        attributeValue: {
                            uri: 'entities/1/attributes/AddressLine/1',
                            value: 'Pushkina 1'
                        },
                        attributeType: {
                            label: 'Address Line',
                            name: 'AddressLine',
                            type: 'String',
                            uri: 'configuration/entityTypes/Location/attributes/AddressLine'
                        },
                        crosswalk: {
                            uri: 'entities/j8K1vc9/crosswalks/12jf9nL05',
                            type: 'configuration/sources/Reltio',
                            value: 'nQpZyQt',
                            reltioLoadDate: '2021-06-11T08:24:31.726Z',
                            createDate: '2018-11-19T12:14:00.735Z',
                            updateDate: '2018-11-19T12:14:00.735Z',
                            attributes: ['entities/1/attributes/CountryCode/1', 'entities/1/attributes/Date/1'],
                            singleAttributeUpdateDates: {
                                'entities/1/attributes/Date/1': '2018-11-29T05:39:56.445Z'
                            }
                        }
                    };
                    updateAttributeAction(editEvent);
                    expect(updateAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/AddressLine/1',
                        sourceUri: 'configuration/sources/Reltio',
                        crosswalkValue: 'nQpZyQt',
                        value: 'Pushkina 1'
                    });
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess(__assign({}, editEvent.attributeValue));
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(pinAttribute).not.toHaveBeenCalled();
                    expect(ignoreAttribute).not.toHaveBeenCalled();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    updateAttributeAction(editEvent);
                    expect(updateAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/AddressLine/1',
                        sourceUri: 'configuration/sources/Reltio',
                        crosswalkValue: 'nQpZyQt',
                        value: 'Pushkina 1'
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should keep ignored flag on attribute update', function () { return __awaiter(void 0, void 0, void 0, function () {
        var updateAttributeAction, editEvent;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    updateAttributeAction = getActions().updateAttribute;
                    editEvent = {
                        attributeValue: {
                            uri: 'entities/1/attributes/AddressLine/1',
                            value: 'Pushkina 1',
                            ignored: true
                        },
                        attributeType: {
                            label: 'Address Line',
                            name: 'AddressLine',
                            type: 'String',
                            uri: 'configuration/entityTypes/Location/attributes/AddressLine'
                        },
                        crosswalk: {
                            uri: 'entities/j8K1vc9/crosswalks/12jf9nL05',
                            type: 'configuration/sources/Reltio',
                            value: 'nQpZyQt',
                            reltioLoadDate: '2021-06-11T08:24:31.726Z',
                            createDate: '2018-11-19T12:14:00.735Z',
                            updateDate: '2018-11-19T12:14:00.735Z',
                            attributes: ['entities/1/attributes/CountryCode/1', 'entities/1/attributes/Date/1'],
                            singleAttributeUpdateDates: {
                                'entities/1/attributes/Date/1': '2018-11-29T05:39:56.445Z'
                            }
                        }
                    };
                    updateAttributeAction(editEvent);
                    expect(updateAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/AddressLine/1',
                        sourceUri: 'configuration/sources/Reltio',
                        crosswalkValue: 'nQpZyQt',
                        value: 'Pushkina 1'
                    });
                    expect(pinAttribute).not.toHaveBeenCalled();
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess(__assign({}, editEvent.attributeValue));
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(ignoreAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/AddressLine/1',
                        value: true
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess(__assign({}, editEvent.attributeValue));
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should return correct update action for lookup attribute', function () { return __awaiter(void 0, void 0, void 0, function () {
        var updateAttributeAction, editEvent;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    updateAttributeAction = getActions().updateAttribute;
                    editEvent = {
                        attributeValue: {
                            uri: 'entities/1/attributes/CountryCode/1',
                            value: 'Italy',
                            lookupCode: 'IT'
                        },
                        attributeType: {
                            label: 'Country Code',
                            name: 'CountryCode',
                            type: 'String',
                            uri: 'configuration/entityTypes/HCP/attributes/CountryCode',
                            dependentLookupCode: 'COUNTRY_CD'
                        },
                        crosswalk: {
                            uri: 'entities/j8K1vc9/crosswalks/12jf9nL05',
                            type: 'configuration/sources/Reltio',
                            value: 'nQpZyQt',
                            reltioLoadDate: '2021-06-11T08:24:31.726Z',
                            createDate: '2018-11-19T12:14:00.735Z',
                            updateDate: '2018-11-19T12:14:00.735Z',
                            attributes: ['entities/1/attributes/CountryCode/1', 'entities/1/attributes/Date/1'],
                            singleAttributeUpdateDates: {
                                'entities/1/attributes/Date/1': '2018-11-29T05:39:56.445Z'
                            }
                        }
                    };
                    updateAttributeAction(editEvent);
                    expect(updateAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/CountryCode/1',
                        sourceUri: 'configuration/sources/Reltio',
                        crosswalkValue: 'nQpZyQt',
                        value: 'IT'
                    });
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess(__assign({}, editEvent.attributeValue));
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    updateAttributeAction(editEvent);
                    expect(updateAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/CountryCode/1',
                        sourceUri: 'configuration/sources/Reltio',
                        crosswalkValue: 'nQpZyQt',
                        value: 'IT'
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should return correct create action for not lookup attribute', function () { return __awaiter(void 0, void 0, void 0, function () {
        var createAttributeAction, attributeValue, crosswalk;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    createAttributeAction = getActions().createAttribute;
                    attributeValue = {
                        uri: 'entities/1/attributes/CountryCode/$$$uri1',
                        type: 'configuration/entityTypes/HCP/attributes/CountryCode',
                        value: 'Italy',
                        ov: true
                    };
                    crosswalk = {
                        uri: 'entities/j8K1vc9/crosswalks/12jf9nL05',
                        type: 'configuration/sources/Reltio',
                        value: 'nQpZyQt',
                        reltioLoadDate: '2021-06-11T08:24:31.726Z',
                        createDate: '2018-11-19T12:14:00.735Z',
                        updateDate: '2018-11-19T12:14:00.735Z',
                        attributes: ['entities/1/attributes/CountryCode/1', 'entities/1/attributes/Date/1'],
                        singleAttributeUpdateDates: {
                            'entities/1/attributes/Date/1': '2018-11-29T05:39:56.445Z'
                        }
                    };
                    createAttributeAction({ attributeValue: attributeValue, crosswalk: crosswalk });
                    expect(createAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/CountryCode/$$$uri1',
                        sourceUri: 'configuration/sources/Reltio',
                        crosswalkValue: 'nQpZyQt',
                        crosswalkSourceTable: undefined,
                        value: 'Italy'
                    });
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess([{ index: 0, successful: true, object: {} }]);
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    createAttributeAction({ attributeValue: attributeValue, crosswalk: crosswalk });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should return correct create action for lookup attribute', function () { return __awaiter(void 0, void 0, void 0, function () {
        var createAttributeAction, attributeValue, crosswalk;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    createAttributeAction = getActions().createAttribute;
                    attributeValue = {
                        uri: 'entities/1/attributes/CountryCode/$$$uri1',
                        type: 'configuration/entityTypes/HCP/attributes/CountryCode',
                        value: 'Italy',
                        lookupCode: 'IT',
                        ov: true
                    };
                    crosswalk = {
                        uri: 'entities/j8K1vc9/crosswalks/12jf9nL05',
                        type: 'configuration/sources/Reltio',
                        value: 'nQpZyQt',
                        reltioLoadDate: '2021-06-11T08:24:31.726Z',
                        createDate: '2018-11-19T12:14:00.735Z',
                        updateDate: '2018-11-19T12:14:00.735Z',
                        attributes: ['entities/1/attributes/CountryCode/1', 'entities/1/attributes/Date/1'],
                        singleAttributeUpdateDates: {
                            'entities/1/attributes/Date/1': '2018-11-29T05:39:56.445Z'
                        }
                    };
                    createAttributeAction({ attributeValue: attributeValue, crosswalk: crosswalk });
                    expect(createAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/1/attributes/CountryCode/$$$uri1',
                        sourceUri: 'configuration/sources/Reltio',
                        crosswalkValue: 'nQpZyQt',
                        crosswalkSourceTable: undefined,
                        value: 'IT'
                    });
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess([{ index: 0, successful: true, object: {} }]);
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    createAttributeAction({ attributeValue: attributeValue, crosswalk: crosswalk });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should return correct create action for lookup attribute inside nested', function () { return __awaiter(void 0, void 0, void 0, function () {
        var createAttributeAction, attributeValue, crosswalk;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    createAttributeAction = getActions().createAttribute;
                    attributeValue = {
                        value: {
                            CountryCode: [
                                {
                                    value: 'Germany',
                                    uri: 'entities/03caeDZ/attributes/UseCase1/uri$$K6aSzmeM8knmWyNT1711463312035/CountryCode/uri$$iRJqqbduM4p6SSmf1711463314199',
                                    type: 'configuration/entityTypes/ForDL/attributes/UseCase1/attributes/CountryCode',
                                    lookupCode: 'DE'
                                }
                            ]
                        },
                        uri: 'entities/03caeDZ/attributes/UseCase1/uri$$K6aSzmeM8knmWyNT1711463312035',
                        type: 'configuration/entityTypes/ForDL/attributes/UseCase1'
                    };
                    crosswalk = {
                        ownerType: 'entity',
                        uri: 'entities/03caeDZ/crosswalks/StgcmIT',
                        type: 'configuration/sources/Reltio',
                        value: '03caeDZ',
                        reltioLoadDate: '2024-03-21T10:56:35.541Z',
                        createDate: '2023-10-24T07:00:52.741Z',
                        updateDate: '2023-10-24T07:00:52.741Z',
                        attributes: [
                            'entities/03caeDZ/attributes/CountryCode/rqQhlc2',
                            'entities/03caeDZ/attributes/CountryCode/og2irm1',
                            'entities/03caeDZ/attributes/Name/Stgci2D'
                        ],
                        singleAttributeUpdateDates: {
                            'entities/03caeDZ/attributes/CountryCode/rqQhlc2': '2024-03-21T10:33:38.146Z',
                            'entities/03caeDZ/attributes/CountryCode/og2irm1': '2024-03-21T10:31:37.206Z'
                        }
                    };
                    createAttributeAction({ attributeValue: attributeValue, crosswalk: crosswalk });
                    expect(createAttribute).toHaveBeenCalledWith({
                        attributeUri: 'entities/03caeDZ/attributes/UseCase1/uri$$K6aSzmeM8knmWyNT1711463312035',
                        sourceUri: 'configuration/sources/Reltio',
                        crosswalkValue: '03caeDZ',
                        crosswalkSourceTable: undefined,
                        value: {
                            CountryCode: [
                                {
                                    value: 'Germany',
                                    uri: 'entities/03caeDZ/attributes/UseCase1/uri$$K6aSzmeM8knmWyNT1711463312035/CountryCode/uri$$iRJqqbduM4p6SSmf1711463314199',
                                    type: 'configuration/entityTypes/ForDL/attributes/UseCase1/attributes/CountryCode',
                                    lookupCode: 'DE'
                                }
                            ]
                        }
                    });
                    expect(initialProps.onLoad).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveSuccess([{ index: 0, successful: true, object: {} }]);
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(initialProps.onSuccess).toHaveBeenCalled();
                    createAttributeAction({ attributeValue: attributeValue, crosswalk: crosswalk });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                resolveError();
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(initialProps.onError).toHaveBeenCalledWith({ errorMessage: 'Some error' });
                    return [2 /*return*/];
            }
        });
    }); });
});
