Skip to content

raghavgarg1257/social-cops-app

Repository files navigation

Social Cops Node JS Task

The problem statement has been uploaded in the repo.

Using ES6 syntax, with Babel.

Demo (its currently down/not working)

You can use the undergiven ip address to make the request using Postman. It is hosted on AWS.

http://35.163.21.122:8000

Task Assessment

The task progress according to the NodejsTask.pdf.

Pre-requisite

  1. NodeJS
  2. Globally installed nodemon (to use npm run dev)
  3. Globally installed istanbul (to use npm run cover)

Setup

git clone git@github.com:raghavgarg1257/social-cops-app.git
cd social-cops-app
cp .env.example .env
nano .env # optional, you can set port and jwt secret and sentry dns for logging errors
npm install
npm start # the server will be started and link will be printed in the terminal

Available Npm Script

npm install # to install depensencies
npm start # to start the server
npm run dev # to start the server with nodemon, to develop
npm test # to run test
npm run nyc # to run test with code coverage report in terminal
npm run cover # to get code coverage as an html file

Usage (available routes)

The routes can be tested using Postman or you can use Swagger Docs.

Note: to use protected routes an extra header needs to be added in request of format like:

HEADER {
    "Authorization" : "Bearer JWT_TOKEN" # note the space between keyword Bearer and JWT_TOKEN
}
type: public
req: GET /
res: Text
type: public
req: POST /
res: Text
desc: login route, user can send username and password, and recieve JWT_TOKEN.
    : JWT_TOKEN can be used to making request to protected routes.
    : Currently no authentication process is in place, every username and password will be processed.
type: public
req: POST /login {
    "username" : String,
    "password" : String
}
res:{
    "message": String,
    "data": {
        "username": String,
        "token": JWT_TOKEN
    }
}
desc: json-patch route, user can send json and patch(http://jsonpatch.com/), and recieve new json.
type: protected
req: POST /json-patch {
    json : JSON Object,
    patch: JSON Patch Object
}
res: JSON Object (after applying the patch)
desc: image thumbnail route, user can send public image url, and recieve 50x50 pixel image as response.
    : the url with 'https' will not work.
type: protected
req: POST /img-thumb {
    url : String (valid image url)
}
res: Image

Test Suite

To run normal test

npm test

To run test with code coverage report in terminal

npm run nyc

To get code coverage report in html

npm run cover # then open index.html in /coverage/Icov-report/index/html

Deploy using Docker

Note: exposed port is 8000

To build docker image

docker build -t node-task .

To run the docker image

docker run -p 3000:8000 -d node-task

Swagger Docs (more details)

Note: keep an open daemon of actual server.

Note: To use protected route, run /login, then copy token value from it's response and paste in the top right corner of the screen, then click explore.

Note: /img-thumb would not be tested with it properly as an image is the response of the route and swagger is not able to show it.

cd swagger-docs-server
npm start # link will be printed in the terminal