๐งช European Parliament MCP Server โ Unit Test Plan
๐ก๏ธ Comprehensive Testing Strategy and Coverage Plan
๐ Ensuring Quality Through Systematic Test Coverage
๐ Document Owner: CEO | ๐ Version: 1.0 | ๐
Last Updated: 2026-02-20 (UTC)
๐ Review Cycle: Quarterly | โฐ Next Review: 2026-05-20
๐ท๏ธ Classification: Public (Open Source MCP Server)
This unit test plan defines the testing strategy, coverage targets, and quality gates for the European Parliament MCP Server. It ensures comprehensive validation of all MCP tools, API client functionality, input validation, and error handling.
| Component | Tool | Purpose |
|---|
| Test Runner | Vitest | Unit and integration testing |
| Assertions | Vitest expect | Test assertions |
| Mocking | vi.mock / vi.fn | External dependency mocking |
| Coverage | v8 (via Vitest) | Code coverage reporting |
| E2E Runner | Vitest | End-to-end integration tests |
src/
โโโ tools/
โ โโโ getMEPs.ts
โ โโโ getMEPs.test.ts โ Colocated unit tests
โ โโโ getVotingRecords.ts
โ โโโ getVotingRecords.test.ts
โโโ clients/
โ โโโ europeanParliamentClient.ts
โ โโโ europeanParliamentClient.test.ts
tests/
โโโ e2e/
โ โโโ fullWorkflow.e2e.test.ts โ E2E integration tests
โ โโโ mepQueries.e2e.test.ts
| Metric | Target | Current | Status |
|---|
| Line Coverage | โฅ 80% | 80%+ | โ
|
| Branch Coverage | โฅ 70% | 70%+ | โ
|
| Function Coverage | โฅ 80% | 80%+ | โ
|
| Security Code Coverage | โฅ 95% | 90%+ | โ ๏ธ |
| Module | Target | Priority |
|---|
src/tools/ | 85% | ๐ด Critical |
src/clients/ | 80% | ๐ด Critical |
src/schemas/ | 90% | ๐ High |
src/resources/ | 80% | ๐ก Medium |
src/prompts/ | 75% | ๐ก Medium |
src/index.ts | 70% | ๐ก Medium |
Tests for individual functions and modules in isolation.
describe('get_meps Tool', () => {
it('should return MEPs filtered by country', async () => {
// Mock EP API response
vi.mock('../clients/europeanParliamentClient');
const result = await getMeps({ country: 'SE' });
expect(result).toBeDefined();
expect(Array.isArray(result)).toBe(true);
});
it('should handle API errors gracefully', async () => {
// Mock API error
vi.mocked(epClient.get).mockRejectedValue(new Error('API Error'));
await expect(getMeps()).rejects.toThrow();
});
});
Tests for Zod schema validation on all MCP tool inputs.
| Test Case | Input | Expected |
|---|
| Valid country code | { country: "SE" } | โ
Pass |
| Invalid country code | { country: "XX" } | โ Validation error (invalid country code rejected) |
| Empty string | { country: "" } | โ Validation error (empty string rejected) |
| Missing required field | {} | โ Validation error (required field missing) |
| Injection attempt | { country: "'; DROP TABLE--" } | โ Validation error (malformed input rejected) |
| Excessive length | { country: "A".repeat(1000) } | โ Validation error (excessive length rejected) |
| Scenario | Expected Behavior |
|---|
| API timeout | Graceful error with message |
| API 404 | Empty result set |
| API 500 | Error propagation with context |
| Network error | Retry or graceful failure |
| Invalid response format | Validation error |
| Rate limit exceeded | Rate limit error message |
Tests for component interactions (API client + tool handlers).
| Test | Components | Purpose |
|---|
| Tool + API client | Tool handler, EP client | Request/response flow |
| Cache integration | Tool handler, LRU cache | Cache hit/miss behavior |
| Rate limiter | API client, rate limiter | Throttling behavior |
| Tool | Unit Tests | Input Validation | Error Handling | Status |
|---|
get_meps | โ
| โ
| โ
| Complete |
get_plenary_sessions | โ
| โ
| โ
| Complete |
get_voting_records | โ
| โ
| โ
| Complete |
search_documents | โ
| โ
| โ
| Complete |
get_committee_info | โ
| โ
| โ
| Complete |
get_parliamentary_questions | โ
| โ
| โ
| Complete |
analyze_voting_patterns | โ
| โ
| โ
| Complete |
track_legislation | โ
| โ
| โ
| Complete |
get_mep_details | โ
| โ
| โ
| Complete |
generate_report | โ
| โ
| โ
| Complete |
assess_mep_influence | โ
| โ
| โ
| Complete |
analyze_coalition_dynamics | โ
| โ
| โ
| Complete |
detect_voting_anomalies | โ
| โ
| โ
| Complete |
compare_political_groups | โ
| โ
| โ
| Complete |
analyze_legislative_effectiveness | โ
| โ
| โ
| Complete |
monitor_legislative_pipeline | โ
| โ
| โ
| Complete |
analyze_committee_activity | โ
| โ
| โ
| Complete |
track_mep_attendance | โ
| โ
| โ
| Complete |
analyze_country_delegation | โ
| โ
| โ
| Complete |
generate_political_landscape | โ
| โ
| โ
| Complete |
| Test Area | Tests | Status |
|---|
| HTTP request construction | URL building, headers, params | โ
|
| Response parsing | JSON parsing, type validation | โ
|
| Error handling | Timeouts, HTTP errors, network | โ
|
| Rate limiting | Request throttling | โ
|
| Base URL normalization | Trailing slash handling | โ
|
| Timeout configuration | Environment variable validation | โ
|
| Security Test | Description | Priority |
|---|
| Input injection | SQL/NoSQL injection via tool params | ๐ด Critical |
| XSS via output | Malicious content in EP API responses | ๐ High |
| Parameter tampering | Invalid/malicious parameter values | ๐ด Critical |
| Rate limit bypass | Circumventing rate limiting | ๐ก Medium |
| Error information leakage | Sensitive data in error messages | ๐ High |
| Prototype pollution | Object prototype manipulation | ๐ก Medium |
| Test | Description | Timeout |
|---|
| Full workflow | All 20 tools sequentially | 65s |
| MEP queries | Country/group filtering | 65s |
| Voting records | Vote data retrieval | 65s |
| Document search | Text search functionality | 65s |
| Committee info | Committee data access | 65s |
| Error scenarios | Invalid inputs, timeouts | 65s |
EP_REQUEST_TIMEOUT_MS=60000 (API timeout)
E2E_TEST_TIMEOUT_MS=65000 (test timeout = API + 5s overhead)
# Unit tests
npm test
# E2E tests (requires build first)
npm run build
npm run test:e2e
# Coverage report
npm run test:coverage
| Gate | Threshold | Action on Failure |
|---|
| Unit tests | 100% pass | โ Block merge |
| E2E tests | 100% pass | โ Block merge |
| Line coverage | โฅ 80% | โ Block merge |
| Branch coverage | โฅ 70% | โ ๏ธ Warning |
| ESLint | 0 errors | โ Block merge |
This unit test plan is maintained as part of the Hack23 AB ISMS framework.
Licensed under Apache-2.0