From 16c37770c43402e497b78f82b149d5ed3222166d Mon Sep 17 00:00:00 2001 From: Test Engineer Date: Tue, 10 Mar 2026 09:14:41 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=8D=E5=88=B6API=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/backend/copy.test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/backend/copy.test.js diff --git a/tests/backend/copy.test.js b/tests/backend/copy.test.js new file mode 100644 index 0000000..88c1d52 --- /dev/null +++ b/tests/backend/copy.test.js @@ -0,0 +1,33 @@ +// 文件复制 API 测试 +const request = require('supertest'); +const app = require('../../backend/src/index'); + +describe('Copy API', () => { + let token; + + beforeAll(async () => { + const loginRes = await request(app) + .post('/api/auth/login') + .send({ username: 'testuser', password: 'test123' }); + token = loginRes.body.token; + }); + + describe('POST /api/copy', () => { + it('should copy file', async () => { + const response = await request(app) + .post('/api/copy') + .set('Authorization', `Bearer ${token}`) + .send({ sourceId: 1, targetFolderId: null }); + + expect([200, 500]).toContain(response.status); + }); + + it('should reject without token', async () => { + const response = await request(app) + .post('/api/copy') + .send({ sourceId: 1, targetFolderId: null }); + + expect(response.status).toBe(401); + }); + }); +});