Add comprehensive performance monitoring and testing infrastructure
- Implement performance dashboard with real-time metrics tracking - Add React hooks for smart polling, debouncing, and active source lookup - Create Jest testing framework with comprehensive test suites for components, API endpoints, and utilities - Enhance UI components with optimized rendering and memoization - Improve polling efficiency with visibility detection and adaptive intervals 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a66979fb34
commit
c259f0d943
15 changed files with 6320 additions and 94 deletions
76
app/api/__tests__/streams.test.ts
Normal file
76
app/api/__tests__/streams.test.ts
Normal file
|
@ -0,0 +1,76 @@
|
|||
import { GET } from '../streams/route';
|
||||
|
||||
// Mock the database module
|
||||
jest.mock('@/lib/database', () => ({
|
||||
getDatabase: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('/api/streams', () => {
|
||||
let mockDb: any;
|
||||
|
||||
beforeEach(() => {
|
||||
// Create mock database
|
||||
mockDb = {
|
||||
all: jest.fn(),
|
||||
};
|
||||
|
||||
const { getDatabase } = require('@/lib/database');
|
||||
getDatabase.mockResolvedValue(mockDb);
|
||||
});
|
||||
|
||||
describe('GET /api/streams', () => {
|
||||
it('returns all streams successfully', async () => {
|
||||
const mockStreams = [
|
||||
{ id: 1, name: 'Stream 1', url: 'http://example.com/1', obs_source_name: 'Source 1', team_id: 1 },
|
||||
{ id: 2, name: 'Stream 2', url: 'http://example.com/2', obs_source_name: 'Source 2', team_id: 2 },
|
||||
];
|
||||
|
||||
mockDb.all.mockResolvedValue(mockStreams);
|
||||
|
||||
const response = await GET();
|
||||
|
||||
expect(mockDb.all).toHaveBeenCalledWith(
|
||||
expect.stringContaining('SELECT * FROM')
|
||||
);
|
||||
|
||||
const { NextResponse } = require('next/server');
|
||||
expect(NextResponse.json).toHaveBeenCalledWith(mockStreams);
|
||||
});
|
||||
|
||||
it('returns empty array when no streams exist', async () => {
|
||||
mockDb.all.mockResolvedValue([]);
|
||||
|
||||
const response = await GET();
|
||||
|
||||
const { NextResponse } = require('next/server');
|
||||
expect(NextResponse.json).toHaveBeenCalledWith([]);
|
||||
});
|
||||
|
||||
it('handles database errors gracefully', async () => {
|
||||
const dbError = new Error('Database connection failed');
|
||||
mockDb.all.mockRejectedValue(dbError);
|
||||
|
||||
const response = await GET();
|
||||
|
||||
const { NextResponse } = require('next/server');
|
||||
expect(NextResponse.json).toHaveBeenCalledWith(
|
||||
{ error: 'Failed to fetch streams' },
|
||||
{ status: 500 }
|
||||
);
|
||||
});
|
||||
|
||||
it('handles database connection errors', async () => {
|
||||
const connectionError = new Error('Failed to connect to database');
|
||||
const { getDatabase } = require('@/lib/database');
|
||||
getDatabase.mockRejectedValue(connectionError);
|
||||
|
||||
const response = await GET();
|
||||
|
||||
const { NextResponse } = require('next/server');
|
||||
expect(NextResponse.json).toHaveBeenCalledWith(
|
||||
{ error: 'Failed to fetch streams' },
|
||||
{ status: 500 }
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue