feat(tests): add Jest+Supertest infrastructure with jump route suite (14 tests)

- Extract Express app creation into src/createApp.js to enable testing without starting the server
- Add Jest, Supertest, test helpers (createTestApp, auth token generator)
- Write 14 integration tests for skydive/jumps: auth protection, CRUD, ownership checks

Bugs caught and fixed by the test suite:
- MongoDB models: author field typed as Schema.Types.UUID (Mongoose 6 rejects string UUIDs) → changed to String
- Jump.toJSONFor: called toProfileJSONFor on a UUID string → guarded with typeof check
- exceptions.handler: used err.statusCode but express-jwt throws err.status → returns 500 on 401 errors
- Jump.count(query): deprecated Mongoose method was ignoring the filter → replaced with countDocuments
- jumps.routes GET /: $or query included non-schema field "title" stripped by strictQuery, leaving {} (match-all) → replaced with slug/lieu search
- $regex: was passing a JS RegExp object which serializes to {} in MongoDB → now passes raw string
This commit is contained in:
2026-04-26 01:23:01 +02:00
parent 4c765945b3
commit da1f9437ab
21 changed files with 4068 additions and 163 deletions
+5 -2
View File
@@ -11,7 +11,8 @@
"start": "APP_ENV=production node ./app.js",
"dev": "APP_ENV=development node ./app.js",
"local": "APP_ENV=local nodemon ./app.js",
"test": "newman run ./tests/adastra-api-tests.postman_collection.json -e ./tests/adastra-api-tests.postman_environment.json",
"test": "jest",
"test:postman": "newman run ./tests/adastra-api-tests.postman_collection.json -e ./tests/adastra-api-tests.postman_environment.json",
"stop": "lsof -ti :3200 | xargs kill",
"mongo:start": "docker run --name hu-mongo -p 27017:27017 mongo & sleep 5",
"mongo:stop": "docker stop hu-mongo && docker rm hu-mongo",
@@ -59,8 +60,10 @@
"@eslint/js": "^9.0.0",
"eslint": "^9.0.0",
"globals": "^15.0.0",
"jest": "^30.3.0",
"newman": "^5.3.2",
"nodemon": "^2.0.22",
"sequelize-cli": "^6.6.2"
"sequelize-cli": "^6.6.2",
"supertest": "^7.2.2"
}
}