UNPKG

6.02 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const chai = require("chai");
13const sdk_1 = require("../src/api/sdk");
14const utils_1 = require("../src/api/utils");
15chai.should();
16const timeOffset = new Date().getTime();
17describe("[SDK] AgentManagementClient", () => {
18 const auth = utils_1.loadAuth();
19 const sdk = new sdk_1.MindSphereSdk({
20 basicAuth: utils_1.decrypt(auth, "passkey.4.unit.test"),
21 tenant: auth.tenant,
22 gateway: auth.gateway
23 });
24 const assetMgmt = sdk.GetAssetManagementClient();
25 const agentMgmt = sdk.GetAgentManagementClient();
26 let testAssetId, testAgentId;
27 const testAgent = {
28 name: "",
29 securityProfile: sdk_1.AgentManagementModels.AgentUpdate.SecurityProfileEnum.SHAREDSECRET,
30 entityId: ""
31 };
32 // const test asset :
33 const testAsset = {
34 name: `UnitTestShip_${timeOffset}`,
35 externalId: "SN 123456-123-123456",
36 description: "The ship of Han Solo and Chewbacca",
37 location: {
38 country: "Austria",
39 region: "Tyrol",
40 locality: "Innsbruck",
41 streetAddress: "Industriestraße 21 A/II",
42 postalCode: "6020",
43 longitude: 53.5125546,
44 latitude: 9.9763411
45 },
46 variables: [],
47 aspects: [],
48 fileAssignments: [],
49 typeId: `core.mclib`,
50 timezone: "Europe/Berlin",
51 twinType: sdk_1.AssetManagementModels.TwinType.Performance
52 };
53 before(() => __awaiter(void 0, void 0, void 0, function* () {
54 testAsset.parentId = (yield assetMgmt.GetRootAsset()).assetId;
55 const result = yield assetMgmt.PostAsset(testAsset);
56 testAssetId = `${result.assetId}`;
57 testAgent.name = testAgent.entityId = testAssetId;
58 const agent = yield agentMgmt.PostAgent(testAgent);
59 testAgentId = `${agent.id}`;
60 }));
61 after(() => __awaiter(void 0, void 0, void 0, function* () {
62 yield deleteAgents();
63 }));
64 it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () {
65 sdk.should.not.be.undefined;
66 }));
67 it("standard properties shoud be defined", () => __awaiter(void 0, void 0, void 0, function* () {
68 agentMgmt.should.not.be.undefined;
69 agentMgmt.GetGateway().should.be.equal(auth.gateway);
70 (yield agentMgmt.GetToken()).length.should.be.greaterThan(200);
71 (yield agentMgmt.GetServiceToken()).length.should.be.greaterThan(200);
72 }));
73 it("should GET agent(s)", () => __awaiter(void 0, void 0, void 0, function* () {
74 agentMgmt.should.not.be.undefined;
75 const agents = yield agentMgmt.GetAgents({ size: 10 });
76 agents.should.not.be.undefined;
77 agents.should.not.be.null;
78 agents.totalElements.should.be.greaterThan(0);
79 agents.size.should.be.lessThan(11);
80 }));
81 it("should GET agent(s) with filter", () => __awaiter(void 0, void 0, void 0, function* () {
82 agentMgmt.should.not.be.undefined;
83 const agents = yield agentMgmt.GetAgents({
84 filter: JSON.stringify({
85 and: {
86 id: { startsWith: testAgentId }
87 }
88 })
89 });
90 agents.should.not.be.undefined;
91 agents.should.not.be.null;
92 agents.totalElements.should.equal(1);
93 }));
94 it("should GET agent(s) with sorting", () => __awaiter(void 0, void 0, void 0, function* () {
95 agentMgmt.should.not.be.undefined;
96 const agents = yield agentMgmt.GetAgents({
97 filter: JSON.stringify({
98 and: {
99 name: { startsWith: "1" },
100 id: { startsWith: "1" }
101 }
102 }),
103 sort: "entityId,DESC"
104 });
105 agents.should.not.be.undefined;
106 agents.should.not.be.null;
107 }));
108 it("should GET specific agent ", () => __awaiter(void 0, void 0, void 0, function* () {
109 agentMgmt.should.not.be.undefined;
110 const agent = yield agentMgmt.GetAgent(testAssetId);
111 agent.should.not.be.undefined;
112 }));
113 it("should PUT specific agent ", () => __awaiter(void 0, void 0, void 0, function* () {
114 const agent = yield agentMgmt.GetAgent(testAgentId);
115 agent.securityProfile =
116 sdk_1.AgentManagementModels.AgentUpdate.SecurityProfileEnum.SHAREDSECRET;
117 const { securityProfile } = agent;
118 const newName = `UnitTest${new Date().getTime()}`;
119 const patchedAgent = yield agentMgmt.PutAgent(testAgentId, { name: newName, securityProfile }, { ifMatch: `${agent.eTag}` });
120 patchedAgent.name.should.equal(newName);
121 patchedAgent.securityProfile.should.equal("SHARED_SECRET");
122 }));
123 function deleteAgents() {
124 return __awaiter(this, void 0, void 0, function* () {
125 if (testAgentId) {
126 const agent = yield agentMgmt.GetAgent(testAgentId);
127 yield agentMgmt.DeleteAgent(testAgentId, { ifMatch: `${agent.eTag}` });
128 yield assetMgmt.DeleteAsset(testAssetId, { ifMatch: `0` });
129 }
130 });
131 }
132});
133//# sourceMappingURL=agent-management.spec.js.map
\No newline at end of file