2026-01-07 09:33:52 +00:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
|
import { analyticsService } from './analyticsService';
|
|
|
|
|
|
|
|
|
|
describe('analyticsService', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('recordEvent', () => {
|
|
|
|
|
it('should record an event successfully', async () => {
|
|
|
|
|
const result = await analyticsService.recordEvent('test_event', {});
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(result).toBeUndefined(); // recordEvent retourne void
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle different event types', async () => {
|
|
|
|
|
const events = ['click', 'view', 'download', 'play'];
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
for (const event of events) {
|
|
|
|
|
await analyticsService.recordEvent(event, {});
|
|
|
|
|
}
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
// Si on arrive ici sans erreur, c'est bon
|
|
|
|
|
expect(true).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getGlobalStats', () => {
|
|
|
|
|
it('should return global statistics', async () => {
|
|
|
|
|
const stats = await analyticsService.getGlobalStats();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(stats).toBeDefined();
|
|
|
|
|
expect(stats).toHaveProperty('total_tracks');
|
|
|
|
|
expect(stats).toHaveProperty('total_plays');
|
2026-02-15 15:21:20 +00:00
|
|
|
expect(stats).toHaveProperty('total_revenue');
|
|
|
|
|
expect(stats).toHaveProperty('followers');
|
2026-01-07 09:33:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle different time ranges', async () => {
|
2026-02-15 15:21:20 +00:00
|
|
|
const ranges = ['7d', '30d', '90d'];
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
for (const range of ranges) {
|
|
|
|
|
const stats = await analyticsService.getGlobalStats(range);
|
|
|
|
|
expect(stats).toBeDefined();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getTopTracks', () => {
|
|
|
|
|
it('should return top tracks', async () => {
|
|
|
|
|
const tracks = await analyticsService.getTopTracks();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(tracks).toBeDefined();
|
|
|
|
|
expect(Array.isArray(tracks)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle different time ranges', async () => {
|
2026-02-15 15:21:20 +00:00
|
|
|
const ranges = ['7d', '30d', '90d'];
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
for (const range of ranges) {
|
|
|
|
|
const tracks = await analyticsService.getTopTracks(range);
|
|
|
|
|
expect(Array.isArray(tracks)).toBe(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getTrafficSources', () => {
|
|
|
|
|
it('should return traffic sources', async () => {
|
|
|
|
|
const sources = await analyticsService.getTrafficSources();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(sources).toBeDefined();
|
|
|
|
|
expect(Array.isArray(sources)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|