Test and ship
Add database integration tests
Run the real schema and queries against an isolated SQLite database to catch mistakes mocks cannot reveal.
8 minute lesson
A mock can prove that code made an expected call. It cannot prove that the SQL, constraint, migration, and driver agree.
Create a temporary database for each test file or case, apply migrations, call the API, and remove the file afterward. Cover rollback and constraint behavior as well as the happy path.
Use the same migration runner and repository code as production. Creating a simplified test schema by hand can let a broken migration ship. Give every test an isolated file or database connection, close statements and connections before cleanup, and never point the test configuration at a development database.
Assert persisted state after the HTTP response, not only the response body. Exercise a constraint violation, a multi-step transaction that rolls back, a migration from an empty database, and any relevant concurrent write behavior. When a test fails, preserve enough context to distinguish an HTTP mapping bug from SQL, schema, locking, or cleanup failure.
Run create, read, update, and delete through the app against a temporary database.
Lesson completed