UNPKG

@mindconnect/mindconnect-nodejs

Version:

MindConnect Library for NodeJS (community based)

220 lines 10.5 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.AssetTypes", () => { const auth = utils_1.loadAuth(); const sdk = new sdk_1.MindSphereSdk({ basicAuth: utils_1.decrypt(auth, "passkey.4.unit.test"), tenant: auth.tenant, gateway: auth.gateway }); const am = sdk.GetAssetManagementClient(); const tenant = sdk.GetTenant(); const testAssetType = { name: `SpaceShipType${timeOffset}`, description: "Hyperspace jump capable space ship", parentTypeId: `core.basicdevice`, instantiable: true, scope: sdk_1.AssetManagementModels.AssetTypeBase.ScopeEnum.Private, aspects: [], variables: [ { name: "temperature", dataType: sdk_1.AssetManagementModels.VariableDefinition.DataTypeEnum.STRING, unit: "C/F", searchable: true, length: 5, defaultValue: "25/77" } ], fileAssignments: [] }; before(() => __awaiter(void 0, void 0, void 0, function* () { testAssetType.name = `SpaceShipType_${timeOffset}_A`; yield am.PutAssetType(`${tenant}.SpaceShipType_${timeOffset}_A`, testAssetType); testAssetType.name = `SpaceShipType_${timeOffset}_B`; yield am.PutAssetType(`${tenant}.SpaceShipType_${timeOffset}_B`, testAssetType); testAssetType.name = `SpaceShipType_${timeOffset}_C`; yield am.PutAssetType(`${tenant}.SpaceShipType_${timeOffset}_C`, testAssetType); })); after(() => __awaiter(void 0, void 0, void 0, function* () { yield deleteAssetTypes(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.GetServiceToken()).length.should.be.greaterThan(200); })); it("should GET asset types", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const assetTypes = yield am.GetAssetTypes(); assetTypes.should.not.be.undefined; assetTypes.should.not.be.null; assetTypes.page.number.should.equal(0); assetTypes.page.size.should.equal(10); assetTypes._embedded.assetTypes.length.should.be.greaterThan(0); })); it("should GET asset types with filter", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const assetTypes = yield am.GetAssetTypes({ filter: JSON.stringify({ id: { startsWith: `${tenant}` } }) }); assetTypes.should.not.be.undefined; assetTypes.should.not.be.null; assetTypes._embedded || utils_1.throwError("there have to be some aspecttypes with that filter!"); assetTypes._embedded.assetTypes.length.should.be.greaterThan(0); })); it("should GET asset types with sorting", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const assetTypes = yield am.GetAssetTypes({ filter: JSON.stringify({ and: { id: { startsWith: `${tenant}` }, name: { startsWith: `SpaceShipType_${timeOffset}` } } }), sort: "DESC", page: 0, size: 0 }); assetTypes.should.not.be.undefined; assetTypes.should.not.be.null; assetTypes._embedded || utils_1.throwError("there have to be some aspecttypes with that filter!"); assetTypes._embedded.assetTypes.length.should.be.greaterThan(0); assetTypes._embedded.assetTypes[0].variables.length.should.be.equal(1); })); it("should GET exploded asset types", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const assetTypes = yield am.GetAssetTypes({ filter: JSON.stringify({ and: { id: { startsWith: `${tenant}` }, name: { startsWith: `SpaceShipType_${timeOffset}` } } }), exploded: true }); assetTypes.should.not.be.undefined; assetTypes.should.not.be.null; assetTypes._embedded || utils_1.throwError("there have to be some aspecttypes with that filter!"); assetTypes._embedded.assetTypes.length.should.be.equal(3); assetTypes._embedded.assetTypes[0].variables.length.should.be.equal(3); })); it("should GET specific asset type ", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const assetType = yield am.GetAssetType(`${tenant}.SpaceShipType_${timeOffset}_A`); assetType.variables.length.should.equal(1); const explodedFalse = yield am.GetAssetType(`${tenant}.SpaceShipType_${timeOffset}_A`, { exploded: false }); explodedFalse.variables.length.should.equal(1); const explodedAssetType = yield am.GetAssetType(`${tenant}.SpaceShipType_${timeOffset}_A`, { exploded: true }); explodedAssetType.variables.length.should.equal(3); assetType.should.not.be.null; })); it("should PUT specific asset type ", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; testAssetType.name = `SpaceShipType_${timeOffset}_D`; const assetType = yield am.PutAssetType(`${tenant}.SpaceShipType_${timeOffset}_D`, testAssetType); assetType.should.not.be.null; yield am.DeleteAssetType(`${tenant}.SpaceShipType_${timeOffset}_D`, { ifMatch: `${assetType.etag}` }); })); it("should PATCH specific asset type ", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; testAssetType.name = `SpaceShipType_${timeOffset}_D`; const assetType = yield am.PutAssetType(`${tenant}.SpaceShipType_${timeOffset}_D`, testAssetType); assetType.variables = assetType.variables || new Array(); assetType.variables.push({ dataType: sdk_1.AssetManagementModels.VariableDefinition.DataTypeEnum.BOOLEAN, name: "test" }); const patchedAssetType = yield am.PatchAssetType(`${tenant}.SpaceShipType_${timeOffset}_D`, assetType, { ifMatch: `${assetType.etag}` }); patchedAssetType.should.not.be.null; patchedAssetType.variables.length.should.be.equal(2); assetType.should.not.be.null; yield am.DeleteAssetType(`${tenant}.SpaceShipType_${timeOffset}_D`, { ifMatch: `${patchedAssetType.etag}` }); })); it("should DELETE specific asset type ", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; testAssetType.name = `SpaceShipType_${timeOffset}_F`; const assetType = yield am.PutAssetType(`${tenant}.SpaceShipType_${timeOffset}_F`, testAssetType); yield am.DeleteAssetType(`${tenant}.SpaceShipType_${timeOffset}_F`, { ifMatch: `${assetType.etag}` }); })); it("should throw error on Put File assignment ", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const assetType = yield am.GetAssetType(`${tenant}.SpaceShipType_${timeOffset}_A`); try { yield am.PutAssetTypeFileAssignment(`${assetType.id}`, "Keyword", { fileId: "abcd" }, { ifMatch: `${assetType.etag}` }); } catch (err) { err.message.should.contain("abcd"); } })); it("should throw error on Delete File assignment ", () => __awaiter(void 0, void 0, void 0, function* () { am.should.not.be.undefined; const assetType = yield am.GetAssetType(`${tenant}.SpaceShipType_${timeOffset}_A`); try { yield am.DeleteAssetTypeFileAssignment(`${assetType.id}`, "xyz", { ifMatch: "0" }); } catch (err) { err.message.should.contain("xyz"); } })); }); function deleteAssetTypes(am, tenant) { return __awaiter(this, void 0, void 0, function* () { yield test_utils_1.sleep(2000); const assetTypes = (yield am.GetAssetTypes({ filter: JSON.stringify({ and: { id: { startsWith: `${tenant}` }, name: { startsWith: `SpaceShipType_${timeOffset}` } } }), sort: "DESC", page: 0, size: 0 })); for (const x of assetTypes._embedded.assetTypes) { yield am.DeleteAssetType(x.id, { ifMatch: x.etag }); } }); } //# sourceMappingURL=asset-management-assetypes.spec.js.map