Skip to content

[Testing] Replace placeholder backend test command with deterministic automated tests #4

Description

@VickyKumarOfficial

Problem statement

The backend does not have an executable automated test suite. Its committed test script is a placeholder that always exits with failure:

"test": "echo \"Error: no test specified\" && exit 1"

The root package also has no test script. Existing OpenRouter scripts verify static runtime and configuration invariants, but they do not exercise application behavior.

Impact

  • CI cannot provide a meaningful regression-test gate.
  • Route validation and error handling can regress silently.
  • OpenRouter response parsing and error mapping are untested.
  • Survey persistence and fallback behavior depend on manual verification.

Scope / proposed approach

Choose a Node-compatible runner, such as Vitest or Node's built-in test runner, then:

  1. Replace the backend placeholder test script.
  2. Add deterministic unit tests around pure or mockable service behavior.
  3. Add focused integration tests for Express routes with external dependencies mocked.
  4. Add a root-level test command, or clearly document the frontend/backend commands used by CI.

Priority coverage

OpenRouter provider

  • Successful response normalization.
  • Malformed or empty provider responses.
  • HTTP, authentication, rate-limit, and upstream error mapping.
  • Timeout and network-failure behavior.

AI routes and services

  • Request validation and missing required fields.
  • Service success responses.
  • Stable status and error payloads on failure.
  • Confirmation that tests make no live provider calls.

Survey service

  • Persistence success and failure with a mocked Supabase client.
  • Latest-survey behavior.
  • Malformed AI JSON and fallback behavior.
  • Recommendation-save failures.

Test constraints

  • Do not call live OpenRouter, Supabase, EmailJS, or other production services.
  • Do not require production secrets.
  • Keep fixtures deterministic and small.
  • Tests must clean up their own temporary state.
  • Avoid assertions against unstable log formatting or provider-generated prose.

Acceptance criteria

  • npm --prefix backend test runs real tests.
  • The command exits 0 only when all tests pass and non-zero on failures.
  • Core provider error mapping and response parsing have coverage.
  • At least one representative AI route success path is tested.
  • At least one representative AI route failure path is tested.
  • Survey fallback and persistence behavior are tested with mocks.
  • Tests run without network access or production secrets.
  • Root and CI test commands are documented.
  • GitHub Actions runs the suite.

Verification checklist

npm --prefix backend test
  • Run with network access disabled.
  • Run without production credentials in .env.
  • Deliberately break an assertion and confirm a non-zero exit.
  • Restore the assertion and confirm a clean pass.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions