veza/apps/web/src/services/developerService.test.ts
senke 57b8b1431e fix(a11y): fix heading hierarchy h1→h3 gaps on 8 pages
Changed h3 section titles to h2 on pages where they directly follow the page h1:
- Library: empty state heading
- Queue: "Now Playing" + "Up Next"
- Search: discovery sections + results sections
- Profile: "About" + "Links"
- Sessions: card title
- Notifications: date group headers

Also: add 'api' binary to .gitignore

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 10:14:18 +01:00

79 lines
2.2 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { developerService } from './developerService';
// Mock the API layer
vi.mock('./api/developer', () => ({
developerApi: {
listKeys: vi.fn().mockResolvedValue([]),
createKey: vi.fn().mockResolvedValue({
id: 'key-1',
name: 'Test Key',
prefix: 'veza_',
scopes: ['read', 'write'],
created_at: '2024-01-01T00:00:00Z',
key: 'veza_test_key_123',
}),
deleteKey: vi.fn().mockResolvedValue(undefined),
},
}));
// Mock webhookService used internally by getStats
vi.mock('./webhookService', () => ({
webhookService: {
list: vi.fn().mockResolvedValue([]),
},
}));
// Mock logger
vi.mock('@/utils/logger', () => ({
logger: { error: vi.fn(), warn: vi.fn(), info: vi.fn(), debug: vi.fn() },
}));
describe('developerService', () => {
beforeEach(() => {
vi.clearAllMocks();
});
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('deleteKey', () => {
it('should delete an API key', async () => {
await expect(developerService.deleteKey('key-1')).resolves.not.toThrow();
});
});
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');
});
});
});