Skip to content

Implementation of Unit Testing in NestJs Framework with Book Rental Case Studies

Notifications You must be signed in to change notification settings

fajarnugraha37/nestjs-unit-test-implementation

Repository files navigation

Example Unit Test in NestJS

Specification

  • Nodejs: v18.6.0
  • npm: 8.13.2
  • mysql: 8.0.27

Use Case

  • Members can borrow books with conditions
    • Members may not borrow more than 2 books
    • Borrowed books are not borrowed by other members
    • Member is currently not being penalized
  • Member returns the book with conditions
    • The returned book is a book that the member has borrowed
    • If the book is returned after more than 7 days, the member will be subject to a penalty. Member with penalty cannot able to borrow the book for 3 days
  • Check the book
    • Shows all existing books and quantities
    • Books that are being borrowed are not counted
  • Member check
    • Shows all existing members
    • The number of books being borrowed by each member

Endpoint

  • GET
    • ${HOST_NAME}/swagger
    • API Documentation
  • GET
    • ${HOST_NAME}/members
    • to fetch all members
  • GET
    • ${HOST_NAME}/members/:code
    • to fetch member with spcific member-code
  • GET
    • ${HOST_NAME}/books
    • to fetch all books
  • GET
    • ${HOST_NAME}/book/:code
    • to fetch book with spcific book-code
  • GET
    • ${HOST_NAME}/members
    • to fetch all members
  • GET
    • ${HOST_NAME}/members/:code
    • to fetch member with spcific member-code
  • POST
    • ${HOST_NAME}/members/:memberCode/borrow/:bookCode
    • borrow a book operation
  • POST
    • ${HOST_NAME}/members/:memberCode/return/:bookCode
    • return a book operation

Running

  • install dependency

npm install

  • running test

npm run test

  • running app

npm run start

Releases

No releases published

Packages

No packages published

Languages