The backend test is as follows: (You shall setup an accessible Mongodb backend database with a Nodejs framework to the best of your ability)
- Set up a nodejs server and connect it to a mongodb collection. We should be able to send data to certain urls to store and get data.
/api/getUsers
- returns a json object with all the users in the database/api/insertUser
- accepts the following form data and inserts into the User table.name
email
username
password
- Password being encrypted once inserted into the database
Look at doc/user.requests.http
file for executable examples on HTTP Rest Client
.
First install all dependencies with npm i
.
Then make a copy of/rename .env-example
file as .env
and adjust if necessary.
To run tests also adjust .env-test
file.
Script | Description |
---|---|
npm start |
Start the service. |
npm run start-dev |
Start the service in dev/watch mode. On source file change service will be restarted. |
npm test |
Run unit tests. |
npm test-dev |
Run unit tests in watch mode. |
npm test-int |
Run integration tests. |
npm test-int-dev |
Run integration tests in watch mode. |
Retrieves all users.
None.
users
field on a response body holds the list of the users with the following fields:
Field | Description |
---|---|
_id | ID of the user |
username | User name/login |
name | Full Name |
Email Address |
curl -X GET \
-H 'Accept: application/json' \
http://localhost:3000/api/getUsers
{
"users": [
{
"_id": "607e8d0844e1bd7da5e0cd97",
"username": "some_user",
"name": "Some User",
"email": "some@email.com"
}
]
}
{
"users": []
}
Creates a new user.
Field | Description | Is Mandatory? |
---|---|---|
username | User name/login | Yes |
name | Full Name | Yes |
Email Address | Yes |
user.id
field on a response body holds the newly created user's ID.
curl -X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
http://localhost:3000/api/insertUser \
-d '{
"username": "some_guy",
"name": "Some Guy",
"email": "some_guy@gmail.com",
"password": "123Qw+@cvb"
}'
HTTP Code: 200
{
"user": {
"id": "607e8d0844e1bd7da5e0cd97"
}
}
HTTP Code: 400
{
"error": "Invalid username"
}