PostgreSQL Note that this database will ONLY BE USED FOR TESTS in this project
npm install
npx knex migrate:latest
Create a new file named .env
on the project root (the same level/folder as package.json) and add the following to it:
DATABASE_CONNECTION_STRING=url://connection@string/to/postgress/database
npm test
Look under scripts.test
in package.json
to see how this is set up.
We clear database before running the test so that we always have a clean database to work with and don't end up getting errors for repeating a primary key.
npm test path/to/file.test.js
Example:
npm test src/models/week/index.test.js
FORK this repository before starting to do anything. There is a Fork
button at the top of this repository page.
- Complete the todo tests for the week and topic models.
- Create a new table called instructors. Use any fields that you want.
- Create a model for instructors inside
./src/models
. - Link each week to an instructor. An instructor might be the instructor for more than one week. (one to many relationship)
- Modify week models to handle instructor information.
- Run week tests and see them fail. Modify the tests to meet the new requirements.
- Write tests for instructors model covering at least creation, read, update and deletion (CRUD). You will be using your database as a test database.
https://knexjs.org/guide/migrations.html - Dealing with Knex migrations
https://knexjs.org/guide/schema-builder.html#createtable - Knex Schema Builder
We are using ava
as our test runner.
Read this link for a reference on how to declare tests
using ava.
Read this link for a reference on how to write assertions
using ava.
Take a look at the week test file for an example. But remember that you will need to modify these tests.
https://www.tutorialsteacher.com/sqlserver/tables-relations
https://blog.devart.com/types-of-relationships-in-sql-server-database.html