"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const rsa = require("node-rsa"); const index_1 = require("./index"); const fs_1 = require("fs"); const buffer_1 = require("buffer"); let sf; const testname = "ouiavgbsop687463743"; const testdata = new buffer_1.Buffer("Ich bin ein Test"); const newTestData = new buffer_1.Buffer("neue test daten"); const testprev = new buffer_1.Buffer("Ich bin..."); let testid; let testver; let testver2; const testfolder = "iabos"; let ftestid; let e_testid; let private_key; module.exports = { setUp: function (finished) { let pk = fs_1.readFileSync("./private.pem"); private_key = pk.toString("utf8"); sf = new index_1.default("http://localhost:3005", "test", private_key); finished(); }, create: async function (test) { test.expect(2); let res = await sf.create(testname, testdata, "text", undefined, false, testprev); test.ok(res); test.ok(res._id); testid = res._id; testver = res.version; test.done(); }, test: async function (test) { test.expect(2); let res = await sf.test(); test.ok(res.test); test.equal(res.user, "test"); test.done(); }, get: async function (test) { test.expect(2); let res = await sf.get(testid); test.ok(res); test.equal(res.toString(), testdata.toString()); test.done(); }, list: async function (test) { test.expect(4); let res = await sf.list(); test.ok(res); test.ok(Array.isArray(res), "Is from type Array"); test.ok(res.length > 0, "Do elements exist?"); res.forEach(e => { if (e._id === testid) { test.ok(true, "Element is in List"); } }); test.done(); }, update: async function (test) { test.expect(5); let res = await sf.update(testid, newTestData); test.ok(res); test.ok(res._id); test.notEqual(res.version, testver, "Is new version_id generated?"); testver2 = res.version; let res2 = await sf.get(testid); test.ok(res2); test.equal(res2.toString(), newTestData.toString(), "Is fetched data the updated?"); test.done(); }, history: async function (test) { test.expect(7); let his = await sf.history(testid); test.ok(his); test.ok(his.file); test.ok(his.history); test.equal(his.history.length, 1); test.equal(his.history[0].version, testver); test.equal(his.file.version, testver2, "Is correct version"); let arch = await sf.get(testid, testver); test.equal(arch.toString(), testdata.toString(), "Is old version data correct"); test.done(); }, delete: async function (test) { test.expect(1); let res = await sf.delete(testid); test.ok(res); test.done(); }, folder: { create: async function (test) { test.expect(2); let res = await sf.create(testname, testdata, "text", testfolder, false, testprev); test.ok(res); test.ok(res._id); ftestid = res._id; testver = res.version; test.done(); }, list: async function (test) { test.expect(4); let res = await sf.list(testfolder); test.ok(res); test.ok(Array.isArray(res), "Is from type Array"); test.ok(res.length > 0, "Do elements exist?"); res.forEach(e => { if (e._id === ftestid) { test.ok(true, "Element is in List"); } }); test.done(); }, delete: async function (test) { test.expect(1); let res = await sf.delete(ftestid); test.ok(res); test.done(); }, }, encryption: { create: async function (test) { test.expect(2); let res = await sf.create(testname, testdata, "text", undefined, true, testprev); test.ok(res); test.ok(res._id); e_testid = res._id; testver = res.version; test.done(); }, get: async function (test) { let r = new rsa(private_key, "pkcs1-pem"); test.expect(2); let res = await sf.get(e_testid); res = r.decrypt(res); test.ok(res); test.equal(res.toString(), testdata.toString()); test.done(); }, delete: async function (test) { test.expect(1); let res = await sf.delete(e_testid); test.ok(res); test.done(); }, } };