fix: update exercise tracker test endpoints and test text (#41786)
* fix: update exercise tracker test endpoints and test text * Update curriculum/challenges/english/05-apis-and-microservices/apis-and-microservices-projects/exercise-tracker.md Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com> * Update curriculum/challenges/english/05-apis-and-microservices/apis-and-microservices-projects/exercise-tracker.md Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com> * Update curriculum/challenges/english/05-apis-and-microservices/apis-and-microservices-projects/exercise-tracker.md Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com> * Update curriculum/challenges/english/05-apis-and-microservices/apis-and-microservices-projects/exercise-tracker.md Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com> Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
70a28cc528
commit
986275a6bc
@ -29,12 +29,12 @@ You should provide your own project, not the example URL.
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
You can `POST` to `/api/exercise/new-user` with form data `username` to create a new user. The returned response will be an object with `username` and `_id` properties.
|
You can `POST` to `/api/users` with form data `username` to create a new user. The returned response will be an object with `username` and `_id` properties.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const url = getUserInput('url');
|
const url = getUserInput('url');
|
||||||
const res = await fetch(url + '/api/exercise/new-user', {
|
const res = await fetch(url + '/api/users', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
||||||
@ -49,12 +49,12 @@ async (getUserInput) => {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
You can make a `GET` request to `api/exercise/users` to get an array of all users. Each element in the array is an object containing a user's `username` and `_id`.
|
You can make a `GET` request to `/api/users` to get an array of all users. Each element in the array is an object containing a user's `username` and `_id`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const url = getUserInput('url');
|
const url = getUserInput('url');
|
||||||
const res = await fetch(url + '/api/exercise/users');
|
const res = await fetch(url + '/api/users');
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
assert.isArray(data);
|
assert.isArray(data);
|
||||||
@ -66,12 +66,12 @@ async (getUserInput) => {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
You can `POST` to `/api/exercise/add` with form data `userId=_id`, `description`, `duration`, and optionally `date`. If no date is supplied, the current date will be used. The response returned will be the user object with the exercise fields added.
|
You can `POST` to `/api/users/:_id/exercises` with form data `description`, `duration`, and optionally `date`. If no date is supplied, the current date will be used. The response returned will be the user object with the exercise fields added.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const url = getUserInput('url');
|
const url = getUserInput('url');
|
||||||
const res = await fetch(url + '/api/exercise/new-user', {
|
const res = await fetch(url + '/api/users', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
||||||
@ -85,10 +85,10 @@ async (getUserInput) => {
|
|||||||
_id,
|
_id,
|
||||||
date: 'Mon Jan 01 1990'
|
date: 'Mon Jan 01 1990'
|
||||||
};
|
};
|
||||||
const addRes = await fetch(url + '/api/exercise/add', {
|
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `userId=${_id}&description=${expected.description}&duration=${expected.duration}&date=1990-01-01`
|
body: `description=${expected.description}&duration=${expected.duration}&date=1990-01-01`
|
||||||
});
|
});
|
||||||
if (addRes.ok) {
|
if (addRes.ok) {
|
||||||
const actual = await addRes.json();
|
const actual = await addRes.json();
|
||||||
@ -102,12 +102,12 @@ async (getUserInput) => {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
You can make a `GET` request to `/api/exercise/log` with a parameter of `userId=_id` to retrieve a full exercise log of any user. The returned response will be the user object with a `log` array of all the exercises added. Each log item has the `description`, `duration`, and `date` properties.
|
You can make a `GET` request to `/api/users/:_id/logs` to retrieve a full exercise log of any user. The returned response will be the user object with a `log` array of all the exercises added. Each log item has the `description`, `duration`, and `date` properties.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const url = getUserInput('url');
|
const url = getUserInput('url');
|
||||||
const res = await fetch(url + '/api/exercise/new-user', {
|
const res = await fetch(url + '/api/users', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
||||||
@ -121,13 +121,13 @@ async (getUserInput) => {
|
|||||||
_id,
|
_id,
|
||||||
date: new Date().toDateString()
|
date: new Date().toDateString()
|
||||||
};
|
};
|
||||||
const addRes = await fetch(url + '/api/exercise/add', {
|
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `userId=${_id}&description=${expected.description}&duration=${expected.duration}`
|
body: `description=${expected.description}&duration=${expected.duration}`
|
||||||
});
|
});
|
||||||
if (addRes.ok) {
|
if (addRes.ok) {
|
||||||
const logRes = await fetch(url + `/api/exercise/log?userId=${_id}`);
|
const logRes = await fetch(url + `/api/users/${_id}/logs`);
|
||||||
if (logRes.ok) {
|
if (logRes.ok) {
|
||||||
const { log } = await logRes.json();
|
const { log } = await logRes.json();
|
||||||
assert.isArray(log);
|
assert.isArray(log);
|
||||||
@ -144,12 +144,12 @@ async (getUserInput) => {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
A request to a user's log (`/api/exercise/log`) returns an object with a `count` property representing the number of exercises returned.
|
A request to a user's log (`/api/users/:_id/logs`) returns an object with a `count` property representing the number of exercises returned.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const url = getUserInput('url');
|
const url = getUserInput('url');
|
||||||
const res = await fetch(url + '/api/exercise/new-user', {
|
const res = await fetch(url + '/api/users', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
||||||
@ -163,13 +163,13 @@ async (getUserInput) => {
|
|||||||
_id,
|
_id,
|
||||||
date: new Date().toDateString()
|
date: new Date().toDateString()
|
||||||
};
|
};
|
||||||
const addRes = await fetch(url + '/api/exercise/add', {
|
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `userId=${_id}&description=${expected.description}&duration=${expected.duration}`
|
body: `description=${expected.description}&duration=${expected.duration}`
|
||||||
});
|
});
|
||||||
if (addRes.ok) {
|
if (addRes.ok) {
|
||||||
const logRes = await fetch(url + `/api/exercise/log?userId=${_id}`);
|
const logRes = await fetch(url + `/api/users/${_id}/logs`);
|
||||||
if (logRes.ok) {
|
if (logRes.ok) {
|
||||||
const { count } = await logRes.json();
|
const { count } = await logRes.json();
|
||||||
assert(count);
|
assert(count);
|
||||||
@ -185,12 +185,12 @@ async (getUserInput) => {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
You can add `from`, `to` and `limit` parameters to a `/api/exercise/log` request to retrieve part of the log of any user. `from` and `to` are dates in `yyyy-mm-dd` format. `limit` is an integer of how many logs to send back.
|
You can add `from`, `to` and `limit` parameters to a `/api/users/:_id/logs` request to retrieve part of the log of any user. `from` and `to` are dates in `yyyy-mm-dd` format. `limit` is an integer of how many logs to send back.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const url = getUserInput('url');
|
const url = getUserInput('url');
|
||||||
const res = await fetch(url + '/api/exercise/new-user', {
|
const res = await fetch(url + '/api/users', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
||||||
@ -204,19 +204,19 @@ async (getUserInput) => {
|
|||||||
_id,
|
_id,
|
||||||
date: new Date().toDateString()
|
date: new Date().toDateString()
|
||||||
};
|
};
|
||||||
const addExerciseRes = await fetch(url + '/api/exercise/add', {
|
const addExerciseRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `userId=${_id}&description=${expected.description}&duration=${expected.duration}&date=1990-01-01`
|
body: `description=${expected.description}&duration=${expected.duration}&date=1990-01-01`
|
||||||
});
|
});
|
||||||
const addExerciseTwoRes = await fetch(url + '/api/exercise/add', {
|
const addExerciseTwoRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `userId=${_id}&description=${expected.description}&duration=${expected.duration}&date=1990-01-02`
|
body: `description=${expected.description}&duration=${expected.duration}&date=1990-01-02`
|
||||||
});
|
});
|
||||||
if (addExerciseRes.ok && addExerciseTwoRes.ok) {
|
if (addExerciseRes.ok && addExerciseTwoRes.ok) {
|
||||||
const logRes = await fetch(
|
const logRes = await fetch(
|
||||||
url + `/api/exercise/log?userId=${_id}&from=1989-12-31&to=1990-01-03`
|
url + `/api/users/${_id}/logs?from=1989-12-31&to=1990-01-03`
|
||||||
);
|
);
|
||||||
if (logRes.ok) {
|
if (logRes.ok) {
|
||||||
const { log } = await logRes.json();
|
const { log } = await logRes.json();
|
||||||
@ -226,7 +226,7 @@ async (getUserInput) => {
|
|||||||
throw new Error(`${logRes.status} ${logRes.statusText}`);
|
throw new Error(`${logRes.status} ${logRes.statusText}`);
|
||||||
}
|
}
|
||||||
const limitRes = await fetch(
|
const limitRes = await fetch(
|
||||||
url + `/api/exercise/log?userId=${_id}&limit=1`
|
url + `/api/users/${_id}/logs?limit=1`
|
||||||
);
|
);
|
||||||
if (limitRes.ok) {
|
if (limitRes.ok) {
|
||||||
const { log } = await limitRes.json();
|
const { log } = await limitRes.json();
|
||||||
|
Reference in New Issue
Block a user