Skip to content

Add test coverage for the api-keys lifecycle and prefix deletion #83

Description

@mikewheeleer

Test the API-key create, list, and delete lifecycle

Description

The api-key endpoints in src/index.tsPOST /api/v1/api-keys, GET /api/v1/api-keys, and DELETE /api/v1/api-keys/:prefix — have no tests. The srk_ key format, the 1–64 char label validation, the list projection that returns only the 8-char prefix (never the raw key), and the prefix-match deletion (including the 404 path) are all uncovered. This issue adds end-to-end lifecycle coverage.

Requirements and context

  • Repository scope: StableRoute-Org/Stableroute-backend only.
  • Assert POST returns 201 with a key starting srk_ and the echoed label.
  • Assert POST rejects an empty label and a label over 64 chars with 400 invalid_request and requestId.
  • Assert GET returns items containing prefix, label, createdAt and never the full key.
  • Assert DELETE /api/v1/api-keys/:prefix removes the key (204) using the 8-char prefix, and that an unknown prefix returns 404 not_found.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/api-keys-35-lifecycle
  • Implement changes
    • Write comprehensive tests in: create src/__tests__/apiKeys.test.ts.
    • Add documentation: none beyond test names.
    • Derive the prefix from the created key for the delete step.
    • Validate security: explicitly assert the raw key never appears in the list response.
  • Test and commit

Test and commit

  • Run npm run build, npm run lint, and npm test.
  • Cover edge cases: empty label, 65-char label, delete by valid prefix, delete unknown prefix.
  • Paste the full npm test output and a coverage summary in the PR.

Example commit message

test(api-keys): cover create/list/delete lifecycle and prefix match

Guidelines

  • Minimum 95 percent test coverage for impacted code.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions