"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("./index"); const util_1 = require("util"); const testname = "ouiavgbsop687463743"; const encoder = new util_1.TextEncoder(); const decoder = new util_1.TextDecoder(); const testdata = encoder.encode("Ich bin ein Test"); const newTestData = encoder.encode("neue test daten"); const testprev = "Ich bin..."; const testfolder = "iabos"; let ftestid; const chai_1 = require("chai"); function test(sf) { let testid; let testver; let testver2; it("create", () => __awaiter(this, void 0, void 0, function* () { let res = yield sf.create(testname, testdata, "text", undefined, testprev); chai_1.expect(res, "Res isnnot set").to.exist; chai_1.expect(res._id, "Res has no _id").to.exist; testid = res._id; testver = res.active.version; })); it("get", () => __awaiter(this, void 0, void 0, function* () { let res = yield sf.get(testid); chai_1.expect(res, "No data returned").to.exist; chai_1.expect(decoder.decode(res), "Returned data not equal to stored").to.be.equal(decoder.decode(testdata)); })); it("get - fail", () => __awaiter(this, void 0, void 0, function* () { const inverr = new Error("Should have failed!"); try { yield sf.get(testid + "asod"); throw inverr; } catch (err) { if (err !== inverr) { chai_1.expect(err).to.be.instanceOf(index_1.NotFound); } } })); it("list", () => __awaiter(this, void 0, void 0, function* () { let res = yield sf.list(); chai_1.expect(Array.isArray(res), "Is not from type Array").to.be.true; chai_1.expect(res.length, "No elements returned").to.greaterThan(0); let found = !!res.find(e => e._id === testid); chai_1.expect(found, "Element not in List").to.be.true; })); it("update", () => __awaiter(this, void 0, void 0, function* () { let res = yield sf.update(testid, newTestData, undefined); chai_1.expect(res, "No data returned").to.exist; chai_1.expect(res._id, "_id missing").to.exist; chai_1.expect(res.active.version, "No new version was created").to.not.equal(testver); testver2 = res.active.version; let res2 = yield sf.get(testid); chai_1.expect(decoder.decode(res2), "Fetched data not updated").to.be.equal(decoder.decode(newTestData)); })); it("history", () => __awaiter(this, void 0, void 0, function* () { let his = yield sf.history(testid); chai_1.expect(his, "no data returned").to.exist; chai_1.expect(his.file, "file not set").to.exist; chai_1.expect(his.history, "history not set").to.exist; chai_1.expect(his.history.length, `Not expected history length. Expected 1 got ${his.history.length}`).to.be.equal(1); chai_1.expect(his.history[0].version, "Wrong version on history").to.be.equal(testver); chai_1.expect(his.file.active.version, "Wrong version on file").to.be.equal(testver2); })); it("history get old", () => __awaiter(this, void 0, void 0, function* () { let arch = yield sf.get(testid, testver); chai_1.expect(decoder.decode(arch), "Old version has wrong data").to.be.equal(decoder.decode(testdata)); })); it("history restore", () => __awaiter(this, void 0, void 0, function* () { yield sf.restore(testid, testver); let res = yield sf.get(testid); chai_1.expect(res, "No data returned").to.exist; chai_1.expect(decoder.decode(res), "Returned data not equal to stored").to.be.equal(decoder.decode(testdata)); })); it("delete", () => __awaiter(this, void 0, void 0, function* () { let res = yield sf.delete(testid); chai_1.expect(res, "Res not set").to.exist; })); describe("folder", () => { it("create", () => __awaiter(this, void 0, void 0, function* () { let res = yield sf.create(testname, testdata, "text", testfolder, testprev); chai_1.expect(res, "Res not set").to.exist; chai_1.expect(res._id, "No _id field").to.exist; ftestid = res._id; testver = res.active.version; })); it("list", () => __awaiter(this, void 0, void 0, function* () { let res = yield sf.list(testfolder); chai_1.expect(Array.isArray(res), "Is from type Array").to.be.true; chai_1.expect(res.length, "Do elements exist?").to.be.greaterThan(0); let found = false; res.forEach(e => { if (e._id === ftestid) { found = true; } }); chai_1.expect(found, "Element is not in List").to.exist; })); it("delete", () => __awaiter(this, void 0, void 0, function* () { let res = yield sf.delete(ftestid); chai_1.expect(res, "Res not set").to.exist; })); }); } describe("SecureFile Tests", function () { let sf = new index_1.default("http://localhost:3004"); sf.jwtObservable.subscribe((callback) => { callback[0]("TESTJWT"); }); test(sf); }); //# sourceMappingURL=test.js.map