Adding support for uploading old versions

This commit is contained in:
Fabian Stamm 2019-01-19 16:03:50 +01:00
parent 8dbc2bcb7f
commit b76808022f
3 changed files with 15 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@hibas123/secure-file-wrapper",
"version": "2.2.0",
"version": "2.3.0",
"main": "lib/index.js",
"author": "Fabian Stamm <dev@fabianstamm.de>",
"license": "MIT",

View File

@ -215,8 +215,8 @@ export default class SecureFileWrapper {
}
}
async update(id: string, data: ArrayBuffer | ArrayBufferView, preview?: string, date?: Date): Promise<IFile> {
let params: any = {};
async update(id: string, data: ArrayBuffer | ArrayBufferView, preview?: string, date?: Date, old = false): Promise<IFile> {
let params: any = { old };
if (preview) params.preview = preview;
if (date)
params.date = date.toJSON()

View File

@ -7,6 +7,7 @@ const encoder = new TextEncoder();
const decoder = new TextDecoder();
const testdata = encoder.encode("Ich bin ein Test");
const newTestData = encoder.encode("neue test daten");
const newTestDataOld = encoder.encode("neue test daten asd");
const testprev = "Ich bin...";
const testfolder = "iabos";
@ -33,8 +34,6 @@ function test(sf: SecureFile) {
expect(decoder.decode(res), "Returned data not equal to stored").to.be.equal(decoder.decode(testdata));
})
it("get - fail", async () => {
const inverr = new Error("Should have failed!");
try {
@ -55,6 +54,15 @@ function test(sf: SecureFile) {
expect(found, "Element not in List").to.be.true;
})
it("update to history", async () => {
let res = await sf.update(testid, newTestDataOld, undefined, undefined, true);
expect(res, "No data returned").to.exist;
expect(res._id, "_id missing").to.exist;
expect(res.active.version, "New version was created").to.equal(testver);
let res2 = await sf.get(testid);
expect(decoder.decode(res2), "Fetched data not updated").to.be.equal(decoder.decode(testdata));
})
it("update", async () => {
let res = await sf.update(testid, newTestData, undefined);
expect(res, "No data returned").to.exist;
@ -70,9 +78,9 @@ function test(sf: SecureFile) {
expect(his, "no data returned").to.exist;
expect(his.file, "file not set").to.exist;
expect(his.history, "history not set").to.exist;
expect(his.history.length, `Not expected history length. Expected 1 got ${his.history.length}`).to.be.equal(1);
expect(his.history.length, `Not expected history length. Expected 1 got ${his.history.length}`).to.be.equal(2);
expect(his.history[0].version, "Wrong version on history").to.be.equal(testver);
expect(his.history[1].version, "Wrong version on history").to.be.equal(testver);
expect(his.file.active.version, "Wrong version on file").to.be.equal(testver2);
});