@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)
216 lines (198 loc) • 10 kB
JavaScript
;
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();
const timeOffset = new Date().getTime();
describe.skip("[SDK] DeviceManagementClient.FirmwareDeployment", () => {
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 firmwareDeploymentClient = sdk.GetFirmwareDeploymentClient();
const edgeAppInstanceClient = sdk.GetEdgeAppInstanceManagementClient();
const tenant = sdk.GetTenant();
const testAppInstance = {
name: `testAppInst_${tenant}_${timeOffset}`,
appInstanceId: `testAppInstId_${tenant}_${timeOffset}`,
deviceId: "string",
releaseId: `V001${timeOffset}`,
applicationId: `testAppID_${tenant}_${timeOffset}`,
};
const testConfigurations = {
deviceId: `${tenant}.UnitTestDeviceType`,
appId: "718ca5ad0...",
appReleaseId: "718ca5ad0...",
appInstanceId: "718ca5ad0...",
configuration: {
sampleKey1: "sampleValue1",
sampleKey2: "sampleValue2",
},
};
const firmwareTemplate = {
deviceId: "7d018c...",
softwareType: open_edge_models_1.FirmwareDeploymentModels.InstallationTaskInfo.SoftwareTypeEnum.FIRMWARE,
softwareId: `testSoftId_${tenant}_${timeOffset}`,
softwareReleaseId: `testSoftId_${tenant}_${timeOffset}`,
transitions: [
{
type: "string",
from: open_edge_models_1.FirmwareDeploymentModels.Transition.FromEnum.DOWNLOAD,
to: open_edge_models_1.FirmwareDeploymentModels.Transition.ToEnum.INSTALL,
details: {},
},
],
customData: {
userDefined: {},
},
};
let deviceTypeId = "aee2e37f-f562-4ed6-b90a-c43208dc054a";
let assetTypeId = `${tenant}.UnitTestDeviceAssetType`;
let assetId = "";
let gFolderid = "";
let deviceId = "";
let appId = "";
let appReleaseId = "";
let appInstanceId = "";
// let installationTaskId = "";
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}`;
// Create a new app
testAppInstance.deviceId = `${deviceId}`;
const appInstRes = yield edgeAppInstanceClient.PostAppInstance(testAppInstance);
appInstanceId = appInstRes.id;
appId = appInstRes.applicationId;
appReleaseId = appInstRes.releaseId;
// Create a new app instance configuration
testConfigurations.deviceId = `${deviceId}`;
testConfigurations.appId = `${appId}`;
testConfigurations.appInstanceId = `${appInstanceId}`;
testConfigurations.appReleaseId = `${appReleaseId}`;
const instConfRes = yield edgeAppInstanceClient.PostAppInstanceConfigurations(testConfigurations);
instConfRes.should.not.be.undefined;
// Set the firmwareTemplate
firmwareTemplate.deviceId = `${deviceId}`;
firmwareTemplate.softwareId = `${appId}`;
firmwareTemplate.softwareReleaseId = `${appInstanceId}`;
}));
after(() => __awaiter(void 0, void 0, void 0, function* () {
// delete App configuration
yield edgeAppInstanceClient.DeleteAppInstanceConfiguration(appInstanceId);
// Delete the app
yield edgeAppInstanceClient.DeleteAppInstance(appInstanceId);
// 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* () {
firmwareDeploymentClient.should.not.be.undefined;
firmwareDeploymentClient.GetGateway().should.be.equal(auth.gateway);
(yield firmwareDeploymentClient.GetToken()).length.should.be.greaterThan(200);
(yield firmwareDeploymentClient.GetToken()).length.should.be.greaterThan(200);
}));
it("should GET list of installation tasks.", () => __awaiter(void 0, void 0, void 0, function* () {
firmwareDeploymentClient.should.not.be.undefined;
const taks = yield firmwareDeploymentClient.GetInstallationTasks(deviceId);
taks.should.not.be.undefined;
taks.should.not.be.null;
taks.page.number.should.equal(0);
taks.page.size.should.be.gte(10);
taks.content.length.should.be.gte(0);
}));
/* NOTE: 27-06-2021 Not supported in yet
it("should POST accepted term and conditions", async () => {
firmwareDeploymentClient.should.not.be.undefined;
// Prepare a new workflow instance
const acceptedTermsAndConditions = await firmwareDeploymentClient.PostAcceptTermsAndConditions({
deviceId: deviceId,
releaseId: `V001${timeOffset}`
});
acceptedTermsAndConditions.should.not.be.undefined;
acceptedTermsAndConditions.should.not.be.null;
(acceptedTermsAndConditions as any).firstAccepted.should.not.be.undefined;
(acceptedTermsAndConditions as any).firstAccepted.should.not.be.null;
});
it("should GET terms and conditions", async () => {
firmwareDeploymentClient.should.not.be.undefined;
// Get terms and conditions
const appTermAndConditions = await firmwareDeploymentClient.GetTermsAndConditions(deviceId, `V001${timeOffset}`);
appTermAndConditions.should.not.be.undefined;
appTermAndConditions.should.not.be.null;
(appTermAndConditions as any).firstAccepted.should.not.be.null;
});
it("should POST a new deployment task", async () => {
firmwareDeploymentClient.should.not.be.undefined;
// Set the task template
firmwareTemplate.deviceId = `${deviceId}`;
const installationTask = await firmwareDeploymentClient.PostInstallationTask(firmwareTemplate);
(installationTask as any).should.not.be.undefined;
(installationTask as any).should.not.be.null;
(installationTask as any).id.should.not.be.undefined;
(installationTask as any).id.should.not.be.null;
(installationTask as any).currentState.should.not.be.undefined;
(installationTask as any).currentState.should.not.be.null;
installationTaskId = `${(installationTask as any).id}`;
});
it("should GET specific installation task", async () => {
firmwareDeploymentClient.should.not.be.undefined;
const task = await firmwareDeploymentClient.GetInstallationTask(installationTaskId);
(task as any).should.not.be.undefined;
(task as any).should.not.be.null;
(task as any).id.should.not.be.undefined;
(task as any).id.should.not.be.null;
});
it("should PATCH installation Status as downloading", async () => {
firmwareDeploymentClient.should.not.be.undefined;
// Set the task template
const status = {
"state": FirmwareDeploymentModels.InstallationStateInfo.StateEnum.DOWNLOADING,
"progress": 1.0,
"message": "string",
"details": {}
};
const installationTAsk = await firmwareDeploymentClient.PatchInstallationTask(installationTaskId, status);
(installationTAsk as any).should.not.be.undefined;
(installationTAsk as any).should.not.be.null;
(installationTAsk as any).currentState.should.not.be.undefined;
(installationTAsk as any).currentState.should.not.be.null;
});
it("should PATCH installation Status as activated", async () => {
firmwareDeploymentClient.should.not.be.undefined;
// Set the task template
const status = {
"state": FirmwareDeploymentModels.InstallationStateInfo.StateEnum.ACTIVATED,
"progress": 1.0,
"message": "string",
"details": {}
};
const installationTAsk = await firmwareDeploymentClient.PatchInstallationTask(installationTaskId, status);
(installationTAsk as any).should.not.be.undefined;
(installationTAsk as any).should.not.be.null;
(installationTAsk as any).currentState.should.not.be.undefined;
(installationTAsk as any).currentState.should.not.be.null;
});
*/
});
//# sourceMappingURL=oe-firmware-deployment.spec.js.map