测试: 添加搜索API测试
This commit is contained in:
parent
4f469c051d
commit
78e945f31b
41
tests/backend/search.test.js
Normal file
41
tests/backend/search.test.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// 搜索 API 测试
|
||||||
|
const request = require('supertest');
|
||||||
|
const app = require('../../backend/src/index');
|
||||||
|
|
||||||
|
describe('Search 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/search', () => {
|
||||||
|
it('should search files', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.get('/api/search?q=test')
|
||||||
|
.set('Authorization', `Bearer ${token}`);
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body).toHaveProperty('files');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject short query', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.get('/api/search?q=a')
|
||||||
|
.set('Authorization', `Bearer ${token}`);
|
||||||
|
|
||||||
|
expect(response.status).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should filter by type', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.get('/api/search?q=test&type=folder')
|
||||||
|
.set('Authorization', `Bearer ${token}`);
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user