UnitTestPlan.md

February 23, 2026 ยท View on GitHub

Hack23 Logo

๐Ÿงช European Parliament MCP Server โ€” Unit Test Plan

๐Ÿ›ก๏ธ Comprehensive Testing Strategy and Coverage Plan
๐Ÿ“Š Ensuring Quality Through Systematic Test Coverage

Owner Version Effective Date Review Cycle

๐Ÿ“‹ 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)


๐Ÿ“‘ Table of Contents


๐ŸŽฏ Purpose

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.


๐Ÿ”ง Test Framework

ComponentToolPurpose
Test RunnerVitestUnit and integration testing
AssertionsVitest expectTest assertions
Mockingvi.mock / vi.fnExternal dependency mocking
Coveragev8 (via Vitest)Code coverage reporting
E2E RunnerVitestEnd-to-end integration tests

๐Ÿ“‚ Test File Convention

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

๐Ÿ“Š Coverage Targets

MetricTargetCurrentStatus
Line Coverageโ‰ฅ 80%80%+โœ…
Branch Coverageโ‰ฅ 70%70%+โœ…
Function Coverageโ‰ฅ 80%80%+โœ…
Security Code Coverageโ‰ฅ 95%90%+โš ๏ธ

๐Ÿ“ˆ Coverage by Module

ModuleTargetPriority
src/tools/85%๐Ÿ”ด Critical
src/clients/80%๐Ÿ”ด Critical
src/schemas/90%๐ŸŸ  High
src/resources/80%๐ŸŸก Medium
src/prompts/75%๐ŸŸก Medium
src/index.ts70%๐ŸŸก Medium

๐Ÿงช Test Categories

1. Unit Tests

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();
  });
});

2. Input Validation Tests

Tests for Zod schema validation on all MCP tool inputs.

Test CaseInputExpected
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)

3. Error Handling Tests

ScenarioExpected Behavior
API timeoutGraceful error with message
API 404Empty result set
API 500Error propagation with context
Network errorRetry or graceful failure
Invalid response formatValidation error
Rate limit exceededRate limit error message

4. Integration Tests

Tests for component interactions (API client + tool handlers).

TestComponentsPurpose
Tool + API clientTool handler, EP clientRequest/response flow
Cache integrationTool handler, LRU cacheCache hit/miss behavior
Rate limiterAPI client, rate limiterThrottling behavior

๐Ÿ“‹ Test Matrix

๐Ÿ”Œ MCP Tool Tests

ToolUnit TestsInput ValidationError HandlingStatus
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

๐ŸŒ API Client Tests

Test AreaTestsStatus
HTTP request constructionURL building, headers, paramsโœ…
Response parsingJSON parsing, type validationโœ…
Error handlingTimeouts, HTTP errors, networkโœ…
Rate limitingRequest throttlingโœ…
Base URL normalizationTrailing slash handlingโœ…
Timeout configurationEnvironment variable validationโœ…

๐Ÿ›ก๏ธ Security Testing

Security TestDescriptionPriority
Input injectionSQL/NoSQL injection via tool params๐Ÿ”ด Critical
XSS via outputMalicious content in EP API responses๐ŸŸ  High
Parameter tamperingInvalid/malicious parameter values๐Ÿ”ด Critical
Rate limit bypassCircumventing rate limiting๐ŸŸก Medium
Error information leakageSensitive data in error messages๐ŸŸ  High
Prototype pollutionObject prototype manipulation๐ŸŸก Medium

๐Ÿ”Œ E2E Testing

๐Ÿ“‹ E2E Test Suite

TestDescriptionTimeout
Full workflowAll 20 tools sequentially65s
MEP queriesCountry/group filtering65s
Voting recordsVote data retrieval65s
Document searchText search functionality65s
Committee infoCommittee data access65s
Error scenariosInvalid inputs, timeouts65s

โš™๏ธ E2E Configuration

EP_REQUEST_TIMEOUT_MS=60000  (API timeout)
E2E_TEST_TIMEOUT_MS=65000    (test timeout = API + 5s overhead)

๐Ÿ”„ CI Integration

๐Ÿ“‹ Test Execution in CI

# Unit tests
npm test

# E2E tests (requires build first)
npm run build
npm run test:e2e

# Coverage report
npm run test:coverage

๐Ÿ“Š Quality Gates

GateThresholdAction on Failure
Unit tests100% passโŒ Block merge
E2E tests100% passโŒ Block merge
Line coverageโ‰ฅ 80%โŒ Block merge
Branch coverageโ‰ฅ 70%โš ๏ธ Warning
ESLint0 errorsโŒ Block merge

๐Ÿ”— Policy Alignment

ISMS PolicyRelevanceLink
๐Ÿ”’ Secure DevelopmentTesting requirements (80%+ coverage)Secure_Development_Policy.md
๐Ÿ” Vulnerability ManagementSecurity test requirementsVulnerability_Management.md
๐Ÿท๏ธ ClassificationRisk-based test prioritizationCLASSIFICATION.md

DocumentDescriptionLink
๐Ÿ“Š Test Coverage ReportHistorical coverage snapshotTEST_COVERAGE_REPORT.md
๐Ÿ“ˆ Current Coverage MetricsLatest generated coverage summary (JSON)coverage/coverage-summary.json
๐Ÿงช Integration TestingIntegration test guide../INTEGRATION_TESTING.md
๐Ÿ›๏ธ ArchitectureSystem architecture../ARCHITECTURE.md
๐Ÿ›ก๏ธ Security ArchitectureSecurity controls tested../SECURITY_ARCHITECTURE.md

This unit test plan is maintained as part of the Hack23 AB ISMS framework.
Licensed under Apache-2.0