test(etapi): port export note subtree

This commit is contained in:
Elian Doran 2025-06-03 10:08:41 +03:00
parent 94cb18589a
commit 3dfe2ce066
No known key found for this signature in database
2 changed files with 51 additions and 37 deletions

View File

@ -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");
%}

View File

@ -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");
});
});