This is my solution for the Metric-Imperial Converter freeCodeCamp challenge.
Build a full stack JavaScript app that is functionally similar to the sample project. Working on this project will involve you writing your code using one of the following methods:
- Clone this project's GitHub repo and complete your project locally.
- Use our Replit starter project to complete your project.
- Use a site builder of your choice to complete the project. Be sure to incorporate all the files from our GitHub repo.
- When you are done, make sure a working demo of your project is hosted somewhere public.
- Then submit the URL to it in the
Solution Linkfield. Optionally, also submit a link to your project's source code in theGitHub Linkfield.
- Complete the necessary conversion logic in
/controllers/convertHandler.js - Complete the necessary routes in
/routes/api.js - Copy the sample.env file to .env and set the variables appropriately
- To run the tests uncomment
NODE_ENV=testin your.envfile - To run the tests in the console, use the command
npm run test. To open the Replit console, pressCtrl+Shift+P(Cmdif on a Mac) and type "open shell"
Write the following tests in tests/1_unit-tests.js:
convertHandlershould correctly read a whole number input.convertHandlershould correctly read a decimal number input.convertHandlershould correctly read a fractional input.convertHandlershould correctly read a fractional input with a decimal.convertHandlershould correctly return an error on a double-fraction (i.e. 3/2/3).convertHandlershould correctly default to a numerical input of 1 when no numerical input is provided.convertHandlershould correctly read each valid input unit.convertHandlershould correctly return an error for an invalid input unit.convertHandlershould return the correct return unit for each valid input unit.convertHandlershould correctly return the spelled-out string unit for each valid input unit.convertHandlershould correctly convertgaltoL.convertHandlershould correctly convertLtogal.convertHandlershould correctly convertmitokm.convertHandlershould correctly convertkmtomi.convertHandlershould correctly convertlbstokg.convertHandlershould correctly convertkgtolbs.
Write the following tests in tests/2_functional-tests.js:
- Convert a valid input such as
10L:GETrequest to/api/convert. - Convert an invalid input such as
32g:GETrequest to/api/convert. - Convert an invalid number such as
3/7.2/4kg:GETrequest to/api/convert. - Convert an invalid number AND unit such as
3/7.2/4kilomegagram:GETrequest to/api/convert. - Convert with no number such as
kg:GETrequest to/api/convert.