From bfd5d30a422ac9f7037c94b997f57a368a582013 Mon Sep 17 00:00:00 2001 From: Test Engineer Date: Tue, 10 Mar 2026 09:02:11 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9B=9E=E6=94=B6=E7=AB=99API=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/backend/trash.test.js | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/backend/trash.test.js diff --git a/tests/backend/trash.test.js b/tests/backend/trash.test.js new file mode 100644 index 0000000..5694709 --- /dev/null +++ b/tests/backend/trash.test.js @@ -0,0 +1,55 @@ +// 回收站 API 测试 +const request = require('supertest'); +const app = require('../../backend/src/index'); + +describe('Trash API', () => { + let token; + + beforeAll(async () => { + const loginRes = await request(app) + .post('/api/auth/login') + .send({ username: 'testuser', password: 'test123' }); + token = loginRes.body.token; + }); + + describe('GET /api/trash', () => { + it('should get trashed files', async () => { + const response = await request(app) + .get('/api/trash') + .set('Authorization', `Bearer ${token}`); + + expect(response.status).toBe(200); + expect(response.body).toHaveProperty('files'); + }); + }); + + describe('POST /api/trash/:id/restore', () => { + it('should restore file', async () => { + const response = await request(app) + .post('/api/trash/1/restore') + .set('Authorization', `Bearer ${token}`); + + expect(response.status).toBe(200); + }); + }); + + describe('DELETE /api/trash/:id', () => { + it('should permanently delete file', async () => { + const response = await request(app) + .delete('/api/trash/1') + .set('Authorization', `Bearer ${token}`); + + expect(response.status).toBe(200); + }); + }); + + describe('POST /api/trash/empty', () => { + it('should empty trash', async () => { + const response = await request(app) + .post('/api/trash/empty') + .set('Authorization', `Bearer ${token}`); + + expect(response.status).toBe(200); + }); + }); +});