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