- Development environment
Node v12.13.1
MongoDB v4.0.11
- Clone or download this repository
git clone
- Configure local environments with settings:
export PORT=8080 # default is 8080
export MONGODB_URL=mongodb://localhost:27017/test_db # default is mongodb://localhost:27017/test_db
- Enter your local directory, and install dependencies:
npm i
# run server in development mode
npm run dev
# run test suite
npm test
# run linter
npm run lint
# build docs
npm run doc
# run prod start
npm start
To run this application and test suite it's a requirement to have local installed MongoDB
.
There is possible to containerize this into Docker and create docker-compose to spin up this app and MongoDB in containers, but it's a bit outside of scope of this test task. Also its possible to setup CircleCI
configuration (I mostly use CircleCI in my projects) to run test suite during CI workflow, CircleCI
support using images with preinstallled MongoDB
to run integration tests.
This application implemented like rest-api service which has endpoints to import data into database and endpoints to get patients
list and patient
info. There is automaticaly generated documentation, which available by accessing url http://<server-url:port>/docs
after start server.
There is implemented test suites with examples of unit testing and integration testing the functionality. I'm using one of most popular test framework mocha
(https://mochajs.org) with also popular assertion library chai
(https://www.chaijs.com). As requested for report generation I'm using mochawesome
plugin which is allow to generate well formated html reports and allow to add to these reports some extra context. I decided to use these tools and add some requested information (like ids of patients with empty names) as context to the report.
Unit tests covers parser
library, which is responsible for parsing lines of data file. It is covered with 100% lines.
Integration tests implemented all requested changes, using sample file for loading data into database and the same sample file parsed manually during tests as source of truth (for parsing file during test I'm using the same parser which is covered by unit tests). Test suite can be run by command npm test
, after finish report will be generated to public/report
folder and it will be available by accessing url http://<server-url:port>/report
after start server.
-
make sure that you have installed localy
NodeJS
andMongoDB
, this tested onNodeJS v12.13.1
andMongoDB v4.0.11
-
clone git repository
-
run
npm i
for install all dependencies -
you can setup local env vars for server port (assign
PORT
) and customMongoDB
connection string (assignMONGODB_URL
). By default app will usePORT=8080
andMONGODB_URL=mongodb://localhost:27017/test-load-db
, for test suiteMongoDB
connection string isMONGODB_URL=mongodb://localhost:27017/integration-test-load-db
. IMPORTANT!! Make sure that you don't have any important data in these databases on localMongoDB
. -
run command
npm test
to run test suite, report will be saved topublic/report
folder. -
you can open report manually, just open file
public/report/index.html
-
or you can start the server by the command
npm start
(ornpm run dev
) -
get access to the report by url
http://localhost:8080/report/
-
get access to the api documantation by url
http://localhost:8080/docs/
This app is simple ExpressJS based application. Most important files is:
app/lib/parser.js
- contain all parse logic, this works with separate lines of file, parse it and validate data before put into databseapp/modules/patients/**/*.*
- this folder contain all files reltated to patients import, here is models, service with business logic and router/controllertests/**/*.*
- this folder contains all tests (utin and integration) with all fixtures