Metric-Imperial Converter: Passes all test in my local machine but not passing FCC test

Hi,
I am doing Metric-Imperial Converter, I have written all the required and all test passing my local machine but when I submit the two of FCC test fail. I think there is some problem with the validation of numbers but I am not able to figure it out. Here is the link to my project: https://fcc---metric---imperial---converter.glitch.me/

Tests expect:
1//2gal to return invalid number
and
1//2min to return invalid number and unit

Hi @jenovs
It is returning as expected. Please verify with the provided project link on Glitch.
Regards!

Apparently it’s not:
https://fcc---metric---imperial---converter.glitch.me/api/convert?input=1//2gal

It’s working fine in GUI. I have separately try getNum function with the above-mentioned input and its return invalid number. Now when I am printing the input to console with above input using GUI then it is printing 1//5mi but when I assess with URL(provide by you) then its printing 1/5mi. Using URL I also provide 1///5mi but it still prints 1/5mi.

When you’re sending via GUI, this is what is get sent:
https://fcc---metric---imperial---converter.glitch.me/api/convert?input=1%2F%2F2gal
(jQuery’s .serialize() replaces // with “safe” escape values).

1 Like

And why when I am sending with URL //.. reduced to /? What are some ways to overcome these problems?

Looks like it’s the glitch server who is smashing your slashes together. Try using different hosting.

It worked! Thanks, @jenovs for your help, I really appreciate it. BTW how do you get to know about these errors and how can I find such an error myself. I was stuck with this for almost a day.

I checked the code locally and it was working (so it was not a code problem).
Then I checked the FCC’s example project and it was also working (so it was not a browser problem).
Therefore request was transformed somewhere in between (glitch server?, proxy?, load balancer?, cdn?) before reaching your express server. So the logical step was to try different provider.

1 Like

Hi, @jenovs
Is there any way I can run the FCC test locally so that I can know how our test fails? While submitting the project I can only get only pass/fail no reason why it’s failing. If I can test locally before submitting then I can know what is suppose to output and what my program is outputting and it would make the process much faster.
Thanks!

I’m not too familiar with FCC’s source code, but you can see the seed for this challenge here: https://github.com/freeCodeCamp/freeCodeCamp/blob/master/curriculum/challenges/english/06-quality-assurance/quality-assurance-projects/metric-imperial-converter.md

You can fork the source and try to run it locally, but I would just create a couple of helpers and copy/paste the relevant tests. Something like this:

// imports
const assert = require('assert');
const fetch = require('node-fetch');

// url to test
const url = 'https://fcc---metric---imperial---converter.glitch.me';

// fetch helper
const $ = {
  get: (url) => fetch(url).then((res) => res.json()),
};

// test cases - copy/paste from FCC source and assign to variable
const test1 = async (getUserInput) => {
  try {
    const data1 = await $.get(getUserInput('url') + '/api/convert?input=1gal');
    assert.equal(data1.returnNum, 3.785411);
    assert.equal(data1.returnUnit, 'L');
    const data2 = await $.get(getUserInput('url') + '/api/convert?input=10gal');
    assert.equal(data2.returnNum, 37.8541);
    assert.equal(data2.returnUnit, 'L');
    const data3 = await $.get(getUserInput('url') + '/api/convert?input=1l');
    assert.equal(data3.returnNum, 0.26417);
    assert.equal(data3.returnUnit, 'gal');
    const data4 = await $.get(getUserInput('url') + '/api/convert?input=10l');
    assert.equal(data4.returnNum, 2.64172);
    assert.equal(data4.returnUnit, 'gal');
  } catch (xhr) {
    throw new Error(xhr.responseText || xhr.message);
  }
};

// run test cases
test1(() => url);