diff --git a/_regroup/test-etapi/export-note-subtree.http b/_regroup/test-etapi/export-note-subtree.http deleted file mode 100644 index 28d90a362..000000000 --- a/_regroup/test-etapi/export-note-subtree.http +++ /dev/null @@ -1,37 +0,0 @@ -GET {{triliumHost}}/etapi/notes/root/export -Authorization: {{authToken}} - -> {% - client.assert(response.status === 200); - client.assert(response.headers.valueOf("Content-Type") == "application/zip"); -%} - -### - -GET {{triliumHost}}/etapi/notes/root/export?format=html -Authorization: {{authToken}} - -> {% - client.assert(response.status === 200); - client.assert(response.headers.valueOf("Content-Type") == "application/zip"); -%} - -### - -GET {{triliumHost}}/etapi/notes/root/export?format=markdown -Authorization: {{authToken}} - -> {% - client.assert(response.status === 200); - client.assert(response.headers.valueOf("Content-Type") == "application/zip"); -%} - -### - -GET {{triliumHost}}/etapi/notes/root/export?format=wrong -Authorization: {{authToken}} - -> {% - client.assert(response.status === 400); - client.assert(response.body.code === "UNRECOGNIZED_EXPORT_FORMAT"); -%} diff --git a/apps/server/spec/etapi/export-note-subtree.spec.ts b/apps/server/spec/etapi/export-note-subtree.spec.ts new file mode 100644 index 000000000..f5f09b532 --- /dev/null +++ b/apps/server/spec/etapi/export-note-subtree.spec.ts @@ -0,0 +1,51 @@ +import { Application } from "express"; +import { beforeAll, describe, expect, it } from "vitest"; +import supertest from "supertest"; +import { login } from "./utils.js"; +import config from "../../src/services/config.js"; + +let app: Application; +let token: string; + +const USER = "etapi"; + +describe("etapi/export-note-subtree", () => { + beforeAll(async () => { + config.General.noAuthentication = false; + const buildApp = (await (import("../../src/app.js"))).default; + app = await buildApp(); + token = await login(app); + }); + + it("export works", async () => { + await supertest(app) + .get("/etapi/notes/root/export") + .auth(USER, token, { "type": "basic"}) + .expect(200) + .expect("Content-Type", "application/zip"); + }); + + it("HTML export works", async () => { + await supertest(app) + .get("/etapi/notes/root/export?format=html") + .auth(USER, token, { "type": "basic"}) + .expect(200) + .expect("Content-Type", "application/zip"); + }); + + it("Markdown export works", async () => { + await supertest(app) + .get("/etapi/notes/root/export?format=markdown") + .auth(USER, token, { "type": "basic"}) + .expect(200) + .expect("Content-Type", "application/zip"); + }); + + it("reports wrong format", async () => { + const response = await supertest(app) + .get("/etapi/notes/root/export?format=wrong") + .auth(USER, token, { "type": "basic"}) + .expect(400); + expect(response.body.code).toStrictEqual("UNRECOGNIZED_EXPORT_FORMAT"); + }); +});