Boss Machine: How can I test some requests and see the responses I get?

Hello all,

I am doing the Boss Machine API challenge:

https://www.codecademy.com/paths/web-development/tracks/javascript-back-end-development/modules/express-cumulative-project/informationals/bapi-p4-boss-machine

And I’m struggling to find out why the test module is telling me the GET /minions/:minionId route is returning status 200 - OK when it feeds it both a non-numeric ID as well as an invalid ID.

The code I have set up is:

apiRouter.get('/minions/:minionId', (req, res, next) => {
    const minionId = String(req.params.minionId);
    const foundMinion = getFromDatabaseById('minions', minionId);
    if (foundMinion !== null) {
        res.send(foundMinion);
    } else {
        res.status(404).send('Not found');
    };
});

I am at a loss since the getFromDatabaseById helper function is supposed to return a null result in both these cases, which should then be routed towards the 404 status through my code.

Anyway, beyond knowing if any of you can spot what may be wrong here, I had a general question which is:

  • is there anyway that I can manually check requests and consult the responses I get? Can I write a request in a console or so and see what response I get back? That would allow me to do test cases with specific values and see where the response is going wrong.

Can this be done ? I suppose the Node.js environment allows for this but I’m not sure how to go about it.

Thanks in advance for your help,
Nuno

Nevermind, question solved. :slight_smile:

Could you share your solution to this problem? I was wondering this as well. Thanks!