diff --git a/tests/backend/recent.test.js b/tests/backend/recent.test.js new file mode 100644 index 0000000..b23fb55 --- /dev/null +++ b/tests/backend/recent.test.js @@ -0,0 +1,41 @@ +// 最近访问 API 测试 +const request = require('supertest'); +const app = require('../../backend/src/index'); + +describe('Recent API', () => { + let token; + + beforeAll(async () => { + const loginRes = await request(app) + .post('/api/auth/login') + .send({ username: 'testuser', password: 'test123' }); + token = loginRes.body.token; + }); + + describe('GET /api/recent', () => { + it('should get recently accessed files', async () => { + const response = await request(app) + .get('/api/recent') + .set('Authorization', `Bearer ${token}`); + + expect(response.status).toBe(200); + expect(response.body).toHaveProperty('files'); + }); + + it('should respect limit parameter', async () => { + const response = await request(app) + .get('/api/recent?limit=5') + .set('Authorization', `Bearer ${token}`); + + expect(response.status).toBe(200); + expect(response.body.files.length).toBeLessThanOrEqual(5); + }); + + it('should reject without token', async () => { + const response = await request(app) + .get('/api/recent'); + + expect(response.status).toBe(401); + }); + }); +});