@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)
112 lines • 5.41 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 chai = require("chai");
const debug = require("debug");
require("url-search-params-polyfill");
const src_1 = require("../src");
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");
const log = debug("mindconnect-setup-test");
chai.should();
describe("[SDK] Diagnostic API tests", () => {
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 sharedSecretConfig = {};
let unitTestConfiguration = {};
before(() => __awaiter(void 0, void 0, void 0, function* () {
unitTestConfiguration = yield (0, test_agent_setup_utils_1.unitTestSetup)(sdk, sdk_1.AgentManagementModels.AgentUpdate.SecurityProfileEnum.SHAREDSECRET);
sharedSecretConfig = unitTestConfiguration.agentConfig;
}));
after(() => __awaiter(void 0, void 0, void 0, function* () {
yield (0, test_agent_setup_utils_1.tearDownAgents)(sdk, unitTestConfiguration);
}));
it("should instantiate", () => {
const mcApiClient = sdk.GetMindConnectApiClient();
log(mcApiClient);
mcApiClient.should.exist;
});
it("should register 2 agents for diagnostics", () => __awaiter(void 0, void 0, void 0, function* () {
if (!process.env.CI) {
// don't delete all diagnostic registrations all the time on the CI/CD this can disturb the normal workings on the tenants.
const mcApiClient = sdk.GetMindConnectApiClient();
mcApiClient.should.not.be.null;
yield mcApiClient.DeleteAllDiagnosticActivations();
try {
yield mcApiClient.PostDiagnosticActivation(sharedSecretConfig.content.clientId);
}
catch (err) {
if (("" + err).indexOf("agent limitation") < 0) {
throw err;
}
}
const activations = yield mcApiClient.GetDiagnosticActivations();
log(activations.content);
activations.content.length.should.be.equal(1);
yield mcApiClient.DeleteAllDiagnosticActivations();
}
}));
it("should get logs on error", () => __awaiter(void 0, void 0, void 0, function* () {
if (!process.env.CI) {
const mcApiClient = sdk.GetMindConnectApiClient();
mcApiClient.should.not.be.null;
const agent = new src_1.MindConnectAgent(sharedSecretConfig);
agent.should.exist;
yield mcApiClient.DeleteAllDiagnosticActivations();
try {
const response = yield mcApiClient.PostDiagnosticActivation(agent.ClientId());
}
catch (err) {
if (("" + err).indexOf("Conflict") < 0) {
throw err;
}
}
if (!agent.IsOnBoarded()) {
yield agent.OnBoard();
}
yield agent.PutDataSourceConfiguration({
configurationId: "Configuration01",
dataSources: [
{
name: "EnvironmentData",
description: "EnvironmentData (from environment sensors)",
dataPoints: [
{
id: "DP-Temperature",
name: "Temperature",
description: "Temperature",
type: src_1.DataPoint.TypeEnum.DOUBLE,
unit: "°C",
},
],
},
],
});
yield agent.PostData([
{
dataPointId: "Unexistent",
qualityCode: "123123135",
value: "12312346.42.23",
},
], undefined, false);
const diag = yield mcApiClient.GetDiagnosticActivationMessages(agent.ClientId());
diag.content.should.exist;
let activations = yield mcApiClient.GetDiagnosticActivations();
activations.content.length.should.be.greaterThan(0);
yield mcApiClient.DeleteDiagnosticActivation(agent.ClientId());
activations = yield mcApiClient.GetDiagnosticActivations();
activations.content.length.should.be.equal(0);
}
}));
});
//# sourceMappingURL=diagnostic.spec.js.map