Skip to main content
Glama

dhis2_generate_test_setup

Generate testing setup and example tests for DHIS2 applications. Configure test frameworks, define test types, set coverage thresholds, and create mock setups for DHIS2 API, DataStore, and authentication.

Instructions

Generate testing setup and example tests for DHIS2 app

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
testFrameworkYesTesting framework to configure
testTypesNoTypes of tests to set up
coverageNo
mockSetupNo

Implementation Reference

  • The primary handler function that generates comprehensive Markdown documentation for DHIS2 app testing setup. It supports multiple frameworks (Jest, Cypress, Playwright), test types (unit, integration, E2E, visual), coverage configuration, and mock setups by composing helper functions to produce ready-to-use config files, examples, and commands.
    export function generateTestSetup(args: any): string {
      const { testFramework, testTypes = [], coverage = {}, mockSetup = {} } = args;
    
      return `# DHIS2 Testing Setup
    
    ## ${testFramework.toUpperCase()} Configuration
    
    ${generateTestFrameworkConfig(testFramework, coverage)}
    
    ${testTypes.includes('unit') ? generateUnitTestExamples() : ''}
    ${testTypes.includes('integration') ? generateIntegrationTestExamples() : ''}
    ${testTypes.includes('e2e') ? generateE2ETestExamples(testFramework) : ''}
    ${testTypes.includes('visual') ? generateVisualTestExamples() : ''}
    
    ${Object.keys(mockSetup).length > 0 ? generateMockConfiguration(mockSetup) : ''}
    
    ## Test Commands
    \`\`\`bash
    # Run all tests
    ${testFramework === 'jest' ? 'npm test' : testFramework === 'cypress' ? 'npx cypress open' : 'npx playwright test'}
    
    # Run with coverage
    ${testFramework === 'jest' ? 'npm test -- --coverage' : 'npm run test:coverage'}
    
    # Run specific test file
    ${testFramework === 'jest' ? 'npm test -- MyComponent.test.js' : testFramework === 'cypress' ? 'npx cypress run --spec "cypress/integration/MyComponent.spec.js"' : 'npx playwright test tests/MyComponent.spec.ts'}
    
    # Watch mode
    ${testFramework === 'jest' ? 'npm test -- --watch' : 'npm run test:watch'}
    \`\`\`
    `;
    }
  • src/index.ts:1127-1137 (registration)
    The tool dispatch logic in the main MCP server CallToolRequest handler. Receives arguments, invokes the generateTestSetup handler, and formats the response as MCP content.
    case 'dhis2_generate_test_setup':
      const testArgs = args as any;
      const testSetup = generateTestSetup(testArgs);
      return {
        content: [
          {
            type: 'text',
            text: testSetup,
          },
        ],
      };
  • Permission mapping in TOOL_PERMISSIONS Map associating the tool with 'canConfigureApps' permission for runtime access control via PermissionSystem.filterToolsByPermissions().
    ['dhis2_generate_test_setup', 'canConfigureApps'],
  • Key helper function called by the handler to generate framework-specific test configuration (jest.config.js, cypress.json, playwright.config.ts) including DHIS2-specific mocks and coverage thresholds.
    function generateTestFrameworkConfig(framework: string, coverage: any): string {
      switch (framework) {
        case 'jest':
          return `### Jest Configuration (jest.config.js)
    \`\`\`javascript
    module.exports = {
      testEnvironment: 'jsdom',
      setupFilesAfterEnv: ['<rootDir>/src/setupTests.js'],
      moduleNameMapping: {
        '\\\\.(css|less|scss|sass)$': 'identity-obj-proxy',
      },
      transform: {
        '^.+\\\\.(js|jsx|ts|tsx)$': 'babel-jest',
      },
      collectCoverageFrom: [
        'src/**/*.{js,jsx,ts,tsx}',
        '!src/index.js',
        '!src/serviceWorker.js',
      ],
      coverageThreshold: {
        global: {
          branches: ${coverage.threshold || 80},
          functions: ${coverage.threshold || 80},
          lines: ${coverage.threshold || 80},
          statements: ${coverage.threshold || 80},
        },
      },
      coverageReporters: ${JSON.stringify(coverage.reports || ['text', 'html'])},
    };
    \`\`\`
    
    ### Setup File (src/setupTests.js)
    \`\`\`javascript
    import '@testing-library/jest-dom';
    import { configure } from '@testing-library/react';
    
    configure({ testIdAttribute: 'data-test' });
    
    // Mock DHIS2 App Runtime
    jest.mock('@dhis2/app-runtime', () => ({
      useDataQuery: jest.fn(),
      useDataMutation: jest.fn(),
      useAlert: jest.fn(() => ({ show: jest.fn() })),
    }));
    \`\`\``;
    
        case 'cypress':
          return `### Cypress Configuration (cypress.json)
    \`\`\`json
    {
      "baseUrl": "http://localhost:3000",
      "integrationFolder": "cypress/integration",
      "fixturesFolder": "cypress/fixtures",
      "supportFile": "cypress/support/index.js",
      "video": true,
      "screenshotOnRunFailure": true,
      "defaultCommandTimeout": 10000,
      "env": {
        "dhis2BaseUrl": "https://play.dhis2.org/2.40.4",
        "dhis2Username": "admin",
        "dhis2Password": "district"
      }
    }
    \`\`\`
    
    ### Cypress Commands (cypress/support/commands.js)
    \`\`\`javascript
    Cypress.Commands.add('loginToDHIS2', (username, password) => {
      cy.request({
        method: 'POST',
        url: \`\${Cypress.env('dhis2BaseUrl')}/api/auth/login\`,
        body: { username, password }
      }).then((resp) => {
        window.localStorage.setItem('dhis2.auth', JSON.stringify(resp.body));
      });
    });
    \`\`\``;
    
        case 'playwright':
          return `### Playwright Configuration (playwright.config.ts)
    \`\`\`typescript
    import { defineConfig, devices } from '@playwright/test';
    
    export default defineConfig({
      testDir: './tests',
      fullyParallel: true,
      forbidOnly: !!process.env.CI,
      retries: process.env.CI ? 2 : 0,
      workers: process.env.CI ? 1 : undefined,
      reporter: 'html',
      use: {
        baseURL: 'http://localhost:3000',
        trace: 'on-first-retry',
      },
      projects: [
        {
          name: 'chromium',
          use: { ...devices['Desktop Chrome'] },
        },
        {
          name: 'firefox',
          use: { ...devices['Desktop Firefox'] },
        },
        {
          name: 'webkit',
          use: { ...devices['Desktop Safari'] },
        },
      ],
      webServer: {
        command: 'npm start',
        port: 3000,
      },
    });
    \`\`\``;
    
        default:
          return '### Custom Test Configuration\n```javascript\n// Add your configuration here\n```';
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool 'generates' setup and tests, implying a write operation that creates files or configurations, but doesn't specify what exactly gets generated (e.g., files, directories, code), whether it modifies existing files, requires specific permissions, or has side effects. For a generative tool with zero annotation coverage, this lack of detail is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence: 'Generate testing setup and example tests for DHIS2 app'. It's front-loaded with the core action and resource, with zero redundant words. Every word earns its place, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (4 parameters with nested objects, no annotations, no output schema), the description is inadequate. It doesn't explain what 'generate' entails (e.g., file outputs, overwrite behavior), how parameters interact, or what the result looks like. For a tool that likely creates multiple artifacts, more context is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions 'testing setup and example tests', which loosely relates to parameters like testFramework and testTypes, but adds minimal semantic value beyond the schema. With 50% schema description coverage (only testFramework and coverage have descriptions), the description doesn't compensate for undocumented parameters like testTypes and mockSetup. It provides a high-level context but no specifics on parameter usage or interactions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Generate testing setup and example tests for DHIS2 app'. It specifies the verb ('generate') and resource ('testing setup and example tests'), and distinguishes it from sibling tools like 'dhis2_android_setup_testing' by focusing on general DHIS2 app testing rather than Android-specific setup. However, it doesn't explicitly contrast with all testing-related siblings, keeping it at 4 rather than 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, appropriate contexts, or compare it to sibling tools like 'dhis2_android_setup_testing' or 'dhis2_setup_dev_environment'. The agent must infer usage from the name and parameters alone, which is insufficient for optimal tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Dradebo/dhis2-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server