@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)
87 lines • 4.37 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 sdk_1 = require("../src/api/sdk");
const utils_1 = require("../src/api/utils");
const test_utils_1 = require("./test-utils");
chai.should();
const timeOffset = new Date().getTime();
describe("[SDK] IotFileClient", () => {
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)()) }));
const iotFile = sdk.GetIoTFileClient();
let rootId = "";
before(() => __awaiter(void 0, void 0, void 0, function* () {
const root = yield sdk.GetAssetManagementClient().GetRootAsset();
rootId = `${root.assetId}`;
yield deleteFiles();
}));
after(() => __awaiter(void 0, void 0, void 0, function* () {
yield deleteFiles();
}));
it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () {
sdk.should.not.be.undefined;
iotFile.should.not.be.undefined;
}));
it("should be able to PUT AND GET file @sanity", () => __awaiter(void 0, void 0, void 0, function* () {
yield (0, utils_1.retry)(5, () => iotFile.PutFile(rootId, `unit/test/xyz${timeOffset}.txt`, Buffer.from("xyz"), {
description: "blubb",
type: "text/plain",
}));
const file = yield (0, utils_1.retry)(5, () => iotFile.GetFile(rootId, `unit/test/xyz${timeOffset}.txt`));
const text = yield file.text();
text.should.be.equal("xyz");
}));
it("should be able to upload 8 mb 1byte large file", () => __awaiter(void 0, void 0, void 0, function* () {
const checksum = yield iotFile.UploadFile(rootId, `unit/test/xyz${timeOffset}_8xmb.txt`, Buffer.alloc(8 * 1024 * 1024 + 1), {
chunk: true,
retry: 5,
});
checksum.should.be.equal("cba5242e77abe5709a262350cf64d835");
}));
it("should be able to upload 16.25 mb 1byte large file", () => __awaiter(void 0, void 0, void 0, function* () {
if (!process.env.CI)
return;
const checksum = yield iotFile.UploadFile(rootId, `unit/test/xyz${timeOffset}_1625mb.txt`, Buffer.alloc(16.25 * 1024 * 1024), {
chunk: true,
retry: 5,
});
checksum.should.be.equal("84c8648b8aa9b803ff92515a63aa4580");
}));
it("should be able to upload 1 byte large file", () => __awaiter(void 0, void 0, void 0, function* () {
const checksum = yield iotFile.UploadFile(rootId, `unit/test/xyz${timeOffset}_1by.txt`, Buffer.alloc(1), {
chunk: true,
retry: 5,
});
checksum.should.be.equal("93b885adfe0da089cdf634904fd59f71");
}));
it("should be able to upload 0 byte large file", () => __awaiter(void 0, void 0, void 0, function* () {
const checksum = yield iotFile.UploadFile(rootId, `unit/test/xyz${timeOffset}_0by.txt`, Buffer.alloc(0), {
chunk: true,
retry: 5,
});
checksum.should.be.equal("d41d8cd98f00b204e9800998ecf8427e");
}));
function deleteFiles() {
return __awaiter(this, void 0, void 0, function* () {
yield (0, test_utils_1.sleep)(2000);
const files = yield iotFile.GetFiles(rootId, {
filter: `name eq xyz${timeOffset}*.txt and path eq unit/test/`,
});
for (const file of files) {
yield iotFile.DeleteFile(rootId, `${file.path}${file.name}`);
}
});
}
});
//# sourceMappingURL=iot-file.spec.js.map