Assert statements metric converter

what am I supposed to fill in the assert statements

 test("Convert 10L (valid input)", function(done) {
        chai
          .request(server)
          .get("/api/convert")
          .query({ input: "10L" })
          .end(function(err, res) {
            assert.equal(res.status, 200);
            assert.equal(res.body.initNum, 10); //  <-
// here I enter a invalid number then what should I enter here
            assert.equal(res.body.initUnit, "l");
            assert.approximately(res.body.returnNum, 2.64172, 0.1);
            assert.equal(res.body.returnUnit, "gal");
            done();
          });
      });
1 Like

@Advitya-sharma, try with input 10l (not capital). If it solves, and even after if you want to put also 10L, you need to do some more work on the main app

no I’m not asking about this
what I’m interested in knowing is
if I enter a invalid number eg 34kx
then what I need to enter in
assert.equal(res.body.initUnit, "l");
and
assert.equal(res.body.returnUnit, "gal");

if you put 34l your code will give a valid output as per logic in the main app, and the output will be in gal. Now, if you put 34kx it will return an error as you set in your main app.
So, if you test code with wrong input, your assert need to fill something like this,
assert.noEqual(res.body.yourTestUnit, 'l')
or
assert.equal(res.body.yourTestUnitHere, 'yourErrorTextHereAsYouSetInYourApp')

the second functional test is not passing, the changed the code so that it return undefined

@Advitya-sharma,
Since, -g- is not defined , it would result invalid unit and should not go for further check to convert the item, rejecting one part - you can reject the whole thing with null/undefined value

something like this

      var input = req.query.input;
      var initNum = convertHandler.getNum(input);
      var initUnit = convertHandler.getUnit(input);
        if(initNum == undefined){
      res.json({initNum:initNum,initUnit:undefined,returnNum:undefined,returnUnit:undefined,toString:undefined});
    }
      ```

TypeError: Cannot read property 'toLowerCase' of undefined at ConvertHandler.convert (/app/controllers/convertHandler.js:125:22) at /app/routes/api.js:26:38

this is the output for wrong unit input. The problem is inside your main app, not in the testing part, try to understand the error, and fix it from there, then come back to the testing part

1 Like

yes I fixed this issue , how did you found this It was not showing any error

1 Like

I followed the route you’re working on, you’we testing ‘/api/convert’ and sending the query {input:'32g'}, So, the main app link is
your-site-url/api/convert?input=32g, that showed the error
@Advitya-sharma

1 Like

could you check the
Convert 3/7.2/4kg (invalid number) test
when I console.log in api.js its showing results but the JSON object returned is empty

     
    console.log(initNum);
    console.log(initUnit);
    console.log(returnNum);
    console.log(returnUnit);
    console.log(toString);