测试: 添加统计API测试
This commit is contained in:
parent
24d72ddfd2
commit
9704f6da71
35
tests/backend/stats.test.js
Normal file
35
tests/backend/stats.test.js
Normal file
@ -0,0 +1,35 @@
|
||||
// 统计 API 测试
|
||||
const request = require('supertest');
|
||||
const app = require('../../backend/src/index');
|
||||
|
||||
describe('Stats 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/stats', () => {
|
||||
it('should get user statistics', async () => {
|
||||
const response = await request(app)
|
||||
.get('/api/stats')
|
||||
.set('Authorization', `Bearer ${token}`);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body).toHaveProperty('totalFiles');
|
||||
expect(response.body).toHaveProperty('storageUsed');
|
||||
expect(response.body).toHaveProperty('trashCount');
|
||||
expect(response.body).toHaveProperty('shareCount');
|
||||
});
|
||||
|
||||
it('should reject without token', async () => {
|
||||
const response = await request(app)
|
||||
.get('/api/stats');
|
||||
|
||||
expect(response.status).toBe(401);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user