UNPKG

@mindconnect/mindconnect-nodejs

Version:

MindConnect Library for NodeJS (community based)

64 lines 3.46 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 sdk_1 = require("../src/api/sdk"); const utils_1 = require("../src/api/utils"); const test_agent_setup_utils_1 = require("./test-agent-setup-utils"); describe("IotTsAggregateClient", () => { const auth = utils_1.loadAuth(); const gateway = process.env.GATEWAY || auth.gateway; const tenant = process.env.TENANT || auth.tenant; const basicAuth = process.env.BASICAUTH || utils_1.decrypt(auth, "passkey.4.unit.test"); const sdk = new sdk_1.MindSphereSdk({ gateway, tenant, basicAuth }); let assetid = ""; before(() => __awaiter(void 0, void 0, void 0, function* () { const unitTestStructure = yield test_agent_setup_utils_1.setupStructure(sdk); assetid = `${unitTestStructure.targetAsset.assetId}`; })); it("should instantiate", () => __awaiter(void 0, void 0, void 0, function* () { const aggregateClient = sdk.GetTimeSeriesAggregateClient(); aggregateClient.should.exist; })); it("should renew token", () => __awaiter(void 0, void 0, void 0, function* () { const aggregateClient = sdk.GetTimeSeriesAggregateClient(); aggregateClient.should.exist; const result = yield aggregateClient.RenewToken(); result.should.be.true; const token = yield aggregateClient.GetToken(); token.should.exist; token.length.should.be.gte(100); })); it("should get aggregates per hour of the last 7 days using the test asset", () => __awaiter(void 0, void 0, void 0, function* () { const aggregateClient = sdk.GetTimeSeriesAggregateClient(); assetid.should.not.be.undefined; assetid.should.not.be.equal(""); utils_1.checkAssetId(assetid); const now = new Date(); const lastMonth = new Date(); lastMonth.setDate(lastMonth.getDate() - 7); const fromLastMonth = new Date(lastMonth.getUTCFullYear(), lastMonth.getUTCMonth(), lastMonth.getUTCDate()); const toNow = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()); const aggregates = yield aggregateClient.GetAggregates(assetid, "VibrationData", { from: fromLastMonth, to: toNow, intervalUnit: "hour", intervalValue: 1 }); aggregates.should.not.be.undefined; aggregates.should.not.be.null; for (const obj of Object.keys(aggregates)) { const currentAggregate = aggregates[obj]; currentAggregate.starttime.should.not.be.undefined; currentAggregate.endtime.should.not.be.undefined; } })); }); //# sourceMappingURL=iot-ts-aggregates.spec.js.map