You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cURL is by default already installed in Mac OS. For Windows, you can download cURL separately.
55
-
You can send different HTTP requests.
53
+
cURL stands for Client URL.
54
+
cURL is by default already installed in Mac OS. For Windows, if you have anything older than Windows 10 build 1706, you can download cURL separately. Else, you might already have cURL.
55
+
56
+
You can send different HTTP requests using cURL.
56
57
57
58
For example, let's send a POST request to https://localhost:3000/ with a JSON message body.
Sometimes, we do not want to test for an exact match for the response object. We are satisfied with having certain object properties. We can make use of a useful Jest method called `toMatchObject`.
294
+
295
+
One possible use of this is for the GET /songs/:id route.
296
+
297
+
```js
298
+
it("GET /songs/:id should return the correct song", () => {
@@ -262,6 +334,112 @@ There are some cases where we need to reuse the agent again. For example, we mig
262
334
263
335
Check the [github page for supertest](https://github.com/visionmedia/supertest) for an example on how to access the agent in SuperTest and reuse the agent to persist a request and its cookies.
264
336
265
-
## Exercises
337
+
## Exercises
338
+
339
+
Add tests to the existing songs API we have been building.
340
+
341
+
## TDD with Express.js
266
342
267
-
Add tests to the songs API we have been building.
343
+
Besides songs and the music industry, now our company would like to go into the movie industry. We need more routes on our API. They will now return movie information.
344
+
345
+
Let's try TDD for movie routes.
346
+
347
+
Add the tests for the movies endpoints.
348
+
349
+
Test: POST /movies should return a new movie object
350
+
Route: POST /movies
351
+
Expected response status code: 201
352
+
Example request body:
353
+
354
+
```json
355
+
{
356
+
"movieName": "Lion King"
357
+
}
358
+
```
359
+
360
+
Example JSON response:
361
+
362
+
```json
363
+
{
364
+
"id": 1,
365
+
"movieName": "Lion King"
366
+
}
367
+
```
368
+
369
+
Test: GET /songs should return an array containing one song
370
+
Route: GET /movies
371
+
Expected response status code: 200
372
+
Example JSON response:
373
+
374
+
```json
375
+
[
376
+
{
377
+
"id": 1,
378
+
"movieName": "Lion King"
379
+
}
380
+
]
381
+
```
382
+
383
+
Test: GET /movies/:id should return the movie with id
384
+
Route: GET /movies/1
385
+
Expected response status code: 200
386
+
Example JSON response:
387
+
388
+
```json
389
+
{
390
+
"id": 1,
391
+
"movieName": "Lion King"
392
+
}
393
+
```
394
+
395
+
Test: PUT /movies/:id should return the updated movie
396
+
Route: PUT /movies/1
397
+
Expected response status code: 200
398
+
399
+
Example request body:
400
+
401
+
```json
402
+
{
403
+
"movieName": "Frozen 2"
404
+
}
405
+
```
406
+
407
+
Example JSON response:
408
+
409
+
```json
410
+
{
411
+
"id": 1,
412
+
"movieName": "Frozen 2"
413
+
}
414
+
```
415
+
416
+
Test: DELETE /movies/:id should return the deleted movie
0 commit comments