From 4a407d0fdbe3148f3dc1ca8af23c706cf6b5e6f4 Mon Sep 17 00:00:00 2001 From: Test Engineer Date: Tue, 10 Mar 2026 09:12:36 +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=E9=87=8D=E5=91=BD=E5=90=8DAPI=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/backend/rename.test.js | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/backend/rename.test.js diff --git a/tests/backend/rename.test.js b/tests/backend/rename.test.js new file mode 100644 index 0000000..1bc5225 --- /dev/null +++ b/tests/backend/rename.test.js @@ -0,0 +1,42 @@ +// 文件重命名 API 测试 +const request = require('supertest'); +const app = require('../../backend/src/index'); + +describe('Rename API', () => { + let token; + + beforeAll(async () => { + const loginRes = await request(app) + .post('/api/auth/login') + .send({ username: 'testuser', password: 'test123' }); + token = loginRes.body.token; + }); + + describe('PUT /api/rename/:id', () => { + it('should rename file', async () => { + const response = await request(app) + .put('/api/rename/1') + .set('Authorization', `Bearer ${token}`) + .send({ name: 'new-filename.pdf' }); + + expect([200, 404]).toContain(response.status); + }); + + it('should reject empty name', async () => { + const response = await request(app) + .put('/api/rename/1') + .set('Authorization', `Bearer ${token}`) + .send({ name: '' }); + + expect(response.status).toBe(400); + }); + + it('should reject without token', async () => { + const response = await request(app) + .put('/api/rename/1') + .send({ name: 'test.pdf' }); + + expect(response.status).toBe(401); + }); + }); +});