测试: 添加文件复制API测试

This commit is contained in:
Test Engineer 2026-03-10 09:14:41 +00:00
parent 5e612ac064
commit 16c37770c4

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