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 chai = require("chai");
|
13 | require("url-search-params-polyfill");
|
14 | const sdk_1 = require("../src/api/sdk");
|
15 | const utils_1 = require("../src/api/utils");
|
16 | const test_utils_1 = require("./test-utils");
|
17 | chai.should();
|
18 | const timeOffset = new Date().getTime();
|
19 | describe("[SDK] IotFileClient", () => {
|
20 | const auth = utils_1.loadAuth();
|
21 | const sdk = new sdk_1.MindSphereSdk({
|
22 | basicAuth: utils_1.decrypt(auth, "passkey.4.unit.test"),
|
23 | tenant: auth.tenant,
|
24 | gateway: auth.gateway
|
25 | });
|
26 | const iotFile = sdk.GetIoTFileClient();
|
27 | let rootId = "";
|
28 | before(() => __awaiter(void 0, void 0, void 0, function* () {
|
29 | const root = yield sdk.GetAssetManagementClient().GetRootAsset();
|
30 | rootId = `${root.assetId}`;
|
31 | yield deleteFiles();
|
32 | }));
|
33 | after(() => __awaiter(void 0, void 0, void 0, function* () {
|
34 | yield deleteFiles();
|
35 | }));
|
36 | it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () {
|
37 | sdk.should.not.be.undefined;
|
38 | iotFile.should.not.be.undefined;
|
39 | }));
|
40 | it("should be able to PUT AND GET file", () => __awaiter(void 0, void 0, void 0, function* () {
|
41 | yield utils_1.retry(5, () => iotFile.PutFile(rootId, `unit/test/xyz${timeOffset}.txt`, Buffer.from("xyz"), {
|
42 | description: "blubb",
|
43 | type: "text/plain"
|
44 | }));
|
45 | const file = yield utils_1.retry(5, () => iotFile.GetFile(rootId, `unit/test/xyz${timeOffset}.txt`));
|
46 | const text = yield file.text();
|
47 | text.should.be.equal("xyz");
|
48 | }));
|
49 | it("should be able to upload 8 mb 1byte large file", () => __awaiter(void 0, void 0, void 0, function* () {
|
50 | const checksum = yield iotFile.UploadFile(rootId, `unit/test/xyz${timeOffset}_8xmb.txt`, Buffer.alloc(8 * 1024 * 1024 + 1), {
|
51 | chunk: true,
|
52 | retry: 5
|
53 | });
|
54 | checksum.should.be.equal("cba5242e77abe5709a262350cf64d835");
|
55 | }));
|
56 | it("should be able to upload 16.25 mb 1byte large file", () => __awaiter(void 0, void 0, void 0, function* () {
|
57 | if (!process.env.CI)
|
58 | return;
|
59 | const checksum = yield iotFile.UploadFile(rootId, `unit/test/xyz${timeOffset}_1625mb.txt`, Buffer.alloc(16.25 * 1024 * 1024), {
|
60 | chunk: true,
|
61 | retry: 5
|
62 | });
|
63 | checksum.should.be.equal("84c8648b8aa9b803ff92515a63aa4580");
|
64 | }));
|
65 | it("should be able to upload 1 byte large file", () => __awaiter(void 0, void 0, void 0, function* () {
|
66 | const checksum = yield iotFile.UploadFile(rootId, `unit/test/xyz${timeOffset}_1by.txt`, Buffer.alloc(1), {
|
67 | chunk: true,
|
68 | retry: 5
|
69 | });
|
70 | checksum.should.be.equal("93b885adfe0da089cdf634904fd59f71");
|
71 | }));
|
72 | it("should be able to upload 0 byte large file", () => __awaiter(void 0, void 0, void 0, function* () {
|
73 | const checksum = yield iotFile.UploadFile(rootId, `unit/test/xyz${timeOffset}_0by.txt`, Buffer.alloc(0), {
|
74 | chunk: true,
|
75 | retry: 5
|
76 | });
|
77 | checksum.should.be.equal("d41d8cd98f00b204e9800998ecf8427e");
|
78 | }));
|
79 | function deleteFiles() {
|
80 | return __awaiter(this, void 0, void 0, function* () {
|
81 | yield test_utils_1.sleep(2000);
|
82 | const files = yield iotFile.GetFiles(rootId, {
|
83 | filter: `name eq xyz${timeOffset}*.txt and path eq unit/test/`
|
84 | });
|
85 | for (const file of files) {
|
86 | yield iotFile.DeleteFile(rootId, `${file.path}${file.name}`);
|
87 | }
|
88 | });
|
89 | }
|
90 | });
|
91 |
|
\ | No newline at end of file |