@eclipse-emfcloud/model-service
Version:
Model service framework
109 lines • 4.89 kB
JavaScript
;
// *****************************************************************************
// 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
// *****************************************************************************
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = __importStar(require("chai"));
const chai_as_promised_1 = __importDefault(require("chai-as-promised"));
const sinon_1 = __importDefault(require("sinon"));
const sinon_chai_1 = __importDefault(require("sinon-chai"));
const model_service_contribution_1 = require("../model-service-contribution");
chai_1.default.use(sinon_chai_1.default);
chai_1.default.use(chai_as_promised_1.default);
describe('AbstractModelServiceContribution', () => {
const id = '@test/contrib';
let contrib;
let sandbox;
let persistenceContribution;
beforeEach(() => {
sandbox = sinon_1.default.createSandbox();
contrib = new TestContribution();
persistenceContribution = {
canHandle: sandbox.stub().returns(true),
loadModel: sandbox.stub().returns(Promise.resolve({})),
saveModel: sandbox.stub().returns(Promise.resolve(true)),
};
});
afterEach(() => {
sandbox.restore();
});
it('id', () => {
contrib.postConstruct({ id });
(0, chai_1.expect)(contrib.id).to.be.equal('@test/contrib');
});
describe('persistenceContribution', () => {
it('supplied', async () => {
contrib.postConstruct({
id,
persistenceContribution,
});
const persistence = contrib.persistenceContribution;
(0, chai_1.expect)(persistence).to.exist;
(0, chai_1.expect)(persistence.canHandle('myModel')).to.be.true;
await persistence.saveModel('myModel', await persistence.loadModel('myModel'));
(0, chai_1.expect)(persistenceContribution.canHandle).to.have.been.called;
(0, chai_1.expect)(persistenceContribution.loadModel).to.have.been.called;
(0, chai_1.expect)(persistenceContribution.saveModel).to.have.been.called;
});
it('defaulted', async () => {
contrib.postConstruct({ id });
const persistence = contrib.persistenceContribution;
(0, chai_1.expect)(persistence).to.exist;
await (0, chai_1.expect)(persistence.canHandle('myModel')).to.eventually.be.false;
await (0, chai_1.expect)(persistence.loadModel('myModel')).to.eventually.be.rejected;
await (0, chai_1.expect)(persistence.saveModel('myModel', {})).to.eventually.be
.rejected;
});
});
});
class TestContribution extends model_service_contribution_1.AbstractModelServiceContribution {
postConstruct({ id, persistenceContribution, validationContribution, modelAccessorContribution, }) {
this.initialize({
id,
persistenceContribution,
validationContribution,
modelAccessorContribution,
});
}
getModelService() {
throw new Error('Method not required for testing.');
}
}
//# sourceMappingURL=model-service-contribution.spec.js.map