Not understanding why my Exercise Tracker project is failing

When I run the tests on my Exercise tracker it consistently fails the test on the /api/exercise/add route and occasionally fails the test on the /api/exercise/log route, even when I haven’t changed the code under that route between tests.'/api/exercise/add', async (req, res) => {
  try {
    let { userId, description, duration, date } = req.body;
    const user = await User.findById(userId, '_id username').lean();
    if (!date) {
      date = dayjs().format('YYYY-MM-DD');
    const activity = new Activity({
      userId: userId,
      description: description,
      duration: duration,
      date, date
    }); = date
    user.duration = duration;
    user.description = description;

  catch (err) {

this is the code for the /add route and it seems to work properly when I look at the response page.

Is there anything obvious that I’ve overlooked?

You can find the app here
and a userId that has a decent amount of exercises logged is 5fced7e87e1038135b4bfef1

I just noticed that I’m getting this error in my browser console when I run the tests.

Access to fetch at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Does anything in my code remove that header?

Ok. I solved this one!

The tests are looking for very specific formats.

The key “duration” must be a number.

The key “date” must be a date string.

Nowhere in the user stories does it say this, but once I made those changes my tests passed.

The CORS issue I was having last night went away on its own, so not sure what happened with that.

Thank you, for bringing this up again. I have opened an issue on the GitHub repository to get more information added to the description.

1 Like