A progressive Node.js framework for building efficient and scalable server-side applications.
This is a Nest framework Feature Enhancement Assignment. This assignment implements a new feature to manage a collection of tasks, each task has the following properties:
id
: unique identifier, auto-generatedtitle
: string, requireddescription
: string, optionalstatus
: enum, required: ['TODO', 'IN_PROGRESS', 'COMPLETED']createdAt
: date, auto-generatedupdatedAt
: date, auto-generated
This assignment implements the following operations:
- Create a new task (POST)
- Retrieve a task by its
id
(GET) - Delete a task by its
id
(DELETE)
The folder src/tasks
contains implementation and unit tests for the new module TasksModule
, which contains the following files:
- The file
tasks.entity.ts
definesTask
andTaskStatus
. - The file
tasks.controller.ts
validates the parameters and implements routing for the 3 RESTful APIs (POST, GET, DELETE). - The file
tasks.service.ts
implements logics for task storage and query. - The file
tasks.controller.spec.ts
contains unit tests for the controller, implemented with Jest. - The file
tasks.service.spec.ts
contains unit tests for the provider, implemented with Jest.
The E2E tests are placed under the test
folder, which connects to a PostgreSQL database and runs E2E tests automatically.
- Install the PostgreSQL, create a database called "Tasks".
- Install Node.js and npm.
- Install the Nest.js CLI.
- Tools to test the APIs, e.g. Postman.
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# unit tests coverage
$ npm run test:cov
# e2e tests
$ npm run test:e2e
# e2e tests coverage
$ npm run test:e2e:cov
Note:
- When checking the coverage for unit tests, it would complain about
*.module.ts
, but was suggested to ignore them and test those files in the E2E tests. - When checking the coverage for E2E tests, line 5 of
tasks.entity.ts
was marked as uncovered. That was an imported decorator, seems unnecessary to write tests specifically for it.
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
- This assignment
- Author - Junda Shen
- Original framework
- Author - Kamil Myśliwiec
- Website - https://nestjs.com
- Twitter - @nestframework
Nest is MIT licensed.