From 52bd9bb1c21b3758095fbe41c711f2f5c21bebbe Mon Sep 17 00:00:00 2001 From: Test Engineer Date: Tue, 10 Mar 2026 09:10:06 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=9C=80=E8=BF=91=E8=AE=BF=E9=97=AEAPI=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/backend/recent.test.js | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/backend/recent.test.js 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); + }); + }); +});