Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Automated Integration Testing for API Routes via Vitest and @nuxt/test-utils #86

Open
2 of 3 tasks
nathanchase opened this issue Oct 31, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@nathanchase
Copy link

nathanchase commented Oct 31, 2024

Description

With Nuxt API Party’s capability to auto-generate routes from backend OpenAPI schemas, it would be beneficial to introduce automatic integration testing using Vitest and @nuxt/test-utils. This feature would verify each endpoint's validity as specified in the OpenAPI schema through automatically generated integration tests, enhancing API reliability and easing development.

Proposed Feature

1. OpenAPI Schema-Based Test Generation:

  • Use the OpenAPI schema provided to Nuxt API Party to generate integration tests for each endpoint.
  • Create a test for each HTTP method and endpoint path, validating expected request/response types, query parameters, headers, and request bodies (when applicable).

2. Type Validation:

  • Utilize the TypeScript definitions generated from openapi-typescript to ensure each request and response aligns with the types provided by the schema.
  • Test cases could automatically verify that each endpoint uses the correct path and parameter types, ensuring compatibility with the defined API schema.

3. Error-Handling Cases:

  • Generate tests to check error handling for required path parameters and query parameters to ensure informative feedback when misconfigured.
  • Validate handling of HTTP errors and unsupported methods if encountered.

4. Testing Configuration:

  • Use Vitest and @nuxt/test-utils for managing and running tests. The configuration would allow tests to run locally during development and automatically in CI/CD pipelines.
  • Optionally, allow developers to specify subsets of endpoints to test (e.g., by method (GET, POST, etc.) or path prefix).

Automatic Test Coverage for New Endpoints:

  • As new endpoints are added to the schema, integration tests would automatically be created based on the updated schema.
  • This would reduce manual testing requirements and ensure consistency in endpoint testing as APIs evolve.

Benefits

  • Enhanced Reliability: Ensures that all API endpoints adhere to the schema, reducing errors and improving client and server interaction.
  • Development Efficiency: Automating these tests minimizes the need for manual testing, ensuring rapid feedback on API integrity.
  • Reduced Maintenance: Automatically updating tests based on schema changes eliminates the need for repetitive test setup.

Suggested Implementation

Integrate this feature as an optional setting in nuxt.config.ts under apiParty, such as:

export default defineNuxtConfig({
  apiParty: {
    myApi: {
      url: process.env.MY_API_API_BASE_URL!,
      schema: './schemas/myApi.yaml',
      autoTest: true // Optional auto-test flag
    }
  }
});

Additional information

  • Would you be willing to help implement this feature?
  • Can you think of other implementations of this feature?

Final checks

@johannschopplich johannschopplich added enhancement New feature or request and removed pending triage labels Oct 31, 2024
@johannschopplich
Copy link
Owner

What a wholesome idea, I like it! However, since the implementation requires quite some time, won't be able to work on it for now.

Feel free to give it a start a PR! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants