mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 07:01:31 +08:00 
			
		
		
		
	test(etapi): port export note subtree
This commit is contained in:
		
							parent
							
								
									94cb18589a
								
							
						
					
					
						commit
						3dfe2ce066
					
				@ -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");
 | 
			
		||||
%}
 | 
			
		||||
							
								
								
									
										51
									
								
								apps/server/spec/etapi/export-note-subtree.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								apps/server/spec/etapi/export-note-subtree.spec.ts
									
									
									
									
									
										Normal 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");
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user