1 | "use strict";
|
2 | var __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 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const chai = require("chai");
|
13 | require("url-search-params-polyfill");
|
14 | const sdk_1 = require("../src/api/sdk");
|
15 | const utils_1 = require("../src/api/utils");
|
16 | const test_utils_1 = require("./test-utils");
|
17 | chai.should();
|
18 | const timeOffset = new Date().getTime();
|
19 | describe("[SDK] AssetManagementClient.AspectTypes", () => {
|
20 | const auth = utils_1.loadAuth();
|
21 | const sdk = new sdk_1.MindSphereSdk({
|
22 | basicAuth: utils_1.decrypt(auth, "passkey.4.unit.test"),
|
23 | tenant: auth.tenant,
|
24 | gateway: auth.gateway
|
25 | });
|
26 | const am = sdk.GetAssetManagementClient();
|
27 | const tenant = sdk.GetTenant();
|
28 | const testAspectType = {
|
29 | name: "UnitTestEngine",
|
30 | category: sdk_1.AssetManagementModels.AspectResource.CategoryEnum.Static,
|
31 | scope: sdk_1.AssetManagementModels.AspectType.ScopeEnum.Private,
|
32 | description: "The engine of the Millenium Falcon",
|
33 | variables: [
|
34 | {
|
35 | name: "temperature",
|
36 | dataType: sdk_1.AssetManagementModels.VariableDefinition.DataTypeEnum.STRING,
|
37 | unit: "C/F",
|
38 | searchable: true,
|
39 | length: 5,
|
40 | defaultValue: "25/77",
|
41 | qualityCode: true
|
42 | }
|
43 | ]
|
44 | };
|
45 | before(() => __awaiter(void 0, void 0, void 0, function* () {
|
46 | yield test_utils_1.sleep(2000);
|
47 | yield deleteAspectTypes(am, tenant);
|
48 | testAspectType.name = `UnitTestEngine_${timeOffset}_A`;
|
49 | yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_A`, testAspectType);
|
50 | testAspectType.name = `UnitTestEngine_${timeOffset}_B`;
|
51 | yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_B`, testAspectType);
|
52 | testAspectType.name = `UnitTestEngine_${timeOffset}_C`;
|
53 | yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_C`, testAspectType);
|
54 | }));
|
55 | after(() => __awaiter(void 0, void 0, void 0, function* () {
|
56 | yield test_utils_1.sleep(2000);
|
57 | yield deleteAspectTypes(am, tenant);
|
58 | }));
|
59 | it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () {
|
60 | sdk.should.not.be.undefined;
|
61 | }));
|
62 | it("standard properties shoud be defined", () => __awaiter(void 0, void 0, void 0, function* () {
|
63 | am.should.not.be.undefined;
|
64 | am.GetGateway().should.be.equal(auth.gateway);
|
65 | (yield am.GetToken()).length.should.be.greaterThan(200);
|
66 | (yield am.GetServiceToken()).length.should.be.greaterThan(200);
|
67 | }));
|
68 | it("should GET aspecttypes", () => __awaiter(void 0, void 0, void 0, function* () {
|
69 | am.should.not.be.undefined;
|
70 | const aspectTypes = yield am.GetAspectTypes();
|
71 | aspectTypes.should.not.be.undefined;
|
72 | aspectTypes.should.not.be.null;
|
73 | aspectTypes.page.number.should.equal(0);
|
74 | aspectTypes.page.size.should.equal(10);
|
75 | aspectTypes._embedded.aspectTypes.length.should.be.equal(10);
|
76 | }));
|
77 | it("should GET aspecttypes with filter", () => __awaiter(void 0, void 0, void 0, function* () {
|
78 | am.should.not.be.undefined;
|
79 | const aspectTypes = yield am.GetAspectTypes({
|
80 | filter: JSON.stringify({
|
81 | id: {
|
82 | startsWith: `${tenant}`
|
83 | }
|
84 | })
|
85 | });
|
86 | aspectTypes.should.not.be.undefined;
|
87 | aspectTypes.should.not.be.null;
|
88 | aspectTypes._embedded || utils_1.throwError("there have to be some aspecttypes with that filter!");
|
89 | aspectTypes._embedded.aspectTypes.length.should.be.equal(10);
|
90 | }));
|
91 | it("should GET aspecttypes with sorting", () => __awaiter(void 0, void 0, void 0, function* () {
|
92 | am.should.not.be.undefined;
|
93 | const aspectTypes = yield am.GetAspectTypes({
|
94 | filter: JSON.stringify({
|
95 | and: {
|
96 | id: {
|
97 | startsWith: `${tenant}`
|
98 | },
|
99 | name: {
|
100 | startsWith: `UnitTestEngine_${timeOffset}`
|
101 | }
|
102 | }
|
103 | }),
|
104 | sort: "DESC",
|
105 | page: 0,
|
106 | size: 0
|
107 | });
|
108 | aspectTypes.should.not.be.undefined;
|
109 | aspectTypes.should.not.be.null;
|
110 | aspectTypes._embedded || utils_1.throwError("there have to be some aspecttypes with that filter!");
|
111 | aspectTypes._embedded.aspectTypes.length.should.be.greaterThan(0);
|
112 | }));
|
113 | it("should GET specific aspect type ", () => __awaiter(void 0, void 0, void 0, function* () {
|
114 | am.should.not.be.undefined;
|
115 | const aspectType = yield am.GetAspectType(`${tenant}.UnitTestEngine_${timeOffset}_A`);
|
116 | aspectType.should.not.be.null;
|
117 | }));
|
118 | it("should PUT specific aspect type ", () => __awaiter(void 0, void 0, void 0, function* () {
|
119 | am.should.not.be.undefined;
|
120 | testAspectType.name = `UnitTestEngine_${timeOffset}_D`;
|
121 | const aspectType = yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_D`, testAspectType);
|
122 | aspectType.should.not.be.null;
|
123 | yield am.DeleteAspectType(`${tenant}.UnitTestEngine_${timeOffset}_D`, { ifMatch: `${aspectType.etag}` });
|
124 | }));
|
125 | it("should PATCH specific aspect type ", () => __awaiter(void 0, void 0, void 0, function* () {
|
126 | am.should.not.be.undefined;
|
127 | testAspectType.name = `UnitTestEngine_${timeOffset}_D`;
|
128 | const aspectType = yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_D`, testAspectType);
|
129 | aspectType.variables.push({
|
130 | dataType: sdk_1.AssetManagementModels.VariableDefinition.DataTypeEnum.BOOLEAN,
|
131 | name: "test"
|
132 | });
|
133 | const patchedAspectType = yield am.PatchAspectType(`${tenant}.UnitTestEngine_${timeOffset}_D`, aspectType, {
|
134 | ifMatch: `${aspectType.etag}`
|
135 | });
|
136 | patchedAspectType.should.not.be.null;
|
137 | patchedAspectType.variables.length.should.be.equal(2);
|
138 | yield am.DeleteAspectType(`${tenant}.UnitTestEngine_${timeOffset}_D`, { ifMatch: `${patchedAspectType.etag}` });
|
139 | }));
|
140 | it("should DELETE specific aspect type ", () => __awaiter(void 0, void 0, void 0, function* () {
|
141 | am.should.not.be.undefined;
|
142 | testAspectType.name = `UnitTestEngine_${timeOffset}_E`;
|
143 | const aspectType = yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_E`, testAspectType);
|
144 | yield am.DeleteAspectType(`${tenant}.UnitTestEngine_${timeOffset}_E`, { ifMatch: `${aspectType.etag}` });
|
145 | }));
|
146 | });
|
147 | function deleteAspectTypes(am, tenant) {
|
148 | return __awaiter(this, void 0, void 0, function* () {
|
149 | const aspectTypes = (yield am.GetAspectTypes({
|
150 | filter: JSON.stringify({
|
151 | and: {
|
152 | id: {
|
153 | startsWith: `${tenant}`
|
154 | },
|
155 | name: {
|
156 | startsWith: `UnitTestEngine_${timeOffset}`
|
157 | }
|
158 | }
|
159 | }),
|
160 | sort: "DESC",
|
161 | page: 0,
|
162 | size: 0
|
163 | }));
|
164 | for (const x of aspectTypes._embedded.aspectTypes) {
|
165 | yield am.DeleteAspectType(x.id, { ifMatch: x.etag });
|
166 | }
|
167 | });
|
168 | }
|
169 |
|
\ | No newline at end of file |