Exercise Tracker(Last test)

**Tell us what’s happening: Unable to pass last test, can easily perform the test locally. But looks like i m missing some trick…is it json structure or something else?
I m actually not able to see what kind of JSON response test needs?
any help will be appreciated!

Your project link(s)

solution: GitHub - Samcanes/boilerplate-project-exercisetracker: A boilerplate for a freeCodeCamp project.
Live app: //https://morning-plateau-70797.herokuapp.com

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36.

Challenge: Exercise Tracker

Link to the challenge:

Hello there,

Here is the test:

async (getUserInput) => {
  const url = getUserInput('url');
  const res = await fetch(url + '/api/exercise/new-user', {
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    body: `username=fcc_test_${Date.now()}`.substr(0, 29)
  });
  if (res.ok) {
    const { _id, username } = await res.json();
    const expected = {
      username,
      description: 'test',
      duration: 60,
      _id,
      date: new Date().toDateString()
    };
    const addExerciseRes = await fetch(url + '/api/exercise/add', {
      method: 'POST',
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
      body: `userId=${_id}&description=${expected.description}&duration=${expected.duration}&date=1990-01-01`
    });
    const addExerciseTwoRes = await fetch(url + '/api/exercise/add', {
      method: 'POST',
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
      body: `userId=${_id}&description=${expected.description}&duration=${expected.duration}&date=1990-01-02`
    });
    if (addExerciseRes.ok && addExerciseTwoRes.ok) {
      const logRes = await fetch(
        url + `/api/exercise/log?userId=${_id}&from=1989-12-31&to=1990-01-03`
      );
      if (logRes.ok) {
        const { log } = await logRes.json();
        assert.isArray(log);
        assert.equal(2, log.length);
      } else {
        throw new Error(`${logRes.status} ${logRes.statusText}`);
      }
      const limitRes = await fetch(
        url + `/api/exercise/log?userId=${_id}&limit=1`
      );
      if (limitRes.ok) {
        const { log } = await limitRes.json();
        assert.isArray(log);
        assert.equal(1, log.length);
      } else {
        throw new Error(`${limitRes.status} ${limitRes.statusText}`);
      }
    } else {
      throw new Error(`${res.status} ${res.statusText}`);
    }
  } else {
    throw new Error(`${res.status} ${res.statusText}`);
  }
};

Summarised, it does this:

  • Creates a new user
  • Adds two exercises to the user
  • Requests a log of the user between two dates, and expects a log returned with a length of 2
  • Requests a log of the user with a limit of 1, and expects the return to contain 1 object. (Does not actually have to be an object)

Hope this helps

1 Like

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