Metric-Imperial Converter - Intent behind Test Assertions?

I’m at the point in my Metric-Imperial Converter project that things are pretty much working and I began completing the unit tests in ./tests/1_unit-tests.js. But, I’m not sure of the intent behind this one so I’m not sure how I want to write it:

test('Fractional Input', function(done) {
      
      //done();
    });

One user story states “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.”

Another user story states “My return will consist of the initNum, initUnit, returnNum, returnUnit, and string spelling out units in format {initNum} {initial_Units} converts to {returnNum} {return_Units} with the result rounded to 5 decimals.”

So, my app allows for initNum to contain a fraction and will still do conversion. But, I don’t modify the fraction in my getNum function, so that my response will still include the original value of {initNum}. In other words, if I submit 5.4/3lbs, my response is:

{"initNum":"5.4/3","initUnit":"lbs","returnNum":0.8164656,"returnUnit":"kg","string":"5.4/3 pounds converts to 0.81647 kilograms"}

I still calculate the value to get my returnNum, but I leave my initNum as it was entered so that I report back the value the user entered.

Was the intent behind the unit test, that the fraction would be resolved to a decimal in the getNum function? Or merely to allow a fraction as valid input? I think this test could be written to assert either one but the intent is unclear.

Was the initNum sent in the JSON response intended to be the value as entered by the user (e.g., “1/2”), or the computed value (e.g. 0.5)?

Since the challenge page currently appears to allow any URL to pass, I want to write my app and my tests in good faith as much as possible.

browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Metric-Imperial Converter

Link to the challenge:
https://www.freecodecamp.org/learn/information-security-and-quality-assurance/information-security-and-quality-assurance-projects/metric-imperial-converter

1 Like