From b76808022f44c7d0c23b415c649a2bffe236c7d3 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Sat, 19 Jan 2019 16:03:50 +0100 Subject: [PATCH] Adding support for uploading old versions --- package.json | 2 +- src/index.ts | 4 ++-- src/test.ts | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index d3beea0..10d8d0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/secure-file-wrapper", - "version": "2.2.0", + "version": "2.3.0", "main": "lib/index.js", "author": "Fabian Stamm ", "license": "MIT", diff --git a/src/index.ts b/src/index.ts index 838796f..79bf752 100644 --- a/src/index.ts +++ b/src/index.ts @@ -215,8 +215,8 @@ export default class SecureFileWrapper { } } - async update(id: string, data: ArrayBuffer | ArrayBufferView, preview?: string, date?: Date): Promise { - let params: any = {}; + async update(id: string, data: ArrayBuffer | ArrayBufferView, preview?: string, date?: Date, old = false): Promise { + let params: any = { old }; if (preview) params.preview = preview; if (date) params.date = date.toJSON() diff --git a/src/test.ts b/src/test.ts index aabb949..82e566c 100644 --- a/src/test.ts +++ b/src/test.ts @@ -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); });