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)

288 lines (287 loc) 15.2 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(); const timeOffset = new Date().getTime(); describe.skip("[SDK] DeviceManagementClient.EdgeAppInstance", () => { 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 edgeAppInstanceClient = sdk.GetEdgeAppInstanceManagementClient(); const tenant = sdk.GetTenant(); const testAppInstance = { name: `testAppInst_${tenant}_${timeOffset}`, appInstanceId: `testAppInst_${tenant}_${timeOffset}`, deviceId: "string", releaseId: "string", applicationId: `testApp_${tenant}_${timeOffset}`, }; const testConfigurations = { deviceId: `${tenant}.UnitTestDeviceType`, appId: "718ca5ad0...", appReleaseId: "718ca5ad0...", appInstanceId: "718ca5ad0...", configuration: { sampleKey1: "sampleValue1", sampleKey2: "sampleValue2", }, }; let deviceTypeId = "aee2e37f-f562-4ed6-b90a-c43208dc054a"; let assetTypeId = `${tenant}.UnitTestDeviceAssetType`; let assetId = ""; let gFolderid = ""; let deviceId = ""; let appId = ""; let appReleaseId = ""; let appInstanceId = ""; 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}`; testConfigurations.deviceId = `${device.id}`; // Create a new app testAppInstance.deviceId = `${deviceId}`; testAppInstance.releaseId = `V001${timeOffset}`; 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}`; yield edgeAppInstanceClient.PostAppInstanceConfigurations(testConfigurations); })); 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* () { edgeAppInstanceClient.should.not.be.undefined; edgeAppInstanceClient.GetGateway().should.be.equal(auth.gateway); (yield edgeAppInstanceClient.GetToken()).length.should.be.greaterThan(200); (yield edgeAppInstanceClient.GetToken()).length.should.be.greaterThan(200); })); it("should GET all app instances by deviceId @sanity", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; const apps = yield edgeAppInstanceClient.GetAppInstances(deviceId); apps.should.not.be.undefined; apps.should.not.be.null; apps.page.number.should.equal(0); apps.page.size.should.equal(10); apps.content.length.should.be.gte(0); })); it("should GET all app instances by deviceId (with size param)", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; const apps = yield edgeAppInstanceClient.GetAppInstances(deviceId, 100, 0, "ASC"); apps.should.not.be.undefined; apps.should.not.be.null; apps.page.number.should.equal(0); apps.page.size.should.equal(100); apps.content.length.should.be.gte(0); })); it("should GET the deployement status of the application instance by id", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; const status = yield edgeAppInstanceClient.GetAppInstanceLifecycle(appInstanceId); status.should.not.be.undefined; status.should.not.be.null; status.id.should.not.be.undefined; status.id.should.not.be.null; status.status.should.not.be.undefined; status.status.should.not.be.null; })); it("should POST a new app instance for the given device id", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; // Add new device testAppInstance.name = `testAppInst_${tenant}_${timeOffset}_A`; testAppInstance.appInstanceId = `testAppInst_${tenant}_${timeOffset}_A`; testAppInstance.applicationId = `testApp_${tenant}_${timeOffset}_A`; testAppInstance.deviceId = `${deviceId}`; testAppInstance.releaseId = `V001${timeOffset}`; const appInstRes = yield edgeAppInstanceClient.PostAppInstance(testAppInstance); appInstRes.should.not.be.undefined; appInstRes.should.not.be.null; appInstRes.id.should.not.be.undefined; appInstRes.id.should.not.be.null; appInstRes.name.should.not.be.undefined; appInstRes.name.should.not.be.null; appInstRes.releaseId.should.not.be.undefined; appInstRes.releaseId.should.not.be.null; appInstRes.applicationId.should.not.be.undefined; appInstRes.applicationId.should.not.be.null; const _appInstanceId = appInstRes.id; // Delete App yield edgeAppInstanceClient.DeleteAppInstance(_appInstanceId); })); it("should DELETE an app instance", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; // Create a new app instance testAppInstance.name = `testAppInst_${tenant}_${timeOffset}_B`; testAppInstance.appInstanceId = `testAppInst_${tenant}_${timeOffset}_B`; testAppInstance.applicationId = `testApp_${tenant}_${timeOffset}_B`; testAppInstance.deviceId = `${deviceId}`; testAppInstance.releaseId = `V001${timeOffset}`; const appInstRes = yield edgeAppInstanceClient.PostAppInstance(testAppInstance); appInstRes.should.not.be.undefined; appInstRes.should.not.be.null; const _appInstanceId = appInstRes.id; // Delete App yield edgeAppInstanceClient.DeleteAppInstance(_appInstanceId); })); it("should PATCH Status of Application Release Instance", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; // Create a new instance testAppInstance.name = `testAppInst_${tenant}_${timeOffset}_C`; testAppInstance.appInstanceId = `testAppInst_${tenant}_${timeOffset}_C`; testAppInstance.applicationId = `testApp_${tenant}_${timeOffset}_C`; testAppInstance.deviceId = `${deviceId}`; testAppInstance.releaseId = `V001${timeOffset}`; const appInstRes = yield edgeAppInstanceClient.PostAppInstance(testAppInstance); appInstRes.should.not.be.undefined; appInstRes.should.not.be.null; const _appInstanceId = appInstRes.id; const testStatus = { status: open_edge_models_1.EdgeAppInstanceModels.ApplicationInstanceLifeCycleStatus.StatusEnum.STOPPED, }; const _status = yield edgeAppInstanceClient.PatchAppInstanceStatus(_appInstanceId, testStatus); _status.should.not.be.undefined; _status.should.not.be.null; _status.status.should.equal(open_edge_models_1.EdgeAppInstanceModels.ApplicationInstanceLifeCycleStatus.StatusEnum.STOPPED); // Delete App yield edgeAppInstanceClient.DeleteAppInstance(_appInstanceId); })); it("should GET all application configurations by device id @sanity", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; const configurations = yield edgeAppInstanceClient.GetAppInstanceConfigurations(deviceId); configurations.should.not.be.undefined; configurations.should.not.be.null; configurations.page.number.should.equal(0); configurations.page.size.should.equal(10); configurations.content.length.should.be.gte(0); })); it("should GET all app instance configurations by deviceId (with size param)", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; const configurations = yield edgeAppInstanceClient.GetAppInstanceConfigurations(deviceId, 10, 0, "ASC"); configurations.should.not.be.undefined; configurations.should.not.be.null; configurations.page.number.should.equal(0); configurations.page.size.should.equal(10); configurations.content.length.should.be.gte(0); })); it("should GET an instance configuration by id", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; // console.log(deviceId); // console.log(deviceTypeId); // console.log(appInstanceId); const all = yield edgeAppInstanceClient.GetAppInstanceConfigurations(deviceId); // console.log(all); const configuration = yield edgeAppInstanceClient.GetAppInstanceConfiguration(appInstanceId); configuration.should.not.be.undefined; configuration.should.not.be.null; configuration.deviceId.should.not.be.undefined; configuration.deviceId.should.not.be.null; configuration.appId.should.not.be.undefined; configuration.appId.should.not.be.null; configuration.appReleaseId.should.not.be.undefined; configuration.appReleaseId.should.not.be.null; configuration.appInstanceId.should.not.be.undefined; configuration.appInstanceId.should.not.be.null; })); it("should POST a new app instance configuration for the given device id and application instance id", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; // Delete App inst configuration yield edgeAppInstanceClient.DeleteAppInstanceConfiguration(appInstanceId); // Add new configuration testConfigurations.deviceId = `${deviceId}`; testConfigurations.appId = `${appId}`; testConfigurations.appInstanceId = `${appInstanceId}`; testConfigurations.appReleaseId = `${appReleaseId}`; testConfigurations.configuration = { sampleKey1: "sampleValue1_A", sampleKey2: "sampleValue2_A", }; const instConfRes = yield edgeAppInstanceClient.PostAppInstanceConfigurations(testConfigurations); instConfRes.should.not.be.undefined; instConfRes.should.not.be.null; instConfRes.deviceId.should.not.be.undefined; instConfRes.deviceId.should.not.be.null; instConfRes.appId.should.not.be.undefined; instConfRes.appId.should.not.be.null; instConfRes.appReleaseId.should.not.be.undefined; instConfRes.appReleaseId.should.not.be.null; instConfRes.appInstanceId.should.not.be.undefined; instConfRes.appInstanceId.should.not.be.null; })); it("should PATCH specified instance configuration", () => __awaiter(void 0, void 0, void 0, function* () { edgeAppInstanceClient.should.not.be.undefined; testConfigurations.deviceId = `${deviceId}`; testConfigurations.appId = `${appId}`; testConfigurations.appInstanceId = `${appInstanceId}`; testConfigurations.appReleaseId = `${appReleaseId}`; testConfigurations.configuration = { sampleKey1: `sampleValue1_B_${timeOffset}`, sampleKey2: `sampleValue2_B_${timeOffset}`, }; const instConfRes = yield edgeAppInstanceClient.PatchAppInstanceConfigurationData(appInstanceId, testConfigurations); instConfRes.should.not.be.undefined; instConfRes.should.not.be.null; instConfRes.deviceId.should.not.be.undefined; instConfRes.deviceId.should.not.be.null; instConfRes.appId.should.not.be.undefined; instConfRes.appId.should.not.be.null; instConfRes.appReleaseId.should.not.be.undefined; instConfRes.appReleaseId.should.not.be.null; instConfRes.appInstanceId.should.not.be.undefined; instConfRes.appInstanceId.should.not.be.null; })); /* it("should PATCH all instance configurations", async () => { edgeAppInstanceClient.should.not.be.undefined; const testAllConfigurations = { instanceConfigurations: [ { id: "Config01", configuration: { sampleKey1: `sampleValue1_C_1_${timeOffset}`, sampleKey2: `sampleValue2_C_1_${timeOffset}` } } ] }; await edgeAppInstanceClient.PatchAppInstanceConfigurations(testAllConfigurations); }); */ it("should DELETE an app instance configuration", () => __awaiter(void 0, void 0, void 0, function* () { // Delete App inst configuration yield edgeAppInstanceClient.DeleteAppInstanceConfiguration(appInstanceId); })); }); //# sourceMappingURL=oe-app-inst-management.spec.js.map