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)

165 lines 8.03 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 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] AssetManagementClient.AspectTypes", () => { 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 am = sdk.GetAssetManagementClient(); const tenant = sdk.GetTenant(); const testAspectType = { name: "UnitTestEngine", category: sdk_1.AssetManagementModels.AspectResource.CategoryEnum.Static, scope: sdk_1.AssetManagementModels.AspectType.ScopeEnum.Private, description: "The engine of the Millenium Falcon", variables: [ { name: "temperature", dataType: sdk_1.AssetManagementModels.VariableDefinition.DataTypeEnum.STRING, unit: "C/F", searchable: true, length: 5, defaultValue: "25/77", qualityCode: true, }, ], }; before(() => __awaiter(void 0, void 0, void 0, function* () { yield (0, test_utils_1.sleep)(2000); yield deleteAspectTypes(am, tenant); testAspectType.name = `UnitTestEngine_${timeOffset}_A`; yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_A`, testAspectType); testAspectType.name = `UnitTestEngine_${timeOffset}_B`; yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_B`, testAspectType); testAspectType.name = `UnitTestEngine_${timeOffset}_C`; yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_C`, testAspectType); })); after(() => __awaiter(void 0, void 0, void 0, function* () { yield (0, test_utils_1.sleep)(2000); yield deleteAspectTypes(am, tenant); })); 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* () { am.should.not.be.undefined; am.GetGateway().should.be.equal(auth.gateway); (yield am.GetToken()).length.should.be.greaterThan(200); (yield am.GetToken()).length.should.be.greaterThan(200); })); it("should GET aspecttypes @sanity", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const aspectTypes = yield am.GetAspectTypes(); aspectTypes.should.not.be.undefined; aspectTypes.should.not.be.null; aspectTypes.page.number.should.equal(0); aspectTypes.page.size.should.equal(10); aspectTypes._embedded.aspectTypes.length.should.be.equal(10); })); it("should GET aspecttypes with filter", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const aspectTypes = yield am.GetAspectTypes({ filter: JSON.stringify({ id: { startsWith: `${tenant}`, }, }), }); aspectTypes.should.not.be.undefined; aspectTypes.should.not.be.null; aspectTypes._embedded || (0, utils_1.throwError)("there have to be some aspecttypes with that filter!"); aspectTypes._embedded.aspectTypes.length.should.be.equal(10); })); it("should GET aspecttypes with sorting", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const aspectTypes = yield am.GetAspectTypes({ filter: JSON.stringify({ and: { id: { startsWith: `${tenant}`, }, name: { startsWith: `UnitTestEngine_${timeOffset}`, }, }, }), sort: "DESC", page: 0, size: 0, }); aspectTypes.should.not.be.undefined; aspectTypes.should.not.be.null; aspectTypes._embedded || (0, utils_1.throwError)("there have to be some aspecttypes with that filter!"); aspectTypes._embedded.aspectTypes.length.should.be.greaterThan(0); })); it("should GET specific aspect type ", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const aspectType = yield am.GetAspectType(`${tenant}.UnitTestEngine_${timeOffset}_A`); aspectType.should.not.be.null; })); it("should PUT specific aspect type ", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; testAspectType.name = `UnitTestEngine_${timeOffset}_D`; const aspectType = yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_D`, testAspectType); aspectType.should.not.be.null; yield am.DeleteAspectType(`${tenant}.UnitTestEngine_${timeOffset}_D`, { ifMatch: `${aspectType.etag}` }); })); it("should PATCH specific aspect type ", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; testAspectType.name = `UnitTestEngine_${timeOffset}_D`; const aspectType = yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_D`, testAspectType); aspectType.variables.push({ dataType: sdk_1.AssetManagementModels.VariableDefinition.DataTypeEnum.BOOLEAN, name: "test", }); const patchedAspectType = yield am.PatchAspectType(`${tenant}.UnitTestEngine_${timeOffset}_D`, aspectType, { ifMatch: `${aspectType.etag}`, }); patchedAspectType.should.not.be.null; patchedAspectType.variables.length.should.be.equal(2); yield am.DeleteAspectType(`${tenant}.UnitTestEngine_${timeOffset}_D`, { ifMatch: `${patchedAspectType.etag}` }); })); it("should DELETE specific aspect type ", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; testAspectType.name = `UnitTestEngine_${timeOffset}_E`; const aspectType = yield am.PutAspectType(`${tenant}.UnitTestEngine_${timeOffset}_E`, testAspectType); yield am.DeleteAspectType(`${tenant}.UnitTestEngine_${timeOffset}_E`, { ifMatch: `${aspectType.etag}` }); })); }); function deleteAspectTypes(am, tenant) { return __awaiter(this, void 0, void 0, function* () { const aspectTypes = (yield am.GetAspectTypes({ filter: JSON.stringify({ and: { id: { startsWith: `${tenant}`, }, name: { startsWith: `UnitTestEngine_${timeOffset}`, }, }, }), sort: "DESC", page: 0, size: 0, })); for (const x of aspectTypes._embedded.aspectTypes) { yield am.DeleteAspectType(x.id, { ifMatch: x.etag }); } }); } //# sourceMappingURL=asset-management-aspecttypes.spec.js.map