- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler - veza-common: logging, metrics, traits, validation, random - veza-stream-server: audio pipeline, codecs, cache, monitoring, routes - apps/web/dist_verification: refresh build assets (content-hashed filenames) Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { developerService } from './developerService';
|
|
|
|
// Mock webhookService used internally by getStats
|
|
vi.mock('./webhookService', () => ({
|
|
webhookService: {
|
|
list: vi.fn().mockResolvedValue([]),
|
|
},
|
|
}));
|
|
|
|
describe('developerService', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
// Clear localStorage for consistent test behavior
|
|
localStorage.clear();
|
|
sessionStorage.clear();
|
|
});
|
|
|
|
describe('listKeys', () => {
|
|
it('should return empty array when no keys stored', async () => {
|
|
const keys = await developerService.listKeys();
|
|
|
|
expect(keys).toBeDefined();
|
|
expect(Array.isArray(keys)).toBe(true);
|
|
expect(keys.length).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('createKey', () => {
|
|
it('should create a new API key', async () => {
|
|
const newKey = await developerService.createKey({
|
|
name: 'Test Key',
|
|
scopes: ['read', 'write'],
|
|
});
|
|
|
|
expect(newKey).toBeDefined();
|
|
expect(newKey.name).toBe('Test Key');
|
|
expect(newKey.scopes).toEqual(['read', 'write']);
|
|
expect(newKey.status).toBe('active');
|
|
expect(newKey).toHaveProperty('id');
|
|
expect(newKey).toHaveProperty('prefix');
|
|
});
|
|
});
|
|
|
|
describe('revokeKey', () => {
|
|
it('should revoke an API key', async () => {
|
|
const result = await developerService.revokeKey('key-1');
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result.success).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('getStats', () => {
|
|
it('should return developer statistics', async () => {
|
|
const stats = await developerService.getStats();
|
|
|
|
expect(stats).toBeDefined();
|
|
expect(stats).toHaveProperty('requests_24h');
|
|
expect(stats).toHaveProperty('avg_latency');
|
|
expect(stats).toHaveProperty('active_keys');
|
|
});
|
|
});
|
|
});
|