UNPKG

@eclipse-emfcloud/trigger-engine

Version:

Generic model triggers computation engine.

86 lines 3.77 kB
"use strict"; // ***************************************************************************** // Copyright (C) 2023-2024 STMicroelectronics. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: MIT License which is // available at https://opensource.org/licenses/MIT. // // SPDX-License-Identifier: EPL-2.0 OR MIT // ***************************************************************************** Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const trigger_1 = require("../trigger"); const allOperations = [ { op: 'test', path: '/int', value: 42 }, { op: 'add', path: '/int', value: 42 }, { op: 'replace', path: '/int', value: 42 }, { op: 'remove', path: '/int' }, { op: 'copy', path: '/int', from: '/over/there' }, { op: 'test', path: '/string', value: '29' }, { op: 'move', path: '/string', from: '/over/there' }, { op: 'add', path: '/string', value: '29' }, { op: 'replace', path: '/string', value: '29' }, { op: 'remove', path: '/string' }, ]; describe('Helper Functions for Triggers', () => { it('nonTestOperations', () => { const nonTest = (0, trigger_1.nonTestOperations)(allOperations); (0, chai_1.expect)(nonTest).to.be.deep.equal([ { op: 'add', path: '/int', value: 42 }, { op: 'replace', path: '/int', value: 42 }, { op: 'remove', path: '/int' }, { op: 'copy', path: '/int', from: '/over/there' }, { op: 'move', path: '/string', from: '/over/there' }, { op: 'add', path: '/string', value: '29' }, { op: 'replace', path: '/string', value: '29' }, { op: 'remove', path: '/string' }, ]); }); it('addOperations', () => { const add = (0, trigger_1.addOperations)(allOperations); (0, chai_1.expect)(add).to.be.deep.equal([ { op: 'add', path: '/int', value: 42 }, { op: 'add', path: '/string', value: '29' }, ]); }); it('addOperations with value guard', () => { const add = (0, trigger_1.addOperations)(allOperations, isInt); (0, chai_1.expect)(add).to.be.deep.equal([{ op: 'add', path: '/int', value: 42 }]); }); it('addOrReplaceOperations', () => { const addOrReplace = (0, trigger_1.addOrReplaceOperations)(allOperations); (0, chai_1.expect)(addOrReplace).to.be.deep.equal([ { op: 'add', path: '/int', value: 42 }, { op: 'replace', path: '/int', value: 42 }, { op: 'add', path: '/string', value: '29' }, { op: 'replace', path: '/string', value: '29' }, ]); }); it('addOrReplaceOperations with value guard', () => { const addOrReplace = (0, trigger_1.addOrReplaceOperations)(allOperations, isString); (0, chai_1.expect)(addOrReplace).to.be.deep.equal([ { op: 'add', path: '/string', value: '29' }, { op: 'replace', path: '/string', value: '29' }, ]); }); it('removeOperations', () => { const remove = (0, trigger_1.removeOperations)(allOperations); (0, chai_1.expect)(remove).to.be.deep.equal([ { op: 'remove', path: '/int' }, { op: 'remove', path: '/string' }, ]); }); }); function isInt(value) { return typeof value === 'number'; } function isString(value) { return typeof value === 'string'; } //# sourceMappingURL=trigger.spec.js.map