From 41be18e9383ae99978ac7b2e445deec4951d8af2 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 28 Dec 2020 20:43:27 -0800 Subject: [PATCH] test --- package.json | 2 +- .../__snapshots__/collections.test.js.snap | 9 ++++++++ server/api/collections.test.js | 21 +++++++++++++++++++ server/api/documents.test.js | 8 +++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e2ed4fe9d..8484504cb 100644 --- a/package.json +++ b/package.json @@ -207,4 +207,4 @@ "js-yaml": "^3.13.1" }, "version": "0.51.0" -} \ No newline at end of file +} diff --git a/server/api/__snapshots__/collections.test.js.snap b/server/api/__snapshots__/collections.test.js.snap index 95fec2a7c..b3aaf516a 100644 --- a/server/api/__snapshots__/collections.test.js.snap +++ b/server/api/__snapshots__/collections.test.js.snap @@ -61,6 +61,15 @@ Object { } `; +exports[`#collections.import should require authentication 1`] = ` +Object { + "error": "authentication_required", + "message": "Authentication required", + "ok": false, + "status": 401, +} +`; + exports[`#collections.info should require authentication 1`] = ` Object { "error": "authentication_required", diff --git a/server/api/collections.test.js b/server/api/collections.test.js index abb8574f2..da1fe9e4c 100644 --- a/server/api/collections.test.js +++ b/server/api/collections.test.js @@ -4,6 +4,7 @@ import app from "../app"; import { Collection, CollectionUser, CollectionGroup } from "../models"; import { buildUser, buildGroup, buildCollection } from "../test/factories"; import { flushdb, seed } from "../test/support"; + const server = new TestServer(app.callback()); beforeEach(() => flushdb()); @@ -104,6 +105,26 @@ describe("#collections.list", () => { }); }); +describe("#collections.import", () => { + it("should error if no file is passed", async () => { + const user = await buildUser(); + const res = await server.post("/api/collections.import", { + body: { + token: user.getJwtToken(), + }, + }); + expect(res.status).toEqual(400); + }); + + it("should require authentication", async () => { + const res = await server.post("/api/collections.import"); + const body = await res.json(); + + expect(res.status).toEqual(401); + expect(body).toMatchSnapshot(); + }); +}); + describe("#collections.export", () => { it("should now allow export of private collection not a member", async () => { const { user } = await seed(); diff --git a/server/api/documents.test.js b/server/api/documents.test.js index 2bba66881..f6f073bd1 100644 --- a/server/api/documents.test.js +++ b/server/api/documents.test.js @@ -1551,6 +1551,14 @@ describe("#documents.import", () => { }); expect(res.status).toEqual(400); }); + + it("should require authentication", async () => { + const { document } = await seed(); + const res = await server.post("/api/documents.import", { + body: { id: document.id }, + }); + expect(res.status).toEqual(401); + }); }); describe("#documents.create", () => {