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); + }); + }); +});