feat(learn): Move metric imperial converter tests (#40358)

* Move tests to /learn

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* Modify test verbiage

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* Apply suggestions from code review

Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>

* Update curriculum/challenges/english/06-quality-assurance/quality-assurance-projects/metric-imperial-converter.md

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>

* Update curriculum/challenges/english/06-quality-assurance/quality-assurance-projects/metric-imperial-converter.md

Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>

* fix: add missing tests

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* fix: Correct inaccurate test text - thx @ShaunSHamilton

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* fix: remove arrow from test name

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>
This commit is contained in:
Nicholas Carrigan (he/him)
2021-01-20 20:51:57 -08:00
committed by GitHub
parent d6e47037de
commit b07394603b

View File

@ -10,18 +10,53 @@ dashedName: metric-imperial-converter
Build a full stack JavaScript app that is functionally similar to this: <https://metric-imperial-converter.freecodecamp.rocks/>. Working on this project will involve you writing your code using one of the following methods:
- Clone [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-metricimpconverter/) and complete your project locally.
- Use [our repl.it starter project](https://repl.it/github/freeCodeCamp/boilerplate-project-metricimpconverter) 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.
- Clone [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-metricimpconverter/) and complete your project locally.
- Use [our repl.it starter project](https://repl.it/github/freeCodeCamp/boilerplate-project-metricimpconverter) 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 Link` field. Optionally, also submit a link to your project's source code in the `GitHub Link` field.
# --instructions--
- 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=test` in your `.env` file
- To run the tests in the console, use the command `npm run test`. To open the Repl.it console, press Ctrl+Shift+P (Cmd if on a Mac) and type "open shell"
Write the following tests in `tests/1_unit-tests.js`:
- `convertHandler` should correctly read a whole number input.
- `convertHandler` should correctly read a decimal number input.
- `convertHandler` should correctly read a fractional input.
- `convertHandler` should correctly read a fractional input with a decimal.
- `convertHandler` should correctly return an error on a double-fraction (i.e. `3/2/3`).
- `convertHandler` should correctly default to a numerical input of `1` when no numerical input is provided.
- `convertHandler` should correctly read each valid input unit.
- `convertHandler` should correctly return an error for an invalid input unit.
- `convertHandler` should return the correct return unit for each valid input unit.
- `convertHandler` should correctly return the spelled-out string unit for each valid input unit.
- `convertHandler` should correctly convert `gal` to `L`.
- `convertHandler` should correctly convert `L` to `gal`.
- `convertHandler` should correctly convert `mi` to `km`.
- `convertHandler` should correctly convert `km` to `mi`.
- `convertHandler` should correctly convert `lbs` to `kg`.
- `convertHandler` should correctly convert `kg` to `lbs`.
Write the following tests in `tests/2_functional-tests.js`:
- Convert a valid input such as `10L`: `GET` request to `/api/convert`.
- Convert an invalid input such as `32g`: `GET` request to `/api/convert`.
- Convert an invalid number such as `3/7.2/4kg`: `GET` request to `/api/convert`.
- Convert an invalid number AND unit such as `3/7.2/4kilomegagram`: `GET` request to `/api/convert`.
- Convert with no number such as `kg`: `GET` request to `/api/convert`.
# --hints--
I can provide my own project, not the example URL.
You can provide your own project, not the example URL.
```js
(getUserInput) => {
getUserInput => {
assert(
!/.*\/metric-imperial-converter\.freecodecamp\.rocks/.test(
getUserInput('url')
@ -30,16 +65,15 @@ I can provide my own project, not the example URL.
};
```
I can GET /api/convert with a single parameter containing an accepted number and unit and have it converted. (Hint: Split the input by looking for the index of the first character which will mark the start of the unit)
You can `GET` `/api/convert` with a single parameter containing an accepted number and unit and have it converted. (Hint: Split the input by looking for the index of the first character which will mark the start of the unit)
```js
```
I can convert `'gal'` to `'L'` and vice versa. (1 gal to 3.78541 L)
You can convert `'gal'` to `'L'` and vice versa. (1 gal to 3.78541 L)
```js
async (getUserInput) => {
async getUserInput => {
try {
const data1 = await $.get(getUserInput('url') + '/api/convert?input=1gal');
assert.equal(data1.returnNum, 3.78541);
@ -59,10 +93,10 @@ async (getUserInput) => {
};
```
I can convert `'lbs'` to `'kg'` and vice versa. (1 lbs to 0.453592 kg)
You can convert `'lbs'` to `'kg'` and vice versa. (1 lbs to 0.453592 kg)
```js
async (getUserInput) => {
async getUserInput => {
try {
const data1 = await $.get(getUserInput('url') + '/api/convert?input=1lbs');
assert.equal(data1.returnNum, 0.45359);
@ -82,10 +116,10 @@ async (getUserInput) => {
};
```
I can convert `'mi'` to `'km'` and vice versa. (1 mi to 1.60934 km)
You can convert `'mi'` to `'km'` and vice versa. (1 mi to 1.60934 km)
```js
async (getUserInput) => {
async getUserInput => {
try {
const data1 = await $.get(getUserInput('url') + '/api/convert?input=1mi');
assert.equal(data1.returnNum, 1.60934);
@ -108,7 +142,7 @@ async (getUserInput) => {
All incoming units should be accepted in both upper and lower case, but should be returned in both the `initUnit` and `returnUnit` in lower case, except for liter, which should be represented as an uppercase `'L'`.
```js
async (getUserInput) => {
async getUserInput => {
try {
const data1 = await $.get(getUserInput('url') + '/api/convert?input=1gal');
assert.equal(data1.initUnit, 'gal');
@ -128,10 +162,10 @@ async (getUserInput) => {
};
```
If my unit of measurement is invalid, returned will be `'invalid unit'`.
If the unit of measurement is invalid, returned will be `'invalid unit'`.
```js
async (getUserInput) => {
async getUserInput => {
try {
const data = await $.get(getUserInput('url') + '/api/convert?input=1min');
assert(data.error === 'invalid unit' || data === 'invalid unit');
@ -141,10 +175,10 @@ async (getUserInput) => {
};
```
If my number is invalid, returned will be `'invalid number'`.
If the number is invalid, returned will be `'invalid number'`.
```js
async (getUserInput) => {
async getUserInput => {
try {
const data = await $.get(
getUserInput('url') + '/api/convert?input=1//2gal'
@ -159,7 +193,7 @@ async (getUserInput) => {
If both the unit and number are invalid, returned will be `'invalid number and unit'`.
```js
async (getUserInput) => {
async getUserInput => {
try {
const data = await $.get(
getUserInput('url') + '/api/convert?input=1//2min'
@ -174,10 +208,10 @@ async (getUserInput) => {
};
```
I can use fractions, decimals or both in my parameter(ie. 5, 1/2, 2.5/6), but if nothing is provided it will default to 1.
You can use fractions, decimals or both in the parameter (ie. 5, 1/2, 2.5/6), but if nothing is provided it will default to 1.
```js
async (getUserInput) => {
async getUserInput => {
try {
const data1 = await $.get(getUserInput('url') + '/api/convert?input=mi');
assert.approximately(data1.initNum, 1, 0.001);
@ -205,10 +239,10 @@ async (getUserInput) => {
};
```
My return will consist of the `initNum`, `initUnit`, `returnNum`, `returnUnit`, and `string` spelling out units in the format `'{initNum} {initial_Units} converts to {returnNum} {return_Units}'` with the result rounded to 5 decimals.
Your return will consist of the `initNum`, `initUnit`, `returnNum`, `returnUnit`, and `string` spelling out units in the format `'{initNum} {initUnitString} converts to {returnNum} {returnUnitString}'` with the result rounded to 5 decimals.
```js
async (getUserInput) => {
async getUserInput => {
try {
const data = await $.get(getUserInput('url') + '/api/convert?input=2mi');
assert.equal(data.initNum, 2);
@ -225,15 +259,15 @@ async (getUserInput) => {
All 16 unit tests are complete and passing.
```js
async (getUserInput) => {
async getUserInput => {
try {
const getTests = await $.get(getUserInput('url') + '/_api/get-tests');
assert.isArray(getTests);
const unitTests = getTests.filter((test) => {
return !!test.context.match(/Unit Tests ->/gi);
const unitTests = getTests.filter(test => {
return !!test.context.match(/Unit Tests/gi);
});
assert.isAtLeast(unitTests.length, 16, 'At least 16 tests passed');
unitTests.forEach((test) => {
unitTests.forEach(test => {
assert.equal(test.state, 'passed', 'Tests in Passed State');
assert.isAtLeast(
test.assertions.length,
@ -250,15 +284,15 @@ async (getUserInput) => {
All 5 functional tests are complete and passing.
```js
async (getUserInput) => {
async getUserInput => {
try {
const getTests = await $.get(getUserInput('url') + '/_api/get-tests');
assert.isArray(getTests);
const functTests = getTests.filter((test) => {
return !!test.context.match(/Functional Tests ->/gi);
const functTests = getTests.filter(test => {
return !!test.context.match(/Functional Tests/gi);
});
assert.isAtLeast(functTests.length, 5, 'At least 5 tests passed');
functTests.forEach((test) => {
functTests.forEach(test => {
assert.equal(test.state, 'passed', 'Tests in Passed State');
assert.isAtLeast(
test.assertions.length,