Backend API Exercise tracker tests failing because of response format(?)/structure(?)

Hi there,

Here is the link for my repl:

I can’t undestand why this particular test is failing :

  • The response returned from POST /api/users/:_id/exercises will be the user object with the exercise fields added.

Since the result you get when calling the server I wrote is :

  "date":"Tue Mar 21 2023",

This is what the exercise is asking for, isn’t it ?

Best regards

That is not what your response is for the test:

Request URL:
{"error":"No User exists for that ID."}

const _id = req.body[":_id"];

Are you sure that is the correct way of getting the id when passed as a params?

Test URL (params)


Test payload (body)

description: test
duration: 60
date: 1990-01-01

You can also look in the views/index.html file to see how the form submission is handled.

Oh so …I should be able to post an exercise even if the user does not exist ?

I can get the id using this :

const _id = req.body[":_id"];

The only difference I have seen so far , is this :

If I POST to /api/users/641a2717570d8a793a7bda9a/exercises for the official example, I get :

[object Object]

If I POST to /api/users/641a2717570d8a793a7bda9a/exercises to my server, l get :

"error": "No User exists for that ID."

OMG, yes !! Found out the problem was me getting the id from the request body and not the URL parameters. Don’t know why but it mattered for the tests!!

What the hell !! And I was looking on it for so long! Nice !

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