test: Add integration tests for webhooks + unit tests for requireApiKey middleware#741
Merged
Jayy4rl merged 2 commits intoJun 29, 2026
Conversation
|
@jayteemoney Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds automated test coverage for two areas of the backend API:
requireApiKeymiddleware #693 — Unit tests for therequireApiKeyauthentication middleware.All new tests use the project's existing Vitest + Supertest stack and follow the established mocking patterns (
vi.mock("../../db/index.js")). They are fully isolated and fast — no real database, network, or DNS access.#690 — Webhook endpoint integration tests
File:
backend/src/api/controllers/webhooks.integration.test.tsExercises the real router stack (auth → validation → controller) mounted on a minimal Express app, mirroring how
app.tswires/api/v1/webhooks:POST /api/v1/webhooks— valid body →201; non-HTTPS URL →400; missing/emptyevents→400; no auth →401.GET /api/v1/webhooks— no auth →401; valid auth →200+ array (and asserts secrets are never exposed); empty list →200+[].DELETE /api/v1/webhooks/:id— not found →404; success →204; non-numeric id →400; no auth →401.The DB layer and
NotificationService/validateWebhookUrlare mocked at module level.#693 —
requireApiKeymiddleware unit testsFile:
backend/src/api/middleware/auth.test.tsAuthorizationheader →401 Unauthorized.Bearerprefix /Basicscheme) →401.403(fails closed).403 Insufficient permissions.next()and attachesreq.apiKey.next().The database query is mocked; no real DB is hit.
Test results
Both files pass ESLint and are type-clean.
Notes for the maintainer
While wiring the integration test I noticed two pre-existing issues on
main(not introduced here, left untouched to keep this PR focused):src/api/controllers/vaults.tsdeclaresgetVaultOperatorstwice (lines 410 and 986), which breaks the esbuild/tsc transform for anything importing the full app. The integration test mounts only the webhooks router to stay unaffected.src/api/controllers/webhooks.test.tshas an assertion that predates theconsecutiveFailuresfield added toformatWebhook, so that existing test currently fails.Closes #690
Closes #693