@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)
142 lines • 7.2 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");
require("url-search-params-polyfill");
const src_1 = require("../src");
const utils_1 = require("../src/api/utils");
const test_device_setup_utils_1 = require("./test-device-setup-utils");
const test_utils_1 = require("./test-utils");
chai.should();
const timeOffset = new Date().getTime();
describe.skip("[SDK] DeviceManagementClient.Devices", () => {
const auth = (0, utils_1.loadAuth)();
const sdk = new src_1.MindSphereSdk(Object.assign(Object.assign({}, auth), { basicAuth: (0, utils_1.decrypt)(auth, (0, test_utils_1.getPasskeyForUnitTest)()) }));
const deviceManagementClient = sdk.GetDeviceManagementClient();
const assetMgmt = sdk.GetAssetManagementClient();
const tenant = sdk.GetTenant();
const testDevice = {
deviceTypeId: `${tenant}.UnitTestDeviceType`,
assetId: `myAssetId`,
serialNumber: `UnitTestserialNumber_A`,
agents: [],
properties: {
key1: "value1",
key2: "value2",
},
};
let deviceTypeId = "aee2e37f-f562-4ed6-b90a-c43208dc054a";
let assetTypeId = `${tenant}.UnitTestDeviceAssetType`;
let assetId = "";
let deviceId = "";
let gFolderid = "";
before(() => __awaiter(void 0, void 0, void 0, function* () {
// tear Down test infrastructure
yield (0, test_device_setup_utils_1.tearDownDeviceTestStructure)(sdk);
// Setup the testing architecture
const { device, deviceAsset, deviceType, deviceAssetType, folderid } = yield (0, test_device_setup_utils_1.setupDeviceTestStructure)(sdk);
assetTypeId = `${deviceAssetType.id}`;
deviceTypeId = `${deviceType.id}`;
assetId = `${deviceAsset.assetId}`;
deviceId = `${device.id}`;
gFolderid = `${folderid}`;
testDevice.deviceTypeId = `${deviceTypeId}`;
testDevice.assetId = `${assetId}`;
}));
after(() => __awaiter(void 0, void 0, void 0, function* () {
// tear Down test infrastructure
yield (0, test_device_setup_utils_1.tearDownDeviceTestStructure)(sdk);
}));
it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () {
sdk.should.not.be.undefined;
}));
it("standard properties shoud be defined", () => __awaiter(void 0, void 0, void 0, function* () {
deviceManagementClient.should.not.be.undefined;
deviceManagementClient.GetGateway().should.be.equal(auth.gateway);
(yield deviceManagementClient.GetToken()).length.should.be.greaterThan(200);
(yield deviceManagementClient.GetToken()).length.should.be.greaterThan(200);
}));
it("should GET devices @sanity", () => __awaiter(void 0, void 0, void 0, function* () {
deviceManagementClient.should.not.be.undefined;
const devices = yield deviceManagementClient.GetDevices({
assetId: `${assetId}`,
});
devices.should.not.be.undefined;
devices.should.not.be.null;
devices.page.number.should.equal(0);
devices.page.size.should.equal(10);
devices.content.length.should.be.gte(1);
}));
it("should GET devices with size", () => __awaiter(void 0, void 0, void 0, function* () {
deviceManagementClient.should.not.be.undefined;
const devices = yield deviceManagementClient.GetDevices({
assetId: `${assetId}`,
page: 0,
size: 5,
});
devices.should.not.be.undefined;
devices.should.not.be.null;
devices.content || (0, utils_1.throwError)("there have to be some devicetypes with that sort parameter!");
devices.content.length.should.be.greaterThan(0);
}));
it("should GET specific device", () => __awaiter(void 0, void 0, void 0, function* () {
deviceManagementClient.should.not.be.undefined;
const device = yield deviceManagementClient.GetDevice(deviceId);
device.should.not.be.null;
}));
it("should POST specific device @sanity", () => __awaiter(void 0, void 0, void 0, function* () {
deviceManagementClient.should.not.be.undefined;
// Add a new asset
const _asset = yield assetMgmt.PostAsset({
name: `${tenant}.UnitTestDeviceAsset.${timeOffset}`,
typeId: `${assetTypeId}`,
parentId: gFolderid,
});
// Add new device
testDevice.deviceTypeId = `${deviceTypeId}`;
testDevice.assetId = `${_asset.assetId}`;
testDevice.serialNumber = `UnitTestserialNumber_B`;
const device = yield deviceManagementClient.PostDevice(testDevice);
device.should.not.be.null;
device.serialNumber.should.be.string(`UnitTestserialNumber_B`);
yield deviceManagementClient.DeleteDevice(`${device.id}`);
// Delete the newly created asset
yield assetMgmt.DeleteAsset(`${_asset.assetId}`, { ifMatch: `${_asset.etag}` });
}));
it("should PATCH specific device ", () => __awaiter(void 0, void 0, void 0, function* () {
deviceManagementClient.should.not.be.undefined;
const _device = yield deviceManagementClient.GetDevice(deviceId);
_device.serialNumber = `UnitTestserialNumber_D`;
const patchedDevice = yield deviceManagementClient.PatchDevice(`${_device.id}`, _device);
patchedDevice.should.not.be.null;
patchedDevice.serialNumber.should.be.string(`UnitTestserialNumber_D`);
yield deviceManagementClient.DeleteDevice(`${_device.id}`);
}));
it("should DELETE specific device ", () => __awaiter(void 0, void 0, void 0, function* () {
deviceManagementClient.should.not.be.undefined;
// Add a new asset
const _asset = yield assetMgmt.PostAsset({
name: `${tenant}.UnitTestDeviceAsset.${timeOffset}`,
typeId: `${assetTypeId}`,
parentId: gFolderid,
});
// Add new device
testDevice.deviceTypeId = `${deviceTypeId}`;
testDevice.assetId = `${_asset.assetId}`;
testDevice.serialNumber = `UnitTestserialNumber_B`;
const device = yield deviceManagementClient.PostDevice(testDevice);
device.should.not.be.null;
yield deviceManagementClient.DeleteDevice(`${device.id}`);
// Delete the newly created asset
yield assetMgmt.DeleteAsset(`${_asset.assetId}`, { ifMatch: `${_asset.etag}` });
}));
});
//# sourceMappingURL=oe-device-management-device.spec.js.map