Skip to content

test: fix test suite bugs#407

Open
leowla wants to merge 4 commits into
masterfrom
vps-19-test-coverage
Open

test: fix test suite bugs#407
leowla wants to merge 4 commits into
masterfrom
vps-19-test-coverage

Conversation

@leowla
Copy link
Copy Markdown
Member

@leowla leowla commented May 20, 2026

Issue

  • the Express error handler had wrong arity (2 params instead of 4),
  • nextFunction mock was never cleared between tests causing cross-test contamination
  • deprecated Mongoose connection options were passed
  • the DELETE scenario test had no assertion that the access list entry was removed.
  • user.js had a pre-existing bug where Object.entries was called on a Mongoose query result array, passing whole documents as IDs instead of extracting ._id

Solution

Fix bugs and dedupe Mongoose connection code in test suite

Risk

Low. We can rely on the test suite!!!
Potential risk with user.js fix which corrects broken behaviour (user assignment was passing document objects instead of IDs to the query)

Checklist

  • Acceptance criteria met
  • Wiki documentation is written and up to date
  • Integration tests written and passing

leowla added 3 commits May 20, 2026 20:10
- Fix Express error handler arity in imageApi (2 params → 4; Express
  requires exactly 4 to recognise error-handling middleware)
- Reset nextFunction mock between tests in scenarioAuth to prevent
  call-count bleed across test cases
- Remove deprecated useNewUrlParser/useUnifiedTopology options from
  sceneDao that generated driver warnings
- Add missing Access document deletion assertion to scenario DELETE test
- Replace Object.entries(array).map(([_, doc]) => doc) in user.js with
  .map(doc => doc._id), which passed Mongoose documents where ObjectIds
  were expected
- Configure no-unused-vars argsIgnorePattern for underscore-prefixed
  params; remove now-redundant eslint-disable comment in user.js
Add src/test/mongoSetup.js with two composable functions:
useMongoMemoryServer() registers beforeAll/afterEach/afterAll lifecycle
hooks for MongoMemoryServer; useExpressServer(configureApp) registers
beforeAll/afterAll for an Express server and returns a ctx object whose
port is populated at test time.

Replace ~15 lines of duplicated boilerplate in all five test files with
two calls at the top of each describe block. Also fixes a latent teardown
race: the original server.close(async () => {...}) passed an async
callback that Jest never awaited; the helper uses a Promise-wrapped close
so mongoose.disconnect and mongoServer.stop are properly sequenced.
@leowla leowla requested review from harbassan and hazikchaudhry May 20, 2026 08:28
@leowla leowla self-assigned this May 20, 2026
@leowla leowla added the backend label May 20, 2026
@linear
Copy link
Copy Markdown

linear Bot commented May 20, 2026

VPS-19

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant