mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
test(etapi): port attachment content
This commit is contained in:
parent
d75e86789d
commit
dddbb9d4d1
@ -1,39 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/attachments
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"ownerId": "{{createdNoteId}}",
|
||||
"role": "file",
|
||||
"mime": "text/plain",
|
||||
"title": "my attachment",
|
||||
"content": "text"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdAttachmentId", response.body.attachmentId); %}
|
||||
|
||||
###
|
||||
|
||||
PUT {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}/content
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/octet-stream
|
||||
Content-Transfer-Encoding: binary
|
||||
|
||||
< ../images/icon-color.png
|
||||
|
||||
> {% client.assert(response.status === 204); %}
|
@ -1,45 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/attachments
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"ownerId": "{{createdNoteId}}",
|
||||
"role": "file",
|
||||
"mime": "text/plain",
|
||||
"title": "my attachment",
|
||||
"content": "text"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdAttachmentId", response.body.attachmentId); %}
|
||||
|
||||
###
|
||||
|
||||
PUT {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}/content
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: text/plain
|
||||
|
||||
Changed content
|
||||
|
||||
> {% client.assert(response.status === 204); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}/content
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.body === "Changed content"); %}
|
64
apps/server/spec/etapi/attachment-content.spec.ts
Normal file
64
apps/server/spec/etapi/attachment-content.spec.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { createNote, login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
let createdNoteId: string;
|
||||
let createdAttachmentId: string;
|
||||
|
||||
describe("etapi/attachment-content", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
|
||||
createdNoteId = await createNote(app, token);
|
||||
|
||||
// Create an attachment
|
||||
const response = await supertest(app)
|
||||
.post(`/etapi/attachments`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
"ownerId": createdNoteId,
|
||||
"role": "file",
|
||||
"mime": "text/plain",
|
||||
"title": "my attachment",
|
||||
"content": "text"
|
||||
});
|
||||
createdAttachmentId = response.body.attachmentId;
|
||||
expect(createdAttachmentId).toBeTruthy();
|
||||
});
|
||||
|
||||
it("changes attachment content", async () => {
|
||||
const text = "Changed content";
|
||||
await supertest(app)
|
||||
.put(`/etapi/attachments/${createdAttachmentId}/content`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.set("Content-Type", "text/plain")
|
||||
.send(text)
|
||||
.expect(204);
|
||||
|
||||
// Ensure it got changed.
|
||||
const response = await supertest(app)
|
||||
.get(`/etapi/attachments/${createdAttachmentId}/content`)
|
||||
.auth(USER, token, { "type": "basic"});
|
||||
expect(response.text).toStrictEqual(text);
|
||||
});
|
||||
|
||||
it("supports binary content", async() => {
|
||||
await supertest(app)
|
||||
.put(`/etapi/attachments/${createdAttachmentId}/content`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.set("Content-Type", "application/octet-stream")
|
||||
.set("Content-Transfer-Encoding", "binary")
|
||||
.send(Buffer.from("Hello world"))
|
||||
.expect(204);
|
||||
});
|
||||
|
||||
});
|
@ -3,14 +3,12 @@ import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { createNote, login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
import { randomUUID } from "crypto";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
let createdNoteId: string;
|
||||
let createdBranchId: string;
|
||||
|
||||
describe("etapi/note-content", () => {
|
||||
beforeAll(async () => {
|
||||
@ -19,7 +17,7 @@ describe("etapi/note-content", () => {
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
|
||||
({ createdNoteId, createdBranchId } = await createNote(app, token));
|
||||
createdNoteId = await createNote(app, token);
|
||||
});
|
||||
|
||||
it("get content", async () => {
|
||||
|
@ -27,7 +27,7 @@ export async function createNote(app: Application, token: string, content?: stri
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
const noteId = response.body.note.noteId;
|
||||
const noteId = response.body.note.noteId as string;
|
||||
expect(noteId).toStrictEqual(noteId);
|
||||
return noteId;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user