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)

129 lines 5.93 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"); const sdk_1 = require("../src/api/sdk"); const utils_1 = require("../src/api/utils"); const test_utils_1 = require("./test-utils"); chai.should(); const timeOffset = new Date().getTime(); describe("[SDK] AgentManagementClient", () => { const auth = (0, utils_1.loadAuth)(); const sdk = new sdk_1.MindSphereSdk(Object.assign(Object.assign({}, auth), { basicAuth: (0, utils_1.decrypt)(auth, (0, test_utils_1.getPasskeyForUnitTest)()) })); const assetMgmt = sdk.GetAssetManagementClient(); const agentMgmt = sdk.GetAgentManagementClient(); let testAssetId, testAgentId; const testAgent = { name: "", securityProfile: sdk_1.AgentManagementModels.AgentUpdate.SecurityProfileEnum.SHAREDSECRET, entityId: "", }; // const test asset : const testAsset = { name: `UnitTestShip_${timeOffset}`, externalId: "SN 123456-123-123456", description: "The ship of Han Solo and Chewbacca", location: { country: "Austria", region: "Tyrol", locality: "Innsbruck", streetAddress: "Industriestraße 21 A/II", postalCode: "6020", longitude: 53.5125546, latitude: 9.9763411, }, variables: [], aspects: [], fileAssignments: [], typeId: `core.mclib`, timezone: "Europe/Berlin", twinType: sdk_1.AssetManagementModels.TwinType.Performance, }; before(() => __awaiter(void 0, void 0, void 0, function* () { testAsset.parentId = (yield assetMgmt.GetRootAsset()).assetId; const result = yield assetMgmt.PostAsset(testAsset); testAssetId = `${result.assetId}`; testAgent.name = testAgent.entityId = testAssetId; const agent = yield agentMgmt.PostAgent(testAgent); testAgentId = `${agent.id}`; })); after(() => __awaiter(void 0, void 0, void 0, function* () { yield deleteAgents(); })); 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* () { agentMgmt.should.not.be.undefined; agentMgmt.GetGateway().should.be.equal(auth.gateway); (yield agentMgmt.GetToken()).length.should.be.greaterThan(200); (yield agentMgmt.GetToken()).length.should.be.greaterThan(200); })); it("should GET agent(s)", () => __awaiter(void 0, void 0, void 0, function* () { agentMgmt.should.not.be.undefined; const agents = yield agentMgmt.GetAgents({ size: 10 }); agents.should.not.be.undefined; agents.should.not.be.null; agents.totalElements.should.be.greaterThan(0); agents.size.should.be.lessThan(11); })); it("should GET agent(s) with filter @sanity", () => __awaiter(void 0, void 0, void 0, function* () { agentMgmt.should.not.be.undefined; const agents = yield agentMgmt.GetAgents({ filter: JSON.stringify({ and: { id: { startsWith: testAgentId }, }, }), }); agents.should.not.be.undefined; agents.should.not.be.null; agents.totalElements.should.equal(1); })); it("should GET agent(s) with sorting", () => __awaiter(void 0, void 0, void 0, function* () { agentMgmt.should.not.be.undefined; const agents = yield agentMgmt.GetAgents({ filter: JSON.stringify({ and: { name: { startsWith: "1" }, id: { startsWith: "1" }, }, }), sort: "entityId,DESC", }); agents.should.not.be.undefined; agents.should.not.be.null; })); it("should GET specific agent ", () => __awaiter(void 0, void 0, void 0, function* () { agentMgmt.should.not.be.undefined; const agent = yield agentMgmt.GetAgent(testAssetId); agent.should.not.be.undefined; })); it("should PUT specific agent ", () => __awaiter(void 0, void 0, void 0, function* () { const agent = yield agentMgmt.GetAgent(testAgentId); agent.securityProfile = sdk_1.AgentManagementModels.AgentUpdate.SecurityProfileEnum.SHAREDSECRET; const { securityProfile } = agent; const newName = `UnitTest${new Date().getTime()}`; const patchedAgent = yield agentMgmt.PutAgent(testAgentId, { name: newName, securityProfile }, { ifMatch: `${agent.eTag}` }); patchedAgent.name.should.equal(newName); patchedAgent.securityProfile.should.equal("SHARED_SECRET"); })); function deleteAgents() { return __awaiter(this, void 0, void 0, function* () { if (testAgentId) { const agent = yield agentMgmt.GetAgent(testAgentId); yield agentMgmt.DeleteAgent(testAgentId, { ifMatch: `${agent.eTag}` }); yield assetMgmt.DeleteAsset(testAssetId, { ifMatch: `0` }); } }); } }); //# sourceMappingURL=agent-management.spec.js.map