1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const sdk_1 = require("../src/api/sdk");
|
13 | const utils_1 = require("../src/api/utils");
|
14 | const test_agent_setup_utils_1 = require("./test-agent-setup-utils");
|
15 | describe("IotTsAggregateClient", () => {
|
16 | const auth = utils_1.loadAuth();
|
17 | const gateway = process.env.GATEWAY || auth.gateway;
|
18 | const tenant = process.env.TENANT || auth.tenant;
|
19 | const basicAuth = process.env.BASICAUTH || utils_1.decrypt(auth, "passkey.4.unit.test");
|
20 | const sdk = new sdk_1.MindSphereSdk({ gateway, tenant, basicAuth });
|
21 | let assetid = "";
|
22 | before(() => __awaiter(void 0, void 0, void 0, function* () {
|
23 | const unitTestStructure = yield test_agent_setup_utils_1.setupStructure(sdk);
|
24 | assetid = `${unitTestStructure.targetAsset.assetId}`;
|
25 | }));
|
26 | it("should instantiate", () => __awaiter(void 0, void 0, void 0, function* () {
|
27 | const aggregateClient = sdk.GetTimeSeriesAggregateClient();
|
28 | aggregateClient.should.exist;
|
29 | }));
|
30 | it("should renew token", () => __awaiter(void 0, void 0, void 0, function* () {
|
31 | const aggregateClient = sdk.GetTimeSeriesAggregateClient();
|
32 | aggregateClient.should.exist;
|
33 | const result = yield aggregateClient.RenewToken();
|
34 | result.should.be.true;
|
35 | const token = yield aggregateClient.GetToken();
|
36 | token.should.exist;
|
37 | token.length.should.be.gte(100);
|
38 | }));
|
39 | it("should get aggregates per hour of the last 7 days using the test asset", () => __awaiter(void 0, void 0, void 0, function* () {
|
40 | const aggregateClient = sdk.GetTimeSeriesAggregateClient();
|
41 | assetid.should.not.be.undefined;
|
42 | assetid.should.not.be.equal("");
|
43 | utils_1.checkAssetId(assetid);
|
44 | const now = new Date();
|
45 | const lastMonth = new Date();
|
46 | lastMonth.setDate(lastMonth.getDate() - 7);
|
47 | const fromLastMonth = new Date(lastMonth.getUTCFullYear(), lastMonth.getUTCMonth(), lastMonth.getUTCDate());
|
48 | const toNow = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
49 | const aggregates = yield aggregateClient.GetAggregates(assetid, "VibrationData", {
|
50 | from: fromLastMonth,
|
51 | to: toNow,
|
52 | intervalUnit: "hour",
|
53 | intervalValue: 1
|
54 | });
|
55 | aggregates.should.not.be.undefined;
|
56 | aggregates.should.not.be.null;
|
57 | for (const obj of Object.keys(aggregates)) {
|
58 | const currentAggregate = aggregates[obj];
|
59 | currentAggregate.starttime.should.not.be.undefined;
|
60 | currentAggregate.endtime.should.not.be.undefined;
|
61 | }
|
62 | }));
|
63 | });
|
64 |
|
\ | No newline at end of file |