测试: 添加文件重命名API测试
This commit is contained in:
parent
a63e0e558f
commit
4a407d0fdb
42
tests/backend/rename.test.js
Normal file
42
tests/backend/rename.test.js
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user