This project was for an interview question. It the hotel problem constraint.
Clone the repository and traverse to it's directory to view the code and
run the commands.
It's paramount to have npm installed in your computer.
Make sure you have "win-node-env" installed for the command available in JSON
npm install --save-dev win-node-env
### Installing
Run the following command to install the dependecies of the application :
npm install
### Demonstration Once the dependencies are installed run the following command:
npm run-script prod
You should see this page when it's loaded correctly.
This will build and run the server in production mode.
To test whether the endpoints are setup correctly. Using you browser enter the link http://localhost:3000/api
It should return
{"message":"API Endpoint"}
This will verify that your project folder is complete and basic Express.js function are working.
When no issues arised it's time to test the real problem statement:
Example input
{
"bookings":{
"adult": 6,
"children":2,
"infant": 1
}
}
Send a POST request to http://localhost:3000/api/booking
It will show this as the output:
{
"booking": {
"rooms": [
{
"adult": 3,
"children": 2,
"infant": 1
},
{
"adult": 3
}
]
}
}
To run test just run the following command:
npm test
It should show that all test passed as shown below:
Initial suite test
√ API return message
Problem Statement Test Cases
Booking For Rooms (Returns Result)
Test With Adults Only
√ If 7 adults are booking
√ If 5 adults are booking
√ If 6 adults are booking
√ If 3 adults are booking
Test With Adults And Children Only
√ If 6 adults with 1 child are booking
√ If 4 adults with 2 child are booking
√ If 3 adults with 3 child are booking
Test With Adults And Infants
√ If 6 adults with 1 infant are booking
√ If 4 adults with 3 infant are booking
√ If 3 adults with 2 infant are booking
Test With Adults,Children and Infants
√ If 4 adults,3 child and 3 infants are booking
√ If 3 adults, 1 child and 2 infants are booking
Booking For Rooms (Returns Error)
√ If 8 adults are booking (Overcapacity Error)
√ If 0 adults are booking (Not enough adult)
√ If 0 children are booking (Not enough adult)
√ If 0 infant are booking (Not enough adult)
√ If 6 adults, 2 children and 4 infant are booking (Overcapacity Error)
√ If 1 adults and 6 children are booking (Not enough adult)
√ If a child is booking (Unaccompanied Minor Error)
√ If an infant is booking (Unaccompanied Minor Error)
Small Constraint Engine Test Cases
Checking Current Rule
√ Check if application blocks empty request
√ Check if application blocks incomplete request
√ Check for valid datatypes
√ Check if engine follows application ruleset
25 passing (283ms)
Currently these test are for the api and correctness of the application based on the problem statement provided.
Extra test cases are for the constraint engine introduced for rule flexibility sake. The code could be much simpler for the problem statemen but to showcase what could be accomplished it this project.
I decided to add a simple constraint parser engine for future reusability for something with similar rules.
** IN PROGRESS **
-
Babel - next generation JavaScript
-
NodeJS - The Chrome V8 Javascript engine
-
ExpressJS - Fast, unopinionated, minimalist web framework for Node.js
-
Mocha - Simple, flexible, fun test framework
-
Chai Assertion Library - BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Mohd. Paramasvara - Software Enginner
This project is licensed under the GPL v3 license - see the LICENSE.md file for details
- Hat tip to anyone whose code was used
- Inspiration from the problem statement given