@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)
62 lines • 3.36 kB
JavaScript
;
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");
const test_utils_1 = require("./test-utils");
describe("[SDK] IotTsAggregateClient", () => {
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)()) }));
let assetid = "";
before(() => __awaiter(void 0, void 0, void 0, function* () {
const unitTestStructure = yield (0, 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 @sanity", () => __awaiter(void 0, void 0, void 0, function* () {
const aggregateClient = sdk.GetTimeSeriesAggregateClient();
assetid.should.not.be.undefined;
assetid.should.not.be.equal("");
(0, 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