forked from hibas123/SecureFileWrapper
82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
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;
|
||
|
module.exports = {
|
||
|
setUp: function (finished) {
|
||
|
let pk = fs_1.readFileSync("./private.pem");
|
||
|
sf = new index_1.default("http://localhost:3005", "test", pk.toString("utf8"));
|
||
|
finished();
|
||
|
},
|
||
|
create: async function (test) {
|
||
|
test.expect(2);
|
||
|
let res = await sf.create(testname, testdata, "text", testprev);
|
||
|
test.ok(res);
|
||
|
test.ok(res._id);
|
||
|
testid = res._id;
|
||
|
testver = res.version;
|
||
|
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();
|
||
|
console.log(res);
|
||
|
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();
|
||
|
}
|
||
|
};
|