Issue Tracker (PUT issues)

Section: Quality Assurance
Project: Issue Tracker

My PUT route isn’t passing the “successful update” test even though it updates perfectly fine. I logged the results from the FCC update test and it updates correctly. I also passed all the “error” test cases for the PUT route.

My Update Code:
( I stored the update-fields in the “updates” variable which I pass to $set )

// Update issue
        Issue.findByIdAndUpdate(req.body._id, {
          $set: updates
        }, {
          new: true
        }, (err, data) => {
          // Check for errors
          if(err || !data) {
            console.log("[ Error ]\n" + err)
              error: "could not update",
              _id: req.body._id 
          } else {
            console.log("[ Found Issue ]\n" + data)
              result: "successfully updated",
              _id: req.body._id

Need a or the rest of your code. It’s easier to debug code if you can run it. Plus, the error could be elsewhere even if the other tests pass.

You indicate that you are logging the results, but I don’t see where you are actually logging the response. You can copy/paste a call to res.json() and replace it with console.log() to see what is being sent. Also, you’re not logging the issue pre and post update or the updates, so the record may not be updating correctly. I think this test does a POST, a PUT, and then checks with a GET so if there’s a problem anywhere the test fails.

Regardless, it’s all speculation without the code.

Added my replit link. I initially removed to console.logs to make the code cleaner

It looks like your GET is not returning the correct data which is causing the PUT test to fail. I didn’t really check, but you may need to verify your POST is correct too (even though the tests appear good).

If you run the tests with the browser console open, there are three errors. The first mentions an expected property of created_on and you have createdAt in your issue and you are just returning the issue data without changing the field names. The second complains of a NaN with is probably a test looking for the above property, not finding it, and casting the result to a number. The third is your test suite not running.

Looking at some old code and I have comments indicating that created_on is the field to be sent in the JSON responses. You can store it however you like so you could keep createdAt in your model.

Thanks. I just needed to rename to default timestamp fields to the specific fields expected.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.