You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make sure your PGPORT matches the one assigned in your pgAdmin4 Server!
Make sure your PGDATABASE names are different in your .env & .env.test files!
Use the following commands to:
npm test# Test code.
npm start # Start the app in your preferred port (3000 by default).
You can interact with the API and test its functions through Postman.
API Endpoints
Reader
POST/readers(creates a new reader entry)
Parameters and body content
Parameters
Body content
None
Name [STRING], Email [STRING], Password [STRING](8 characters or more)
Responses
code
description
201
Successful operation
400
Content element empty, null, not unique, not the right format or not the right length
GET/readers(returns all the reader entries)
Parameters and body content
Parameters
Body content
None
None
Responses
code
description
200
Successful operation
404
Entry not found
GET/readers/:id(returns a reader entry by ID)
Parameters and body content
Parameters
Body content
Reader_ID
None
Responses
code
description
200
Successful operation
404
Entry not found
PATCH/readers/:id(updates a reader entry by ID)
Parameters and body content
Parameters
Body content
Reader_ID
Name [STRING], Email [STRING], Password [STRING](8 characters or more)
Responses
code
description
200
Successful operation
404
Entry not found
DELETE/readers/:id(deletes a reader entry by ID)
Parameters and body content
Parameters
Body content
Reader_ID
None
Responses
code
description
204
Successful operation
404
Entry not found
Book
POST/books(creates a new book entry)
Parameters and body content
Parameters
Body content. Required.
None
Title [STRING], ISBN [INT], Author_ID [INT], Genre_ID [INT], Reader_ID [INT]
Responses
code
description
201
Successful operation
400
Content element empty, null or not unique
GET/books(returns all book entries)
Parameters and body content
Parameters
Body content
None
None
Responses
code
description
200
Successful operation
404
Entry not found
GET/books/:id(returns a book entry by ID)
Parameters and body content
Parameters
Body content
Book_ID
None
Responses
code
description
200
Successful operation
404
Entry not found
PATCH/books/:id(updates a book entry by ID)
Parameters and body content
Parameters
Body content
Book_ID
Title [STRING], ISBN [STRING], Author_ID [INT], Genre_ID [INT] and/or Reader_ID [INT]
Responses
code
description
200
Successful operation
404
Entry not found
DELETE/books/:id(deletes a book entry by ID)
Parameters and body content
Parameters
Body content
Book_ID
None
Responses
code
description
204
Successful operation
404
Entry not found
Author
POST/authors(creates a new author entry)
Parameters and body content
Parameters
Body content
None
Name [STRING]
Responses
code
description
201
Successful operation
400
Content element empty, null or not unique
GET/authors(returns all the author entries)
Parameters and body content
Parameters
Body content
None
None
Responses
code
description
200
Successful operation
404
Entry not found
GET/authors/:id(returns an author entry by ID)
Parameters and body content
Parameters
Body content
Author_ID
None
Responses
code
description
200
Successful operation
404
Entry not found
PATCH/authors/:id(updates an author entry by ID)
Parameters and body content
Parameters
Body content
Author_ID
Name [STRING]
Responses
code
description
200
Successful operation
404
Entry not found
DELETE/authors/:id(deletes an author entry by ID)
Parameters and body content
Parameters
Body content
Author_ID
None
Responses
code
description
204
Successful operation
404
Entry not found
Genre
POST/genres(creates a new genre entry)
Parameters and body content
Parameters
Body content
None
Genre[STRING]
Responses
code
description
201
Successful operation
400
Content element empty, null or not unique
GET/genres(returns all the genre entries)
Parameters and body content
Parameters
Body content
None
None
Responses
code
description
200
Successful operation
404
Genres not found
GET/genres/:id(returns a genre entry by ID)
Parameters and body content
Parameters
Body content
Genre_ID
None
Responses
code
description
200
Successful operation
404
Entry not found
PATCH/genres/:id(updates a genre entry by ID)
Parameters and body content
Parameters
Body content
Genre_ID
Genre [STRING]
Responses
code
description
200
Successful operation
404
Entry not found
DELETE/genres/:id(deletes a genre entry by ID)
Parameters and body content
Parameters
Body content
Genre_ID
None
Responses
code
description
204
Successful operation
404
Entry not found
Tests
I have been using Mocha, Chai and Supertest to write test suites trying the functionality of the API. This is the result for the current version when running npm test:
Test Results
/authors
with no records in the database
POST /authors
✔ creates a new author in the database (770ms)
✔ errors if name is null
with records in the database
GET /authors
✔ gets all authors records
GET /authors/:id
✔ gets authors record by id
✔ returns a 404 if the author does not exist
PATCH /authors/:id
✔ updates authors name by id
✔ returns a 404 if the author does not exist
DELETE /authors/:id
✔ deletes author record by id
✔ returns a 404 if the author does not exist
/books
with no records in the database
POST /books
✔ creates a new book in the database
✔ errors if title is null
with records in the database
GET /books
✔ gets all books records
GET /books/:id
✔ gets books record by id
✔ returns a 404 if the book does not exist
PATCH /books/:id
✔ updates books title by id
✔ returns a 404 if the book does not exist
DELETE /books/:id
✔ deletes book record by id
✔ returns a 404 if the book does not exist
/genres
with no records in the database
POST /genres
✔ creates a new genre in the database
✔ errors if genre is null
with records in the database
GET /genres
✔ gets all genres records
GET /genres/:id
✔ gets genres record by id
✔ returns a 404 if the genre does not exist
PATCH /genres/:id
✔ updates genres genre by id
✔ returns a 404 if the genre does not exist
DELETE /genres/:id
✔ deletes genre record by id
✔ returns a 404 if the author does not exist
/readers
with no records in the database
POST /readers
✔ creates a new reader in the database
✔ errors if email format not valid
✔ errors if any fields are missing
✔ errors password is less than 8 char length
with records in the database
GET /readers
✔ gets all readers records
GET /readers/:id
✔ gets readers record by id
✔ returns a 404 if the reader does not exist
PATCH /readers/:id
✔ updates readers email by id
✔ returns a 404 if the reader does not exist
DELETE /readers/:id
✔ deletes reader record by id
✔ returns a 404 if the reader does not exist
38 passing (3s)
About
An exercise on Express API creation, Databases and Sequelize. (Docker | Sequelize | Express | PostgreSQL | Databases | ERD | Javascript); Tests: Supertest, Mocha, Chai.