UNPKG

@mindconnect/mindconnect-nodejs

Version:

NodeJS Library for MindSphere Connectivity - TypeScript SDK for MindSphere - MindSphere Command Line Interface - MindSphere Development Proxy

134 lines 5.77 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 command_utils_1 = require("../src/cli/commands/command-utils"); const test_utils_1 = require("./test-utils"); chai.should(); describe("[SDK] SignalCalculationClient", () => { 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 signalCalculationClient = sdk.GetSignalCalculationClient(); it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () { sdk.should.not.be.undefined; signalCalculationClient.should.not.be.undefined; })); it("should calculate sin(Acceleration) on test data. @sanity", () => __awaiter(void 0, void 0, void 0, function* () { sdk.should.not.be.undefined; signalCalculationClient.should.not.be.undefined; const generatedData = (0, command_utils_1.generateTestData)(10, (x) => { return x; }, "Acceleration", "number"); const checkData = (0, command_utils_1.generateTestData)(10, (x) => { return Math.sin(x); }, "Acceleration", "number"); const input = { configuration: { operation: "SIN", operands: [ { entityId: "assetid", propertySetName: "Vibration", propertyName: "Acceleration", }, ], result: { entityId: "assetid", propertySetName: "Vibration", propertyName: "Acceleration", }, }, data: [ { entityId: "assetid", propertySetName: "Vibration", timeSeries: generatedData, }, ], }; const result = yield signalCalculationClient.PostApplyOperation(input); for (let index = 0; index < result.timeSeries.length; index++) { const element = result.timeSeries[index]; element.Acceleration.should.be.equal(checkData[index].Acceleration); } })); it("should generate new data. @sanity", () => __awaiter(void 0, void 0, void 0, function* () { sdk.should.not.be.undefined; signalCalculationClient.should.not.be.undefined; const generatedData = (0, command_utils_1.generateTestData)(10, (x) => { return Math.cos(x); }, "Acceleration", "number"); const input = { configuration: { operation: "GENERATOR", params: { generatorType: "TEMPORAL", timePeriodInSeconds: 60, numberOfEvents: 2 }, operands: [ { entityId: "assetid", propertySetName: "Vibration", propertyName: "Acceleration", }, ], result: { entityId: "assetid", propertySetName: "Vibration", propertyName: "Acceleration", }, }, data: [ { entityId: "assetid", propertySetName: "Vibration", timeSeries: generatedData, }, ], }; const result = yield signalCalculationClient.PostApplyOperation(input); result.timeSeries.length.should.equal(20); })); it("should check if a date is a weekend", () => __awaiter(void 0, void 0, void 0, function* () { sdk.should.not.be.undefined; signalCalculationClient.should.not.be.undefined; const generatedData = (0, command_utils_1.generateTestData)(10, (x) => { return Math.cos(x); }, "Acceleration", "number"); const input = { configuration: { operation: "IS_WEEKEND", operands: [ { entityId: "assetid", propertySetName: "Vibration", propertyName: "_time", }, ], result: { entityId: "assetid", propertySetName: "Schedule", propertyName: "IsWeekend", }, }, data: [ { entityId: "assetid", propertySetName: "Vibration", timeSeries: generatedData, }, ], }; const result = yield signalCalculationClient.PostApplyOperation(input); result.timeSeries.length.should.equal(10); })); }); //# sourceMappingURL=signal-calculation.spec.js.map