Testing Strategy
The Kingisoovitaja system employs a multi-layered testing strategy to ensure reliability, accuracy, and performance.
Testing Pyramid
Unit Tests
Coverage Target: >80%
Focus areas:
- Context extraction logic
- Search query generation
- Diversity algorithms
- Validation functions
- Utility functions
Example:
describe('Context Extraction', () => {
it('extracts product type from query', () => {
const context = extractContext('näita raamatuid');
expect(context.productType).toBe('Raamat');
expect(context.intent).toBe('product_search');
expect(context.language).toBe('et');
});
it('handles budget constraints', () => {
const context = extractContext('kuni 30 eurot');
expect(context.budget?.max).toBe(30);
expect(context.budget?.min).toBeUndefined();
});
});
Integration Tests
Coverage Target: >70%
Focus areas:
- API route handling
- Database queries
- Pipeline orchestration
- Context preservation
- Search flow
Example:
describe('Search Pipeline', () => {
it('returns products matching context', async () => {
const context = {
productType: 'Raamat',
category: 'Ilukirjandus',
budget: { max: 30 }
};
const results = await searchOrchestrator.orchestrate(context);
expect(results.products).toHaveLength(3);
expect(results.products[0].price).toBeLessThanOrEqual(30);
expect(results.searchDurationMs).toBeLessThan(1500);
});
});
End-to-End Tests
Coverage Target: Critical flows 100%
Critical flows:
- Simple product search
- Show more pagination
- Budget refinement
- Author search
- Multi-language switching
- Error recovery
Example:
describe('User Flow: Show More', () => {
it('maintains context across requests', async () => {
// Turn 1: Initial search
await userTypes('raamatud');
await waitFor(() => screen.getAllByTestId('product-card'));
const firstProducts = getProductIds();
expect(firstProducts).toHaveLength(3);
// Turn 2: Show more
await userTypes('näita rohkem');
await waitFor(() => screen.getAllByTestId('product-card'));
const allProducts = getProductIds();
expect(allProducts).toHaveLength(6);
// Verify no duplicates
const unique = new Set(allProducts);
expect(unique.size).toBe(6);
});
});
Testing Tools
Frontend
- Jest - Unit testing framework
- React Testing Library - Component testing
- MSW - API mocking
- Playwright - E2E testing
Backend
- Vitest - Fast unit testing
- Supertest - API testing
- Test Containers - Database testing
Test Execution
Performance Testing
Load Testing
describe('Load Tests', () => {
it('handles 100 concurrent requests', async () => {
const requests = Array(100).fill(null).map(() =>
fetch('/api/chat', { method: 'POST', body: testPayload })
);
const start = Date.now();
const results = await Promise.all(requests);
const duration = Date.now() - start;
expect(results.every(r => r.ok)).toBe(true);
expect(duration).toBeLessThan(5000); // Parallel processing
});
});
Benchmark Testing
describe('Benchmarks', () => {
it('context extraction completes in <1s', async () => {
const start = performance.now();
await extractContext('näita raamatuid');
const duration = performance.now() - start;
expect(duration).toBeLessThan(1000);
});
it('diversity selection completes in <20ms', () => {
const start = performance.now();
selectDiverseProducts(candidates, 3);
const duration = performance.now() - start;
expect(duration).toBeLessThan(20);
});
});
Test Data Management
Mock Products
const MOCK_PRODUCTS = {
books: [
{
id: 'test-1',
title: 'Harry Potter',
authors: 'J.K. Rowling',
category: 'Ilukirjandus',
price: 25.00
}
],
giftCards: [
{
id: 'test-gc-1',
title: 'Kinkekaart 20€',
category: 'Kinkekaardid',
price: 20.00
}
]
};
Test Conversations
const TEST_CONVERSATIONS = {
simpleSearch: [
{ role: 'user', content: 'raamatud' },
{ role: 'assistant', content: '[Products shown]' }
],
showMore: [
{ role: 'user', content: 'raamatud' },
{ role: 'assistant', content: '[Products A,B,C]' },
{ role: 'user', content: 'näita rohkem' },
{ role: 'assistant', content: '[Products D,E,F]' }
]
};
Continuous Integration
# .github/workflows/test.yml
name: Test Pipeline
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Type check
run: npm run type-check
- name: Unit tests
run: npm test
- name: Integration tests
run: npm run test:integration
- name: E2E tests
run: npm run test:e2e
- name: Build
run: npm run build
Quality Gates
Pre-commit
- Linting passes
- Type checking passes
- Unit tests pass
- No TODO/FIXME in committed code
Pre-merge
- All tests pass
- Coverage threshold met
- Performance benchmarks pass
- Code review approved
Pre-deploy
- E2E tests pass
- Load tests pass
- No critical errors in logs
- Smoke tests on staging pass
Test Coverage
Current Coverage:
Overall: 82%
─────────────────
Frontend: 85%
- Components: 90%
- Hooks: 88%
- Utils: 92%
Backend: 78%
- API Routes: 75%
- Orchestrators: 82%
- Services: 85%
- Utils: 90%
Critical Paths: 95%
Related Documentation
- Performance Monitoring - Metrics and benchmarks
- Code Standards - Quality guidelines
- Quality Overview - Quality assurance strategy