测试: 添加回收站API测试
This commit is contained in:
parent
8cb8e262bc
commit
bfd5d30a42
55
tests/backend/trash.test.js
Normal file
55
tests/backend/trash.test.js
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user