Skip to content

feat(tests): integration suite harness against a real Postgres#55

Merged
CryptoJones merged 1 commit into
masterfrom
feat/integration-test-harness
May 18, 2026
Merged

feat(tests): integration suite harness against a real Postgres#55
CryptoJones merged 1 commit into
masterfrom
feat/integration-test-harness

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Summary

Adds tests/integration/ — a skipIf-gated suite that exercises real Sequelize against a live Postgres when one is reachable. Without DB_PASSWORD set or with the DB unreachable, the entire suite skips and the existing unit + API tests stay green.

Coverage in this first pass:

  • sequelize.authenticate()
  • Customer table existence + findAll
  • Customer create → findByPk → destroy round-trip
  • Eager-load smoke test using the new include({as: 'company'}) association

Cleanup: rows are tagged with a _integ_<pid>_<timestamp> sentinel; afterAll deletes by LIKE so a crashed run doesn't poison the table.

Out of scope: end-to-end HTTP→router→real-DB via supertest, and testcontainers-managed Postgres. Those are natural next passes once this harness is in.

Test plan

  • With DB_PASSWORD unset: vitest reports 29 passed / 1 skipped (this suite), 223 passed / 4 skipped (tests). The 4 skipped are the integration tests, intentionally.
  • With a real PG up + migrations applied: tests should pass end-to-end (not verified in this session — no docker daemon access locally)

See tests/integration/README.md for the bring-up flow.

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

Adds tests/integration/ with a skipIf-gated suite. When DB_PASSWORD
is set AND sequelize.authenticate() succeeds, the tests run for
real against the live database. Otherwise they skip the entire
describe block — \`npm test\` keeps working in environments
without a Postgres reachable (CI without docker, local laptops
that haven't run \`docker compose up postgres\`, etc.).

What the harness covers in this first pass:
  - sequelize.authenticate() succeeds
  - Customer.findAll() returns an array against the real schema
  - Customer create → findByPk → destroy round-trip
  - Eager loading via the new include('company') association
    (smoke test only — verifies the include doesn't throw, since
    the real DB may legitimately be empty)

Each test cleans up its own rows by sentinel-string match
(\`_integ_<pid>_<timestamp>%\` LIKE) so a mid-test crash doesn't
poison subsequent runs. Tests share one connection (afterAll
closes it).

Out of scope here:
  - End-to-end HTTP-through-router-to-real-DB. The current suite
    proves the model layer; the next integration pass should add
    supertest hitting the real router stack.
  - testcontainers-style auto-managed PG container. Would be nice
    but adds a devDep + docker-daemon dependency.

Verified locally: with DB_PASSWORD empty the suite reports
"29 passed | 1 skipped (30) / 223 passed | 4 skipped (227)" —
unit + API tests keep passing untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit b63d3ab into master May 18, 2026
2 of 3 checks passed
@CryptoJones CryptoJones deleted the feat/integration-test-harness branch May 18, 2026 00:02
CryptoJones added a commit that referenced this pull request May 18, 2026
After the harness in #55 landed, the actual flow to run integration
tests against a live Postgres turned out to need three things the
docs didn't mention:

  1. docker-compose.override.yml that exposes 127.0.0.1:5432 to
     the host. The base docker-compose.yml deliberately keeps PG
     unreachable from the host for production hardening, but the
     vitest integration suite needs host-side TCP access.

  2. \`docker compose down -v\` before re-running setup. The
     setup/TimeTracker.sql script does an unconditional
     \`CREATE SCHEMA dbo\` which fails (exit 3) against a
     populated postgres-data volume. Filed as a separate
     idempotency-fix tracker.

  3. The exact env-var shape the integration suite reads
     (DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD).

The override file is committed so contributors don't have to
re-derive it. Production deployments should NOT use this
override — port 5432 on a public host is a credential-brute-force
invitation. The override's purpose and risk note are inline in
the file's comment header.

README gets a short "Testing" section pointing at
tests/integration/README.md for the full flow. The integration
README itself is rewritten end-to-end.

Co-authored-by: Aaron K. Clark <akclark@thenetwerk.net>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CryptoJones added a commit that referenced this pull request May 18, 2026
Continues the docs-sync pattern from #44 and #53. CHANGELOG
[Unreleased] now reflects:

  Added:
    - Sequelize associations (#54)
    - Integration test harness (#55)
    - Postman collection (#59)
    - TLS reverse-proxy compose (#60)
    - docker-compose.override.yml committed (#56)

  Fixed:
    - setup/TimeTracker.sql idempotency (#57) — removes the
      \`docker compose down -v\` workaround

  Docs:
    - Integration bring-up flow (#56, #58)
    - README sections for Testing and Behind TLS

Co-authored-by: Aaron K. Clark <akclark@thenetwerk.net>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant