Adding support for uploading old versions
This commit is contained in:
parent
8dbc2bcb7f
commit
b76808022f
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hibas123/secure-file-wrapper",
|
"name": "@hibas123/secure-file-wrapper",
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -215,8 +215,8 @@ export default class SecureFileWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data: ArrayBuffer | ArrayBufferView, preview?: string, date?: Date): Promise<IFile> {
|
async update(id: string, data: ArrayBuffer | ArrayBufferView, preview?: string, date?: Date, old = false): Promise<IFile> {
|
||||||
let params: any = {};
|
let params: any = { old };
|
||||||
if (preview) params.preview = preview;
|
if (preview) params.preview = preview;
|
||||||
if (date)
|
if (date)
|
||||||
params.date = date.toJSON()
|
params.date = date.toJSON()
|
||||||
|
16
src/test.ts
16
src/test.ts
@ -7,6 +7,7 @@ const encoder = new TextEncoder();
|
|||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
const testdata = encoder.encode("Ich bin ein Test");
|
const testdata = encoder.encode("Ich bin ein Test");
|
||||||
const newTestData = encoder.encode("neue test daten");
|
const newTestData = encoder.encode("neue test daten");
|
||||||
|
const newTestDataOld = encoder.encode("neue test daten asd");
|
||||||
const testprev = "Ich bin...";
|
const testprev = "Ich bin...";
|
||||||
|
|
||||||
const testfolder = "iabos";
|
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));
|
expect(decoder.decode(res), "Returned data not equal to stored").to.be.equal(decoder.decode(testdata));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it("get - fail", async () => {
|
it("get - fail", async () => {
|
||||||
const inverr = new Error("Should have failed!");
|
const inverr = new Error("Should have failed!");
|
||||||
try {
|
try {
|
||||||
@ -55,6 +54,15 @@ function test(sf: SecureFile) {
|
|||||||
expect(found, "Element not in List").to.be.true;
|
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 () => {
|
it("update", async () => {
|
||||||
let res = await sf.update(testid, newTestData, undefined);
|
let res = await sf.update(testid, newTestData, undefined);
|
||||||
expect(res, "No data returned").to.exist;
|
expect(res, "No data returned").to.exist;
|
||||||
@ -70,9 +78,9 @@ function test(sf: SecureFile) {
|
|||||||
expect(his, "no data returned").to.exist;
|
expect(his, "no data returned").to.exist;
|
||||||
expect(his.file, "file not set").to.exist;
|
expect(his.file, "file not set").to.exist;
|
||||||
expect(his.history, "history 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);
|
expect(his.file.active.version, "Wrong version on file").to.be.equal(testver2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user