Boss Machine Bonus

I’ve been able to complete the Boss Machine project and the bonus challenges except for one last test. I keep getting this error and it’s doing my head in:

1) checkMillionDollarIdea middleware
       calls next for ideas that will yield at least one million dollars:
     AssertionError: expected 400 to equal null
      at Context.<anonymous> (test\test.js:480:23)
      at processImmediate (internal/timers.js:461:21)

Here’s my middleware:

const checkMillionDollarIdea = (req, res, next) => {
  const idea = req.body;
  idea.numWeeks = Number(idea.numWeeks);
  idea.weeklyRevenue = Number(idea.weeklyRevenue);
  if (
    typeof idea.description === "string" &&
    typeof === "string" && > 0 &&
    typeof idea.numWeeks === "number" &&
    typeof idea.weeklyRevenue === "number" &&
    idea.weeklyRevenue * idea.numWeeks >= 1000000
  ) {
  } else {

// Leave this exports assignment so that the function can be used elsewhere
module.exports = checkMillionDollarIdea;

I don’t understand the problem because the routes work as intended, so the 1000000 check is working?!
Any suggestions?

The logic of your middleware is sound, but it’s trying to do too much verification for the test. It shouldn’t be worried about validating the description and name. It’s only concern is numWeeks and weeklyRevenue.

If you look into the tests themselves or if you do a console.log() of req.body, you’ll find that those tests don’t pass in a name or description, so your conditional causes it to send an error 400 no matter what

Good work completing the project!

So I don’t need to worry about it as longs as it works, it just works better than intended.

It’s not necessarily better. This middleware specializes in rejecting ideas that aren’t worth a million. The rest of the validation would already be handled if it makes it past this middleware when next() is called. It can be rejected there if it’s missing anything that is required.

Validating the same fields in both spots would mean that future updates would need changes in multiple areas too, which could be problematic for larger projects with multiple developers. For example, if the decision to make the field “description” optional was made, knowing that changes must be made in the checkMillionDollarIdea middleware too may not be apparent.