34 lines
914 B
JavaScript
34 lines
914 B
JavaScript
// 文件复制 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);
|
|
});
|
|
});
|
|
});
|