Skip to content

test: add unit tests for CRUD router#165

Open
Thomas-Sedhom wants to merge 2 commits intoaccordproject:mainfrom
Thomas-Sedhom:test/crud-router-unit-tests
Open

test: add unit tests for CRUD router#165
Thomas-Sedhom wants to merge 2 commits intoaccordproject:mainfrom
Thomas-Sedhom:test/crud-router-unit-tests

Conversation

@Thomas-Sedhom
Copy link
Copy Markdown
Contributor

Replaces #133 (closed by stale bot)

Added a full unit test suite for the buildCrudRouter utility in crud.ts. The tests cover all five HTTP methods the router exposes and use a mock DB layer so there's no real database dependency.
What's covered

GET /

  • Returns paginated results and correctly caps limit at 100 even when a higher value is passed
  • Enriches user items with an empty roles array when typeName is users

POST /

  • Runs schema validation, custom validation, transformRequest, and transformResponse in the right order and with the right data
  • Returns 400 with field-level details when schema validation fails
  • Returns 400 with custom error messages when custom validation fails
  • Returns 409 on duplicate key constraint violations (pg error code 23505)

GET /:id

  • Returns a single item passed through transformResponse
  • Returns 404 when the record doesn't exist

PUT /:id

  • Updates the record and returns it transformed
  • Returns 409 on unique constraint violation

DELETE /:id

  • Deletes the record and returns { status: 'deleted' }
Screenshot 2026-03-19 205113 Screenshot 2026-03-19 205102

Signed-off-by: thomas sedhom <thomassedhom97@gmail.com>
Signed-off-by: thomas sedhom <thomassedhom97@gmail.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