UNPKG

@mindconnect/mindconnect-nodejs

Version:

NodeJS Library for Siemens Insights Hub Connectivity - TypeScript SDK for Insights Hub and Industrial IoT - Command Line Interface - Insights Hub Development Proxy (Siemens Insights Hub was formerly known as MindSphere)

210 lines 10 kB
"use strict"; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const chai = require("chai"); require("url-search-params-polyfill"); const src_1 = require("../src"); const open_edge_models_1 = require("../src/api/sdk/open-edge/open-edge-models"); const utils_1 = require("../src/api/utils"); const test_device_setup_utils_1 = require("./test-device-setup-utils"); const test_utils_1 = require("./test-utils"); chai.should(); describe.skip("[SDK] DeviceManagementClient.DeploymentWorkflow", () => { const auth = (0, utils_1.loadAuth)(); const sdk = new src_1.MindSphereSdk(Object.assign(Object.assign({}, auth), { basicAuth: (0, utils_1.decrypt)(auth, (0, test_utils_1.getPasskeyForUnitTest)()) })); const deploymentWorkflowClient = sdk.GetDeploymentWorkflowClient(); const tenant = sdk.GetTenant(); const workflowTemplate = { key: `${tenant}_fwupdate`, states: [ { name: "STOPPED", description: "test state stopped", initial: true, final: false, cancel: false, }, { name: "RUN", description: "test state run", initial: false, final: false, cancel: false, }, { name: "FINAL", description: "test state run", initial: false, final: true, cancel: false, }, { name: "CANCEL", description: "test state run", initial: false, final: false, cancel: true, }, ], transitions: [ { from: "STOPPED", to: "RUN", type: open_edge_models_1.DeploymentWorkflowModels.TransitionType.BACKENDTRIGGER, allowedTypes: [open_edge_models_1.DeploymentWorkflowModels.TransitionType.BACKENDTRIGGER], }, { from: "STOPPED", to: "CANCEL", type: open_edge_models_1.DeploymentWorkflowModels.TransitionType.BACKENDTRIGGER, allowedTypes: [open_edge_models_1.DeploymentWorkflowModels.TransitionType.BACKENDTRIGGER], }, { from: "RUN", to: "CANCEL", type: open_edge_models_1.DeploymentWorkflowModels.TransitionType.BACKENDTRIGGER, allowedTypes: [open_edge_models_1.DeploymentWorkflowModels.TransitionType.BACKENDTRIGGER], }, { from: "RUN", to: "FINAL", type: open_edge_models_1.DeploymentWorkflowModels.TransitionType.BACKENDTRIGGER, allowedTypes: [open_edge_models_1.DeploymentWorkflowModels.TransitionType.BACKENDTRIGGER], }, ], groups: [ { name: "Machine", states: ["STOPPED", "RUN", "CANCEL", "FINAL"], }, ], }; const workflowInstance = { deviceId: "", model: { key: `${tenant}_fwupdate`, customTransitions: [], }, data: { userDefined: {}, }, }; let deviceTypeId = "aee2e37f-f562-4ed6-b90a-c43208dc054a"; let assetTypeId = `${tenant}.UnitTestDeviceAssetType`; let assetId = ""; let gFolderid = ""; let deviceId = ""; let workflowModelKey = `${tenant}_fwupdate`; let workflowInstanceId = `${tenant}_fwupdate`; before(() => __awaiter(void 0, void 0, void 0, function* () { // tear Down test infrastructure yield (0, test_device_setup_utils_1.tearDownDeviceTestStructure)(sdk); // Setup the testing architecture const { device, deviceAsset, deviceType, deviceAssetType, folderid } = yield (0, test_device_setup_utils_1.setupDeviceTestStructure)(sdk); assetTypeId = `${deviceAssetType.id}`; deviceTypeId = `${deviceType.id}`; assetId = `${deviceAsset.assetId}`; deviceId = `${device.id}`; gFolderid = `${folderid}`; })); after(() => __awaiter(void 0, void 0, void 0, function* () { // tear Down test infrastructure yield (0, test_device_setup_utils_1.tearDownDeviceTestStructure)(sdk); })); it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () { sdk.should.not.be.undefined; })); it("standard properties shoud be defined", () => __awaiter(void 0, void 0, void 0, function* () { deploymentWorkflowClient.should.not.be.undefined; deploymentWorkflowClient.GetGateway().should.be.equal(auth.gateway); (yield deploymentWorkflowClient.GetToken()).length.should.be.greaterThan(200); (yield deploymentWorkflowClient.GetToken()).length.should.be.greaterThan(200); })); it("should POST to create a new workflow model", () => __awaiter(void 0, void 0, void 0, function* () { deploymentWorkflowClient.should.not.be.undefined; // Post a new deployment workflow model const newWorkflowModel = yield deploymentWorkflowClient.PostNewWorkflowModel(workflowTemplate); newWorkflowModel.should.not.be.undefined; newWorkflowModel.should.not.be.null; newWorkflowModel.key.should.not.be.undefined; newWorkflowModel.key.should.not.be.null; workflowModelKey = `${newWorkflowModel.key}`; })); it("should GET Model description for a given key", () => __awaiter(void 0, void 0, void 0, function* () { deploymentWorkflowClient.should.not.be.undefined; const workflowModel = yield deploymentWorkflowClient.GetWorkflowModel(workflowModelKey); workflowModel.should.not.be.undefined; workflowModel.should.not.be.null; workflowModel.states.should.not.be.undefined; workflowModel.states.should.not.be.null; workflowModel.states.length.should.be.gte(3); })); it("should POST a new workflow instance", () => __awaiter(void 0, void 0, void 0, function* () { deploymentWorkflowClient.should.not.be.undefined; // Prepare a new workflow instance workflowInstance.deviceId = deviceId; workflowInstance.model.key = workflowModelKey; const newWorkflowInstance = yield deploymentWorkflowClient.PostNewWorflowInstance(workflowInstance, true, true); newWorkflowInstance.should.not.be.undefined; newWorkflowInstance.should.not.be.null; newWorkflowInstance.id.should.not.be.undefined; newWorkflowInstance.id.should.not.be.null; workflowInstanceId = newWorkflowInstance.id; })); it("should GET list of instance descriptions belonging to the caller's tenant.", () => __awaiter(void 0, void 0, void 0, function* () { deploymentWorkflowClient.should.not.be.undefined; const workflowInstances = yield deploymentWorkflowClient.GetWorkflowInstances(true, true); workflowInstances.should.not.be.undefined; workflowInstances.should.not.be.null; workflowInstances.page.number.should.equal(0); workflowInstances.page.size.should.be.gte(10); workflowInstances.content.length.should.be.gte(0); })); it("should GET Instance description for a given id", () => __awaiter(void 0, void 0, void 0, function* () { deploymentWorkflowClient.should.not.be.undefined; const workflowInstance = yield deploymentWorkflowClient.GetWorkflowInstance(workflowInstanceId, true, true); workflowInstance.should.not.be.undefined; workflowInstance.should.not.be.null; workflowInstance.id.should.not.be.undefined; workflowInstance.id.should.not.be.null; })); it("should PATCH Modify current state of a workflow instance.", () => __awaiter(void 0, void 0, void 0, function* () { // Prepare state info const stateInfo = { progress: 100, message: "string", details: { userDefined: {}, }, state: "RUN", }; // Patch the state info const updatedInstance = yield deploymentWorkflowClient.PatchWorkflowInstance(workflowInstanceId, stateInfo, true, true); updatedInstance.should.not.be.undefined; updatedInstance.should.not.be.null; updatedInstance.id.should.not.be.undefined; updatedInstance.id.should.not.be.null; })); it("should POST to cancel a workflow instance", () => __awaiter(void 0, void 0, void 0, function* () { deploymentWorkflowClient.should.not.be.undefined; const workflowInstance = yield deploymentWorkflowClient.PostToCancelWorkflowInstance(workflowInstanceId, true, true); workflowInstance.should.not.be.undefined; workflowInstance.should.not.be.null; workflowInstance.id.should.not.be.undefined; workflowInstance.id.should.not.be.null; })); it("should DELETE workflow model", () => __awaiter(void 0, void 0, void 0, function* () { deploymentWorkflowClient.should.not.be.undefined; // delete file yield deploymentWorkflowClient.DeleteWorkflowModel(workflowModelKey); })); }); //# sourceMappingURL=oe-deployment-workflow.spec.js.map