@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)
407 lines • 21 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 open_edge_models_1 = require("../src/api/sdk/open-edge/open-edge-models");
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.DeviceConfiguration", () => {
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 deviceConfigurationClient = sdk.GetDeviceConfigurationClient();
const tenant = sdk.GetTenant();
const configFileTemplate = {
path: `/${tenant}/TEST/${timeOffset}/TEST_DEVICE_CONFIGURATION.json`,
description: `Configuration for test the API. generated by ${tenant} on ${new Date()}`,
};
const testConfigurationTask = {
files: [
{
name: configFileTemplate.path,
uri: `https://testuri.com/${tenant}/TEST/${timeOffset}/TEST_DEVICE_CONFIGURATION.json`,
checksum: "sha1:cf23...",
},
],
customData: {
name: "TEST_DEVICE_CONFIGURATION",
sampleKey1: "sampleValue1",
sampleKey2: "sampleValue2",
created: timeOffset,
},
target: {
address: "XTOOLS",
},
};
const testConfigurationState = {
state: open_edge_models_1.DeviceConfigurationModels.Updatetask.StateEnum.CONFIGURING,
progress: 0,
message: "Configuring.",
details: {},
};
let deviceTypeId = "aee2e37f-f562-4ed6-b90a-c43208dc054a";
let assetTypeId = `${tenant}.UnitTestDeviceAssetType`;
let assetId = "";
let gFolderid = "";
let deviceId = "";
let configTaskId = "";
let globalFileId = "";
let globalFilePath = "";
before(() => __awaiter(void 0, void 0, void 0, function* () {
// tear Down test infrastructure
yield deleteFiles();
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}`;
// Post a new file config
const newFile = yield deviceConfigurationClient.PostNewFile(configFileTemplate);
globalFileId = `${newFile.id}`;
globalFilePath = `${newFile.path}`;
}));
after(() => __awaiter(void 0, void 0, void 0, function* () {
// Cancel all configuration tasks
// await CancelAllGeneratedConfigurationTaks();
// delete all generated files
yield deleteFiles();
// 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* () {
deviceConfigurationClient.should.not.be.undefined;
deviceConfigurationClient.GetGateway().should.be.equal(auth.gateway);
(yield deviceConfigurationClient.GetToken()).length.should.be.greaterThan(200);
(yield deviceConfigurationClient.GetToken()).length.should.be.greaterThan(200);
}));
it("should POST to create a new empty file", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
// Prepare the template
const _configFileTemplate = {
path: `/${tenant}/TEST/${timeOffset}/TEST_DEVICE_CONFIGURATION_A.json`,
description: `Configuration for test the API. generated by ${tenant} on ${new Date()}`,
};
const newFile = yield deviceConfigurationClient.PostNewFile(_configFileTemplate);
newFile.should.not.be.undefined;
newFile.should.not.be.null;
newFile.id.should.not.be.undefined;
newFile.id.should.not.be.null;
newFile.path.should.not.be.undefined;
newFile.path.should.not.be.null;
// delete file
yield deviceConfigurationClient.DeleteFile(newFile.id);
}));
it("should POST to create a new empty file and add content revision of 1b.", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
// Prepare the template
const _configFileTemplate = {
path: `/${tenant}/TEST/${timeOffset}/TEST_DEVICE_CONFIGURATION_B.json`,
description: `Configuration for test the API. generated by ${tenant} on ${new Date()}`,
};
const newFile = yield deviceConfigurationClient.PostNewFile(_configFileTemplate);
newFile.should.not.be.undefined;
newFile.should.not.be.null;
newFile.id.should.not.be.undefined;
newFile.id.should.not.be.null;
newFile.path.should.not.be.undefined;
newFile.path.should.not.be.null;
const _fileId = newFile.id;
// post content of 1kb
const buffer = Buffer.alloc(1);
const revision = yield deviceConfigurationClient.PostFileRevision(_fileId, buffer);
revision.fileId.should.not.be.undefined;
revision.fileId.should.not.be.null;
revision.contentType.should.not.be.undefined;
revision.contentType.should.not.be.null;
// delete file
yield deviceConfigurationClient.DeleteFile(newFile.id);
}));
it("should POST to create a new empty file and add content revision of 8Mb.", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
// Prepare the template
const _configFileTemplate = {
path: `/${tenant}/TEST/${timeOffset}/TEST_DEVICE_CONFIGURATION_C.json`,
description: `Configuration for test the API. generated by ${tenant} on ${new Date()}`,
};
const newFile = yield deviceConfigurationClient.PostNewFile(_configFileTemplate);
newFile.should.not.be.undefined;
newFile.should.not.be.null;
newFile.id.should.not.be.undefined;
newFile.id.should.not.be.null;
newFile.path.should.not.be.undefined;
newFile.path.should.not.be.null;
const _fileId = newFile.id;
// post content of 1kb
const buffer = Buffer.alloc(8 * 1024 * 1024);
const revision = yield deviceConfigurationClient.PostFileRevision(_fileId, buffer);
revision.fileId.should.not.be.undefined;
revision.fileId.should.not.be.null;
revision.contentType.should.not.be.undefined;
revision.contentType.should.not.be.null;
// delete file
yield deviceConfigurationClient.DeleteFile(newFile.id);
}));
it("should POST to create a new empty file and add content revision of 16Mb.", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
// Prepare the template
const _configFileTemplate = {
path: `/${tenant}/TEST/${timeOffset}/TEST_DEVICE_CONFIGURATION_D.json`,
description: `Configuration for test the API. generated by ${tenant} on ${new Date()}`,
};
const newFile = yield deviceConfigurationClient.PostNewFile(_configFileTemplate);
newFile.should.not.be.undefined;
newFile.should.not.be.null;
newFile.id.should.not.be.undefined;
newFile.id.should.not.be.null;
newFile.path.should.not.be.undefined;
newFile.path.should.not.be.null;
const _fileId = newFile.id;
// post content of 1kb
const buffer = Buffer.alloc(16 * 1024 * 1024);
const revision = yield deviceConfigurationClient.PostFileRevision(_fileId, buffer);
revision.fileId.should.not.be.undefined;
revision.fileId.should.not.be.null;
revision.contentType.should.not.be.undefined;
revision.contentType.should.not.be.null;
// delete file
yield deviceConfigurationClient.DeleteFile(newFile.id);
}));
it("should POST to add content revision of 1Mb.", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
// post content of 1kb
const buffer = Buffer.alloc(1 * 1024 * 1024);
const revision = yield deviceConfigurationClient.PostFileRevision(globalFileId, buffer);
revision.fileId.should.not.be.undefined;
revision.fileId.should.not.be.null;
revision.contentType.should.not.be.undefined;
revision.contentType.should.not.be.null;
}));
// it("should PATCH to Update head to new revision of 2Mb.", async () => {
// deviceConfigurationClient.should.not.be.undefined;
//
// // post content of 1kb
// const buffer = Buffer.alloc(2 * 1024 * 1024);
// const revision = await deviceConfigurationClient.PatchFileHead(globalFileId, buffer);
// (revision as any).fileId.should.not.be.undefined;
// (revision as any).fileId.should.not.be.null;
// (revision as any).contentType.should.not.be.undefined;
// (revision as any).contentType.should.not.be.null;
// });
it("should GET to list all files revisions.", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
const revisions = yield deviceConfigurationClient.GetFileRevisions(globalFileId);
revisions.should.not.be.undefined;
revisions.should.not.be.null;
revisions.page.number.should.equal(0);
revisions.page.size.should.be.gte(10);
revisions.content.length.should.be.gte(0);
}));
it("should GET to list all files from path.", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
const files = yield deviceConfigurationClient.GetFiles(`/${tenant}/TEST/${timeOffset}/`);
files.should.not.be.undefined;
files.should.not.be.null;
files.page.number.should.equal(0);
files.page.size.should.be.gte(10);
files.content.length.should.be.gte(0);
}));
it("should GET file meta data.", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
const fileMetaData = yield deviceConfigurationClient.GetFileMetadata(globalFileId);
fileMetaData.should.not.be.undefined;
fileMetaData.should.not.be.null;
fileMetaData.id.should.not.be.undefined;
fileMetaData.id.should.not.be.null;
fileMetaData.path.should.not.be.undefined;
fileMetaData.path.should.not.be.null;
}));
it("should GET file revision meta data.", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
// Prepare the template
const _configFileTemplate = {
path: `/${tenant}/TEST/${timeOffset}/TEST_DEVICE_CONFIGURATION_E.json`,
description: `Configuration for test the API. generated by ${tenant} on ${new Date()}`,
};
const newFile = yield deviceConfigurationClient.PostNewFile(_configFileTemplate);
newFile.should.not.be.undefined;
newFile.should.not.be.null;
newFile.id.should.not.be.undefined;
newFile.id.should.not.be.null;
newFile.path.should.not.be.undefined;
newFile.path.should.not.be.null;
const _fileId = newFile.id;
// post content of 1kb
const buffer = Buffer.alloc(1);
const revision = yield deviceConfigurationClient.PostFileRevision(_fileId, buffer);
revision.fileId.should.not.be.undefined;
revision.fileId.should.not.be.null;
revision.contentType.should.not.be.undefined;
revision.contentType.should.not.be.null;
// Get file revision
const rRevision = yield deviceConfigurationClient.GetFileRevisionMetadata(_fileId, revision.hash);
rRevision.fileId.should.not.be.undefined;
rRevision.fileId.should.not.be.null;
rRevision.fileId.should.be.equal(revision.fileId);
rRevision.contentType.should.not.be.undefined;
rRevision.contentType.should.not.be.null;
rRevision.contentType.should.be.equal(revision.contentType);
rRevision.hash.should.not.be.undefined;
rRevision.hash.should.not.be.null;
rRevision.hash.should.be.equal(revision.hash);
// delete file
yield deviceConfigurationClient.DeleteFile(newFile.id);
}));
it("should GET file revision content.", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
// Prepare the template
const _configFileTemplate = {
path: `/${tenant}/TEST/${timeOffset}/TEST_DEVICE_CONFIGURATION_F.json`,
description: `Configuration for test the API. generated by ${tenant} on ${new Date()}`,
};
const newFile = yield deviceConfigurationClient.PostNewFile(_configFileTemplate);
newFile.should.not.be.undefined;
newFile.should.not.be.null;
newFile.id.should.not.be.undefined;
newFile.id.should.not.be.null;
newFile.path.should.not.be.undefined;
newFile.path.should.not.be.null;
const _fileId = newFile.id;
// post content of 1kb
const buffer = Buffer.alloc(1);
const revision = yield deviceConfigurationClient.PostFileRevision(_fileId, buffer);
revision.fileId.should.not.be.undefined;
revision.fileId.should.not.be.null;
revision.contentType.should.not.be.undefined;
revision.contentType.should.not.be.null;
// Get file revision
const rContent = yield deviceConfigurationClient.GetFileRevisionContent(_fileId, revision.hash);
rContent.should.not.be.undefined;
rContent.should.not.be.null;
// delete file
yield deviceConfigurationClient.DeleteFile(newFile.id);
}));
it("should DELETE a file of 1b.", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
// Prepare the template
const _configFileTemplate = {
path: `/${tenant}/TEST/${timeOffset}/TEST_DEVICE_CONFIGURATION_G.json`,
description: `Configuration for test the API. generated by ${tenant} on ${new Date()}`,
};
const newFile = yield deviceConfigurationClient.PostNewFile(_configFileTemplate);
newFile.should.not.be.undefined;
newFile.should.not.be.null;
newFile.id.should.not.be.undefined;
newFile.id.should.not.be.null;
newFile.path.should.not.be.undefined;
newFile.path.should.not.be.null;
const _fileId = newFile.id;
// post content of 1b
const buffer = Buffer.alloc(1);
const revision = yield deviceConfigurationClient.PostFileRevision(_fileId, buffer);
revision.fileId.should.not.be.undefined;
revision.fileId.should.not.be.null;
revision.contentType.should.not.be.undefined;
revision.contentType.should.not.be.null;
// delete file
yield deviceConfigurationClient.DeleteFile(newFile.id);
}));
it("should POST a new configuration task", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
// Change the testConfigurationTask
testConfigurationTask.customData.name = `TEST_DEVICE_CONFIGURATION_${tenant}_${timeOffset}_A`;
// Create a new app instance configuration
const newConfigtask = yield deviceConfigurationClient.PostNewDeploymentTaskConfiguration(deviceId, testConfigurationTask);
newConfigtask.should.not.be.undefined;
newConfigtask.should.not.be.null;
newConfigtask.id.should.not.be.undefined;
newConfigtask.id.should.not.be.null;
newConfigtask.customData.name.should.not.be.undefined;
newConfigtask.customData.name.should.not.be.null;
newConfigtask.currentState.should.not.be.undefined;
newConfigtask.currentState.should.not.be.null;
configTaskId = `${newConfigtask.id}`;
//
// const _configTaskId = `${(newConfigtask as any).id}`;
//
// // Cancel the task
// testConfigurationState.state = DeviceConfigurationModels.Updatetask.StateEnum.CANCELED;
// testConfigurationState.progress = 100;
// const configtask = await deviceConfigurationClient.PatchDeploymentTaskConfiguration(
// deviceId,
// _configTaskId,
// testConfigurationState
// );
}));
it("should GET list all tasks of a device @sanity", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
const apps = yield deviceConfigurationClient.GetConfigurationTasks(deviceId);
apps.should.not.be.undefined;
apps.should.not.be.null;
apps.page.number.should.equal(0);
apps.page.size.should.be.gte(10);
apps.content.length.should.be.gte(0);
}));
it("should GET status of a configuration task by id", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
const status = yield deviceConfigurationClient.GetDeviceConfigurationTask(deviceId, configTaskId);
status.should.not.be.undefined;
status.should.not.be.null;
status.currentState.should.not.be.undefined;
status.currentState.should.not.be.null;
}));
it("should PATCH status of configuration task: cancel task.", () => __awaiter(void 0, void 0, void 0, function* () {
// Patch the task
// Prepare the state
testConfigurationState.state = open_edge_models_1.DeviceConfigurationModels.Updatetask.StateEnum.CANCELED;
testConfigurationState.progress = 100;
const configtask = yield deviceConfigurationClient.PatchDeploymentTaskConfiguration(deviceId, configTaskId, testConfigurationState);
configtask.id.should.not.be.undefined;
configtask.id.should.not.be.null;
configtask.currentState.should.not.be.undefined;
configtask.currentState.should.not.be.null;
}));
it("should GET status of a configuration task, which should be canceled", () => __awaiter(void 0, void 0, void 0, function* () {
deviceConfigurationClient.should.not.be.undefined;
const status = yield deviceConfigurationClient.GetDeviceConfigurationTask(deviceId, configTaskId);
status.should.not.be.undefined;
status.should.not.be.null;
status.currentState.should.not.be.undefined;
status.currentState.should.not.be.null;
status.currentState.state.should.be.equal(open_edge_models_1.DeviceConfigurationModels.ConfigurationStateInfo.StateEnum.CANCELED.toString());
}));
function deleteFiles() {
return __awaiter(this, void 0, void 0, function* () {
yield (0, test_utils_1.sleep)(2000);
let files = null;
let page = 0;
do {
files = (yield deviceConfigurationClient.GetFiles(`/${tenant}/TEST`, 100));
files.content = files.content || [];
files.page = files.page || { totalPages: 0 };
for (const _fileMetaData of files.content || []) {
const fileMetaData = _fileMetaData;
yield deviceConfigurationClient.DeleteFile(`${fileMetaData.id}`);
}
} while (page++ < (files.page.totalPages || 0));
});
}
});
//# sourceMappingURL=oe-device-configuration.spec.js.map