📎 Webclip
Test Driven Development With Node, Postgres, and Knex (Red/Green/Refactor)
The post outlines a test-first workflow for building a RESTful API with Node, Express, Knex, and PostgreSQL. It covers project setup, database configuration, migrations, seed files, and Mocha/Chai test setup before moving into route implementation.
Reading notes#
- Sets up separate development and test databases with Knex configuration for different environments.
- Uses migrations to create a
showstable with fields for name, channel, genre, rating, and explicit content. - Uses seed files to populate development and test databases with the same initial rows.
- Configures Mocha, Chai, and Chai HTTP for route testing, and prefixes routes with
/api/v1. - Shows the red/green/refactor cycle by writing a failing test, then adding a query and route until it passes.
- Builds GET all shows, GET one show, POST, PUT, and DELETE routes for the
showsresource. - Uses
beforeEachandafterEachto roll back migrations and reseed the database so tests stay isolated. - Prevents updating the
idfield and adds a test for that case. - Notes that error handling is still incomplete for missing fields and deleting absent rows.
