36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
// 统计 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);
|
|
});
|
|
});
|
|
});
|