diff --git a/tests/backend/copy.test.js b/tests/backend/copy.test.js new file mode 100644 index 0000000..88c1d52 --- /dev/null +++ b/tests/backend/copy.test.js @@ -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); + }); + }); +});