This is a simple service to encourage customers to purchase specific types of organs by offering them additional free organs. The service is designed to read customer orders from CSV files and output the total number of organs the customer is to receive based on the bonus scheme.
-
Clone the repository
-
Install dependencies:
npm install
- To run the application in dev mode
npm run dev input/order.csv
. OR - To build and start the typescript app
npm run build
.npm start input/order.csv
.
Note : file-path is optional. if you run npm run dev
, it will run with default order file
- To run unit tests, use the following command:
npm run test
This will run Jest test suites and output test results to the console. - To run unit tests and get the coverage :
npm run test:coverage
Node.js with TypeScript is chosen for this service because it is a fast and lightweight platform that is well-suited for building web services. The use of TypeScript adds an extra layer of type safety and makes the code more maintainable. Here we are using csv-parse package for csv file parsing. we are using jest for creating tests . The service uses ESLint to enforce code quality and consistency
The project consists of three main parts :
- app.ts: This module is responsible take the input and finally outputting the results to the console.
- service.ts: This module is responsible for reading customer orders from CSV files, processing the orders, and calculating the final result with a bonus.
- utils: This part contains utility functionalities like validation, readCSV.
The project is designed with the following considerations:
- Readability: The code is written to be easily understood and readable by other developers.
- Simplicity: The code is designed to be simple and straightforward, without unnecessary complexity.
- Separation of Concerns: The code is divided into separate modules with distinct responsibilities to ensure maintainability.
- Testability: The code is designed to be easily tested using automated tests and whole tests gives allmost 100% coverage on services file