Expresso project: I think the test for POST to Timesheet & Menuitem could be wrong

I have successfully completed the routes for Employee and am working on the routes for the dependent table Timesheet. LINK
I am on the POST route and all of my tests pass, except the one that says:

should return a 400 status code for invalid timesheets

But, my code checks if the employeeId is valid with this code:

db.get('SELECT * FROM Employee WHERE = $employeeId', {$employeeId: employeeId}, (error, employee) => {
    if(error) {

If the query does not find a matching ID, wouldn’t it throw a 404 (not found) erro?
The test.js is checking to see if it throws a 400 error.

it('should return a 400 status code for invalid timesheets', function() {
    newTimesheet = {
      rate: 3.5,
      date: 100
    return request(app)
        .send({timesheet: newTimesheet})

If I change the test.js code to expect(404); , the test passes.

The instructions for this part even asks for a 404 error!


  • Creates a new timesheet, related to the employee with the supplied employee ID, with the information from the timesheet property of the request body and saves it to the database. Returns a 201 response with the newly-created timesheet on the timesheet property of the response body
  • If an employee with the supplied employee ID doesn’t exist, returns a 404 response

Am I wrong here?
Which should it be, 400 or 404?
Could my ID checking query even be able to throw a 400 error?

Still stuck on this…

Your code snippet and the code snippet from the test don’t directly match up. Your code snippet is about verifying the employeeId, while the test is verifying that a new timesheet being submitted requires all the fields (notice it’s intentionally missing the hours field).

If anything, the instructions are missing the following for that specific route:

  • If any required fields are missing, returns a 400 response

Which was included in 7 other spots in the instructions (every other PUT and POST route). It’s still the exact functionality they’re testing for.

Thank you for pointing that out.
I had been staring at the same code for hours trying to figure it and got my tests mixed up.
I really should have walked away from it for a few minutes and cleared my head.
I’m always grateful that there are patient members willing to point us in the right direction.


1 Like