Not sure, but I think negative numbers are valid input to the Date constructor. So, new Date(-1) would evaluate to one millisecond before 1970-01-01. Anyway, with your program an input of “-1” would not be converted to a number, and so would be evaluated as a string, giving you an invalid date.
It’s definitely the handling of a parseable date string problem. This
seems to be looking for a dash in a date string on the assumption that they will all be like 2011-10-05 when the test actually uses 05 October 2011 as the test value, which will get matched as invalid by this code.
That wasn’t necessarily the only problem; just the one I spotted first. As always, the easiest way to debug is to log your route inputs with console.log(dataParam); and your route responses right before your response, everywhere there is a response. Then run the tests against your project and look at the logs.
Two other things: first, you need to return at responses, like return res.json(...);. This code will send multiple responses if the conditional matches.
Second, new Date(...) will return Invalid Date on invalid dates.