UNPKG

5.08 kBJavaScriptView Raw
1"use strict";
2var __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};
11Object.defineProperty(exports, "__esModule", { value: true });
12const chai = require("chai");
13require("url-search-params-polyfill");
14const sdk_1 = require("../src/api/sdk");
15const utils_1 = require("../src/api/utils");
16const test_utils_1 = require("./test-utils");
17chai.should();
18const timeOffset = new Date().getTime();
19describe("[SDK] AssetManagementClient.Files", () => {
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 am = sdk.GetAssetManagementClient();
27 before(() => __awaiter(void 0, void 0, void 0, function* () {
28 yield deleteFiles(am);
29 }));
30 after(() => __awaiter(void 0, void 0, void 0, function* () {
31 yield deleteFiles(am);
32 }));
33 it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () {
34 sdk.should.not.be.undefined;
35 }));
36 it("should be able to POST AND GET file", () => __awaiter(void 0, void 0, void 0, function* () {
37 if (process.env.CI) {
38 return; // ! lets do this only locally as mindsphere sometimes behaves strange on fast deletion of files
39 }
40 // ! the behavior here is asynchronous...
41 const result = yield utils_1.retry(5, () => am.PostFile(Buffer.from("xyz"), `${timeOffset}xyz.text`, {
42 mimeType: "text/plain",
43 description: "Blubb2"
44 }), 1000);
45 const files = yield am.GetFiles({ filter: JSON.stringify({ name: `${timeOffset}xyz.text` }) });
46 files._embedded.files.length.should.equal(1);
47 yield am.DeleteFile(`${result.id}`, { ifMatch: `${result.etag}` });
48 }));
49 it("should be able to Download file", () => __awaiter(void 0, void 0, void 0, function* () {
50 if (process.env.CI) {
51 return; // ! lets do this only locally as mindsphere sometimes behaves strange on fast deletion of files
52 }
53 const result = yield am.PostFile(Buffer.from("xyz"), `${timeOffset}xyz.text`, {
54 mimeType: "text/plain",
55 description: "Blubb2"
56 });
57 // ! the behavior here is asynchronous...
58 const file = (yield utils_1.retry(5, () => am.DownloadFile(`${result.id}`), 1000));
59 const text = yield file.text();
60 text.should.be.equal("xyz");
61 yield am.DeleteFile(`${result.id}`, { ifMatch: `${result.etag}` });
62 }));
63 it("should be able to DELETE file", () => __awaiter(void 0, void 0, void 0, function* () {
64 const result = yield am.PostFile(Buffer.from("abc"), `${timeOffset}abc.text`, {
65 mimeType: "text/plain",
66 description: "Blubb2"
67 });
68 yield am.DeleteFile(`${result.id}`, { ifMatch: `${result.etag}` });
69 }));
70 it("should be able to PUT file", () => __awaiter(void 0, void 0, void 0, function* () {
71 const result = yield am.PostFile(Buffer.from("abc"), `${timeOffset}test2.text`, {
72 mimeType: "text/plain",
73 description: "Blubb2"
74 });
75 const updatedFile = yield am.PutFile(`${result.id}`, Buffer.from("abcabc"), `${timeOffset}test2.text`, {
76 scope: sdk_1.AssetManagementModels.FileMetadataResource.ScopeEnum.PRIVATE,
77 description: result.description,
78 ifMatch: `${result.etag}`
79 });
80 yield am.DeleteFile(`${result.id}`, { ifMatch: `${updatedFile.etag}` });
81 }));
82 it("should be able to Get Billboard", () => __awaiter(void 0, void 0, void 0, function* () {
83 const billboard = yield am.GetBillboard();
84 billboard.should.not.be.undefined;
85 }));
86});
87function deleteFiles(am) {
88 return __awaiter(this, void 0, void 0, function* () {
89 yield test_utils_1.sleep(2000);
90 const files = (yield am.GetFiles({
91 filter: JSON.stringify({
92 and: {
93 name: {
94 endsWith: ".text"
95 }
96 }
97 }),
98 sort: "DESC",
99 page: 0,
100 size: 0
101 }));
102 for (const x of files._embedded.files) {
103 yield am.DeleteFile(x.id, { ifMatch: x.etag });
104 }
105 });
106}
107//# sourceMappingURL=asset-management-files.spec.js.map
\No newline at end of file