- introduce today's project.
- introduce the TDD/BDD workflow.
- use TDD/BDD to implement a set of requirements.
- configure
jest
's test environment to run innode
mode. - introduce the
supertest
library. - use the
cross-env
module to configure the environment before running the tests. - write integration tests that hit a test database.
- when making a GET to the
/
endpoint the API should respond with status code 200 and the following JSON object:{ api: 'running' }
. - the User model should hash the password before saving it to the database.
TDD === Test Driven Development.
BDD === Behavior Driven Development (search for Dan North video)
TDD Philosophy (red - green - refactor)
- no code is written unless a test requires it.
- only write enough code to make the test pass.
- once the test passes look for opportunities to clean up test and code.
System
- features
- user stories
- scenarios
- user stories
User Story Example
As a: sales executive. I want: login to the system. So that: I can see my sales for the day/quarter.
Scenarios
-
Given: a username
- and: a password
-
When: the username is valid
- and: the password is valid
-
Then: the system will allow login
- and: the user is redirected to their landing page.
-
Given: a username
- and: a password
-
When: the username is valid
- and: the password is invalid
-
Then: the system will NOT allow login
- and: the system will show a message to the user.
- and: the user is redirected to their login page.
As a (role): payroll officer. I want: login to the system. So that: I can run the payroll.
By default Jest uses jsdom
, for node we need to change that default.