test: add 9 edge-case API tests for validation, deleted/SQLi IDs, export, session#9
Open
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
… session Co-Authored-By: Chris Livingston <chris.livingston@cognition.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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 9 new Jest + Supertest tests in
tests/api.test.jscovering edge cases that improve API behavior coverage:GET /api/todos— rejects invalidorderand invalidcompletedfilter values (2 tests).GET /api/todos/stats—POSTto the stats endpoint falls through tonotFoundHandlerand returns 404 (1 test).GET /api/todos/:id— fetching a previously-deleted todo returns 404; SQL-injection-like string in the ID returns 400 fromvalidateTodoId(2 tests).GET /api/todos/:id/export— non-existent UUID returns 404; non-UUID ID returns 400 (2 tests, newdescribeblock).GET /api/session—POSTandDELETEto/api/sessionfall through tonotFoundHandlerand return 404 (2 tests, newdescribeblock).All tests follow the existing pattern of using
supertestagainst theappinstance fromsrc/app.js.Notable finding (per session conversation)
The originally-planned
PUT /api/todos/stats → 404test was dropped. Express matchesPUT /api/todos/statsagainstrouter.put('/todos/:id', validateUpdateTodo, ...)(id="stats"), which fails UUID validation and returns 400 VALIDATION_ERROR, not 404 fromnotFoundHandler. This is route-ordering / matching behavior, not a test bug — left for a follow-up code change if 405/404 semantics are desired on/api/todos/statsfor non-GET methods.Test results
Coverage thresholds (80/70/80/80) are not met on this branch — but they were already failing on the baseline branch (50% statements, 40% branches, 51.15% lines, 44.7% functions). My additions improve coverage slightly:
Bringing thresholds green requires covering
src/public/js/app.js(client-side, currently 0%) andsrc/utils/{crypto,encoding,sanitizer}.js, which is out of scope for this PR.Review & Testing Checklist for Human
PUT /api/todos/stats → 404test, or open a follow-up to add an explicit handler that returns 405/404 for non-GET methods on/api/todos/stats.npm run test:coveragelocally and verify all 63 tests pass.Notes
Targets
devin/1777386487-node18-with-breaking-changes, notmain.Link to Devin session: https://app.devin.ai/sessions/afbfe7394c5c49ef9d2350f14d720da8
Requested by: @clivingston-cognition