This round is to test your Logical thinking, coding skills, reading skills and NestJs basics.
This repo uses NestJs and Jest to create a backend server and perform e2e tests.
Please carefully read the instructions mentioned below.
DON'T CLONE THIS REPO and DON'T MAKE PULL REQUESTS TO THIS REPO. FORK this repo to your own GitHub account then clone it. Fork button is the top right corner of the page. The forked URL should look something like this: https://github.com/${YOUR_GITHUB_USERNAME}/node
- Implement a post route http://localhost:3000/calc that takes a JSON input in the following format:
{
"expression": "<expression>"
}
and returns a json in the following format by evaluating the expression.
{
"result": "<result>"
}
- You cannot use
evel
or any other third party library to evaluate the expression. - You cannot add or remove any files from the project.
- You can only work inside calc/calc.service.ts@calculateExpression method.
- In case the expression is invalid, return a json in the following format with 400 status code
{
"statusCode": 400,
"message": "Invalid expression provided",
"error": "Bad Request"
}
- You need to implement +, -, *, / operations. Handling Operator precedence is optional.
- The repository contains 6 test cases. You need to make sure all of them pass. In case operator precedence is not handled run
pnpm test:basic
command to run only the basic test cases. Otherwise, runpnpm test:advanced
to run all the test cases. - Follow the test case files to understand the input and output format.
- i. test/simpleCalc.e2e-spec.ts
- ii. test/operatorPrecedenceNotHandled.e2e-spec.ts
- iii. test/invalidExpression.e2e-spec.ts
- Implement a NestJS middleware that logs the request URL, method, time taken to execute the request and response status code.
- The middleware should be applied to all the routes.
- The log text example:
GET /calc 200 1.2 ms