test(etapi): port import zip

This commit is contained in:
Elian Doran 2025-06-03 10:16:16 +03:00
parent 3dfe2ce066
commit 2dd2adefae
No known key found for this signature in database
2 changed files with 34 additions and 12 deletions

View File

@ -1,12 +0,0 @@
POST {{triliumHost}}/etapi/notes/root/import
Authorization: {{authToken}}
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
< ../db/demo.zip
> {%
client.assert(response.status === 201);
client.assert(response.body.note.title == "Trilium Demo");
client.assert(response.body.branch.parentNoteId == "root");
%}

View File

@ -0,0 +1,34 @@
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";
import { readFileSync } from "fs";
import { join } from "path";
let app: Application;
let token: string;
const USER = "etapi";
describe("etapi/import", () => {
beforeAll(async () => {
config.General.noAuthentication = false;
const buildApp = (await (import("../../src/app.js"))).default;
app = await buildApp();
token = await login(app);
});
it("demo zip can be imported", async () => {
const buffer = readFileSync(join(__dirname, "../../src/assets/db/demo.zip"));
const response = await supertest(app)
.post("/etapi/notes/root/import")
.auth(USER, token, { "type": "basic"})
.set("Content-Type", "application/octet-stream")
.set("Content-Transfer-Encoding", "binary")
.send(buffer)
.expect(201);
expect(response.body.note.title).toStrictEqual("Journal");
expect(response.body.branch.parentNoteId).toStrictEqual("root");
});
});