Skip to content

test(healthz): cover db_error field on the 503 degraded path (#320)#321

Merged
CryptoJones merged 1 commit into
masterfrom
test/healthz-db-error-on-degraded
May 19, 2026
Merged

test(healthz): cover db_error field on the 503 degraded path (#320)#321
CryptoJones merged 1 commit into
masterfrom
test/healthz-db-error-on-degraded

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Closes #320.

Summary

Adds a behavioral test that stubs db.sequelize.query to reject, then drives /healthz end-to-end. Pins the 503 shape (status: 'degraded', db: 'down', db_error non-empty string, migration: null) so a future controller refactor that drops the field would fail CI.

Test plan

  • npm run lint && npm test — 782 passing (was 781).

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

The OpenAPI spec pins `db_error` on the /healthz 503 schema (see
tests/api/openapi.test.js — operators rely on the field for
debugging a degraded probe). But there was no behavioral assertion
that the field actually appears when the SELECT 1 probe rejects;
a future controller refactor could silently drop the field and
the spec-shape test wouldn't catch the runtime divergence.

Add a test that swaps `db.sequelize.query` to a rejecting stub,
then drives /healthz end-to-end via supertest. Asserts the 503
status, the `status: 'degraded'` + `db: 'down'` shape, that the
`db_error` field is a non-empty string, and that `migration`
remains null (the SequelizeMeta probe never gets a chance to
run when SELECT 1 already threw).

Doesn't pin the error message — it varies by pg connection mode
(no-host, no-password, refused, etc.). The structural assertion
is enough to catch a regression.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit d1c946e into master May 19, 2026
3 checks passed
@CryptoJones CryptoJones deleted the test/healthz-db-error-on-degraded branch May 19, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(healthz): missing behavioral coverage for db_error field on 503 path

1 participant