mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	test(etapi): port patch branch
This commit is contained in:
		@@ -1,66 +0,0 @@
 | 
			
		||||
POST {{triliumHost}}/etapi/create-note
 | 
			
		||||
Authorization: {{authToken}}
 | 
			
		||||
Content-Type: application/json
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
  "parentNoteId": "root",
 | 
			
		||||
  "type": "text",
 | 
			
		||||
  "title": "Hello",
 | 
			
		||||
  "content": ""
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
> {% client.global.set("createdBranchId", response.body.branch.branchId); %}
 | 
			
		||||
 | 
			
		||||
###
 | 
			
		||||
 | 
			
		||||
PATCH {{triliumHost}}/etapi/branches/{{createdBranchId}}
 | 
			
		||||
Authorization: {{authToken}}
 | 
			
		||||
Content-Type: application/json
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
  "prefix": "pref",
 | 
			
		||||
  "notePosition": 666,
 | 
			
		||||
  "isExpanded": true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
###
 | 
			
		||||
 | 
			
		||||
GET {{triliumHost}}/etapi/branches/{{createdBranchId}}
 | 
			
		||||
Authorization: {{authToken}}
 | 
			
		||||
 | 
			
		||||
> {% 
 | 
			
		||||
client.assert(response.status === 200);
 | 
			
		||||
client.assert(response.body.prefix === 'pref');
 | 
			
		||||
client.assert(response.body.notePosition === 666);
 | 
			
		||||
client.assert(response.body.isExpanded === true);
 | 
			
		||||
%}
 | 
			
		||||
 | 
			
		||||
###
 | 
			
		||||
 | 
			
		||||
PATCH {{triliumHost}}/etapi/branches/{{createdBranchId}}
 | 
			
		||||
Authorization: {{authToken}}
 | 
			
		||||
Content-Type: application/json
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
  "parentNoteId": "root"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
> {% 
 | 
			
		||||
    client.assert(response.status === 400); 
 | 
			
		||||
    client.assert(response.body.code == "PROPERTY_NOT_ALLOWED");
 | 
			
		||||
%}
 | 
			
		||||
 | 
			
		||||
###
 | 
			
		||||
 | 
			
		||||
PATCH {{triliumHost}}/etapi/branches/{{createdBranchId}}
 | 
			
		||||
Authorization: {{authToken}}
 | 
			
		||||
Content-Type: application/json
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
  "prefix": 123
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
> {% 
 | 
			
		||||
    client.assert(response.status === 400); 
 | 
			
		||||
    client.assert(response.body.code == "PROPERTY_VALIDATION_ERROR");
 | 
			
		||||
%}
 | 
			
		||||
							
								
								
									
										77
									
								
								apps/server/spec/etapi/patch-branch.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								apps/server/spec/etapi/patch-branch.spec.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,77 @@
 | 
			
		||||
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 createdBranchId: 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);
 | 
			
		||||
 | 
			
		||||
        // Create a note and a branch.
 | 
			
		||||
        const response = await supertest(app)
 | 
			
		||||
            .post("/etapi/create-note")
 | 
			
		||||
            .auth("etapi", token, { "type": "basic"})
 | 
			
		||||
            .send({
 | 
			
		||||
                "parentNoteId": "root",
 | 
			
		||||
                "title": "Hello",
 | 
			
		||||
                "type": "text",
 | 
			
		||||
                "content": "",
 | 
			
		||||
            })
 | 
			
		||||
            .expect(201);
 | 
			
		||||
 | 
			
		||||
        createdBranchId = response.body.branch.branchId;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("can patch branch info", async () => {
 | 
			
		||||
        const state = {
 | 
			
		||||
            prefix: "pref",
 | 
			
		||||
            notePosition: 666,
 | 
			
		||||
            isExpanded: true
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        await supertest(app)
 | 
			
		||||
            .patch(`/etapi/branches/${createdBranchId}`)
 | 
			
		||||
            .auth("etapi", token, { "type": "basic"})
 | 
			
		||||
            .send(state)
 | 
			
		||||
            .expect(200);
 | 
			
		||||
 | 
			
		||||
        const response = await supertest(app)
 | 
			
		||||
            .get(`/etapi/branches/${createdBranchId}`)
 | 
			
		||||
            .auth("etapi", token, { "type": "basic"})
 | 
			
		||||
            .expect(200);
 | 
			
		||||
        expect(response.body).toMatchObject(state);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("rejects not allowed property", async () => {
 | 
			
		||||
        const response = await supertest(app)
 | 
			
		||||
            .patch(`/etapi/branches/${createdBranchId}`)
 | 
			
		||||
            .auth("etapi", token, { "type": "basic"})
 | 
			
		||||
            .send({
 | 
			
		||||
                parentNoteId: "root"
 | 
			
		||||
            })
 | 
			
		||||
            .expect(400);
 | 
			
		||||
        expect(response.body.code).toStrictEqual("PROPERTY_NOT_ALLOWED");
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("rejects invalid property value", async () => {
 | 
			
		||||
        const response = await supertest(app)
 | 
			
		||||
            .patch(`/etapi/branches/${createdBranchId}`)
 | 
			
		||||
            .auth("etapi", token, { "type": "basic"})
 | 
			
		||||
            .send({
 | 
			
		||||
                prefix: 123
 | 
			
		||||
            })
 | 
			
		||||
            .expect(400);
 | 
			
		||||
        expect(response.body.code).toStrictEqual("PROPERTY_VALIDATION_ERROR");
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user