@mindconnect/mindconnect-nodejs
Version:
MindConnect Library for NodeJS (community based)
107 lines • 5.08 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] AssetManagementClient.Files", () => {
const auth = utils_1.loadAuth();
const sdk = new sdk_1.MindSphereSdk({
basicAuth: utils_1.decrypt(auth, "passkey.4.unit.test"),
tenant: auth.tenant,
gateway: auth.gateway
});
const am = sdk.GetAssetManagementClient();
before(() => __awaiter(void 0, void 0, void 0, function* () {
yield deleteFiles(am);
}));
after(() => __awaiter(void 0, void 0, void 0, function* () {
yield deleteFiles(am);
}));
it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () {
sdk.should.not.be.undefined;
}));
it("should be able to POST AND GET file", () => __awaiter(void 0, void 0, void 0, function* () {
if (process.env.CI) {
return; // ! lets do this only locally as mindsphere sometimes behaves strange on fast deletion of files
}
// ! the behavior here is asynchronous...
const result = yield utils_1.retry(5, () => am.PostFile(Buffer.from("xyz"), `${timeOffset}xyz.text`, {
mimeType: "text/plain",
description: "Blubb2"
}), 1000);
const files = yield am.GetFiles({ filter: JSON.stringify({ name: `${timeOffset}xyz.text` }) });
files._embedded.files.length.should.equal(1);
yield am.DeleteFile(`${result.id}`, { ifMatch: `${result.etag}` });
}));
it("should be able to Download file", () => __awaiter(void 0, void 0, void 0, function* () {
if (process.env.CI) {
return; // ! lets do this only locally as mindsphere sometimes behaves strange on fast deletion of files
}
const result = yield am.PostFile(Buffer.from("xyz"), `${timeOffset}xyz.text`, {
mimeType: "text/plain",
description: "Blubb2"
});
// ! the behavior here is asynchronous...
const file = (yield utils_1.retry(5, () => am.DownloadFile(`${result.id}`), 1000));
const text = yield file.text();
text.should.be.equal("xyz");
yield am.DeleteFile(`${result.id}`, { ifMatch: `${result.etag}` });
}));
it("should be able to DELETE file", () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield am.PostFile(Buffer.from("abc"), `${timeOffset}abc.text`, {
mimeType: "text/plain",
description: "Blubb2"
});
yield am.DeleteFile(`${result.id}`, { ifMatch: `${result.etag}` });
}));
it("should be able to PUT file", () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield am.PostFile(Buffer.from("abc"), `${timeOffset}test2.text`, {
mimeType: "text/plain",
description: "Blubb2"
});
const updatedFile = yield am.PutFile(`${result.id}`, Buffer.from("abcabc"), `${timeOffset}test2.text`, {
scope: sdk_1.AssetManagementModels.FileMetadataResource.ScopeEnum.PRIVATE,
description: result.description,
ifMatch: `${result.etag}`
});
yield am.DeleteFile(`${result.id}`, { ifMatch: `${updatedFile.etag}` });
}));
it("should be able to Get Billboard", () => __awaiter(void 0, void 0, void 0, function* () {
const billboard = yield am.GetBillboard();
billboard.should.not.be.undefined;
}));
});
function deleteFiles(am) {
return __awaiter(this, void 0, void 0, function* () {
yield test_utils_1.sleep(2000);
const files = (yield am.GetFiles({
filter: JSON.stringify({
and: {
name: {
endsWith: ".text"
}
}
}),
sort: "DESC",
page: 0,
size: 0
}));
for (const x of files._embedded.files) {
yield am.DeleteFile(x.id, { ifMatch: x.etag });
}
});
}
//# sourceMappingURL=asset-management-files.spec.js.map