2026-01-07 09:33:52 +00:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
|
import { adminService } from './adminService';
|
|
|
|
|
|
|
|
|
|
// Mock fetch pour les tests
|
|
|
|
|
global.fetch = vi.fn();
|
|
|
|
|
|
|
|
|
|
describe('adminService', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getModerationQueue', () => {
|
|
|
|
|
it('should return reports filtered by status', async () => {
|
|
|
|
|
const reports = await adminService.getModerationQueue('all');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(reports).toBeDefined();
|
|
|
|
|
expect(Array.isArray(reports)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should filter reports by status', async () => {
|
|
|
|
|
const reports = await adminService.getModerationQueue('pending');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(reports).toBeDefined();
|
|
|
|
|
expect(Array.isArray(reports)).toBe(true);
|
|
|
|
|
// Tous les rapports devraient avoir le statut 'pending' ou être vide
|
|
|
|
|
if (reports.length > 0) {
|
2026-01-13 18:47:57 +00:00
|
|
|
reports.forEach((report) => {
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(report.status).toBe('pending');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('resolveReport', () => {
|
|
|
|
|
it('should resolve a report successfully', async () => {
|
|
|
|
|
const result = await adminService.resolveReport('report-1', 'approved');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(result).toBeDefined();
|
|
|
|
|
expect(result.success).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle different actions', async () => {
|
|
|
|
|
const actions = ['approved', 'rejected', 'dismissed'];
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
for (const action of actions) {
|
|
|
|
|
const result = await adminService.resolveReport('report-1', action);
|
|
|
|
|
expect(result.success).toBe(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getRecentUploads', () => {
|
|
|
|
|
it('should return recent uploads', async () => {
|
|
|
|
|
const uploads = await adminService.getRecentUploads();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(uploads).toBeDefined();
|
|
|
|
|
expect(Array.isArray(uploads)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getDashboardStats', () => {
|
|
|
|
|
it('should return dashboard statistics', async () => {
|
|
|
|
|
const stats = await adminService.getDashboardStats();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(stats).toBeDefined();
|
|
|
|
|
expect(stats).toHaveProperty('totalUsers');
|
|
|
|
|
expect(stats).toHaveProperty('monthlyRevenue');
|
|
|
|
|
expect(stats).toHaveProperty('activeSessions');
|
|
|
|
|
expect(stats).toHaveProperty('pendingReports');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|