测试: 添加文件复制API测试
This commit is contained in:
parent
5e612ac064
commit
16c37770c4
33
tests/backend/copy.test.js
Normal file
33
tests/backend/copy.test.js
Normal file
@ -0,0 +1,33 @@
|
||||
// 文件复制 API 测试
|
||||
const request = require('supertest');
|
||||
const app = require('../../backend/src/index');
|
||||
|
||||
describe('Copy API', () => {
|
||||
let token;
|
||||
|
||||
beforeAll(async () => {
|
||||
const loginRes = await request(app)
|
||||
.post('/api/auth/login')
|
||||
.send({ username: 'testuser', password: 'test123' });
|
||||
token = loginRes.body.token;
|
||||
});
|
||||
|
||||
describe('POST /api/copy', () => {
|
||||
it('should copy file', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/copy')
|
||||
.set('Authorization', `Bearer ${token}`)
|
||||
.send({ sourceId: 1, targetFolderId: null });
|
||||
|
||||
expect([200, 500]).toContain(response.status);
|
||||
});
|
||||
|
||||
it('should reject without token', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/copy')
|
||||
.send({ sourceId: 1, targetFolderId: null });
|
||||
|
||||
expect(response.status).toBe(401);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user