diff --git a/_regroup/test-etapi/import-zip.http b/_regroup/test-etapi/import-zip.http deleted file mode 100644 index e831a050a..000000000 --- a/_regroup/test-etapi/import-zip.http +++ /dev/null @@ -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"); -%} diff --git a/apps/server/spec/etapi/import-zip.spec.ts b/apps/server/spec/etapi/import-zip.spec.ts new file mode 100644 index 000000000..c42623b76 --- /dev/null +++ b/apps/server/spec/etapi/import-zip.spec.ts @@ -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"); + }); +});