Skip to content

test: add unit tests for CRUD router#133

Closed
Thomas-Sedhom wants to merge 1 commit intoaccordproject:mainfrom
Thomas-Sedhom:test/crud-router-unit-tests
Closed

test: add unit tests for CRUD router#133
Thomas-Sedhom wants to merge 1 commit intoaccordproject:mainfrom
Thomas-Sedhom:test/crud-router-unit-tests

Conversation

@Thomas-Sedhom
Copy link
Copy Markdown
Contributor

@Thomas-Sedhom Thomas-Sedhom commented Mar 19, 2026

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' }
image image

Signed-off-by: thomas sedhom <thomassedhom97@gmail.com>
@Thomas-Sedhom Thomas-Sedhom force-pushed the test/crud-router-unit-tests branch from 04cd342 to 74eb5e2 Compare March 19, 2026 19:03
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 4, 2026

This PR is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@Thomas-Sedhom
Copy link
Copy Markdown
Contributor Author

This work has been continued in #165

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