Skip to content

Commit efd7bf4

Browse files
committed
part 4a
1 parent 1820cc5 commit efd7bf4

File tree

3 files changed

+198
-143
lines changed

3 files changed

+198
-143
lines changed

src/content/4/en/part4a.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = {
5252

5353
The logger has two functions, __info__ for printing normal log messages, and __error__ for all error messages.
5454

55-
Extracting logging into its own module is a good idea in more ways than one. If we wanted to start writing logs to a file or send them to an external logging service like [graylog](https://www.graylog.org/) or [papertrail](https://papertrailapp.com) we would only have to make changes in one place.
55+
Extracting logging into its own module is a good idea in several ways. If we wanted to start writing logs to a file or send them to an external logging service like [graylog](https://www.graylog.org/) or [papertrail](https://papertrailapp.com) we would only have to make changes in one place.
5656

5757
The handling of environment variables is extracted into a separate <i>utils/config.js</i> file:
5858

@@ -178,13 +178,13 @@ All routes are now defined for the router object, similar to what I did before w
178178
It's worth noting that the paths in the route handlers have shortened. In the previous version, we had:
179179

180180
```js
181-
app.delete('/api/notes/:id', (request, response) => {
181+
app.delete('/api/notes/:id', (request, response, next) => {
182182
```
183183
184184
And in the current version, we have:
185185
186186
```js
187-
notesRouter.delete('/:id', (request, response) => {
187+
notesRouter.delete('/:id', (request, response, next) => {
188188
```
189189
190190
So what are these router objects exactly? The Express manual provides the following explanation:
@@ -323,7 +323,7 @@ To recap, the directory structure looks like this after the changes have been ma
323323
324324
For smaller applications, the structure does not matter that much. Once the application starts to grow in size, you are going to have to establish some kind of structure and separate the different responsibilities of the application into separate modules. This will make developing the application much easier.
325325
326-
There is no strict directory structure or file naming convention that is required for Express applications. In contrast, Ruby on Rails does require a specific structure. Our current structure simply follows some of the best practices you can come across on the internet.
326+
There is no strict directory structure or file naming convention that is required for Express applications. In contrast, Ruby on Rails does require a specific structure. Our current structure simply follows some of the best practices that you can come across on the internet.
327327
328328
You can find the code for our current application in its entirety in the <i>part4-1</i> branch of [this GitHub repository](https://github.com/fullstack-hy2020/part3-notes-backend/tree/part4-1).
329329
@@ -401,25 +401,23 @@ The nature of VS Code bleeding into how you write your code is probably not idea
401401
402402
</div>
403403
404-
405-
406404
<div class="tasks">
407405
408406
### Exercises 4.1.-4.2.
409407
410408
In the exercises for this part, we will be building a <i>blog list application</i>, that allows users to save information about interesting blogs they have stumbled across on the internet. For each listed blog we will save the author, title, URL, and amount of upvotes from users of the application.
411409
412-
**Note** You should install Mongoose version 7.6.5 with the command
410+
**Note:** You should install Mongoose version 7.6.5 with the command:
413411
414412
```bash
415413
npm install mongoose@7.6.5
416414
```
417415
418416
since the most recent Mongoose version does not support a library that we will be using in a later part of the course!
419417
420-
#### 4.1 Blog list, step1
418+
#### 4.1 Blog List, step 1
421419
422-
Let's imagine a situation, where you receive an email that contains the following application body:
420+
Let's imagine a situation, where you receive an email that contains the following application body and instructions:
423421
424422
```js
425423
const express = require('express')
@@ -470,11 +468,11 @@ Turn the application into a functioning <i>npm</i> project. To keep your develop
470468
471469
Verify that it is possible to add blogs to the list with Postman or the VS Code REST client and that the application returns the added blogs at the correct endpoint.
472470
473-
#### 4.2 Blog list, step2
471+
#### 4.2 Blog List, step 2
474472
475473
Refactor the application into separate modules as shown earlier in this part of the course material.
476474
477-
**NB** refactor your application in baby steps and verify that the application works after every change you make. If you try to take a "shortcut" by refactoring many things at once, then [Murphy's law](https://en.wikipedia.org/wiki/Murphy%27s_law) will kick in and it is almost certain that something will break in your application. The "shortcut" will end up taking more time than moving forward slowly and systematically.
475+
**NB** refactor your application in baby steps and verify that it works after every change you make. If you try to take a "shortcut" by refactoring many things at once, then [Murphy's law](https://en.wikipedia.org/wiki/Murphy%27s_law) will kick in and it is almost certain that something will break in your application. The "shortcut" will end up taking more time than moving forward slowly and systematically.
478476
479477
One best practice is to commit your code every time it is in a stable state. This makes it easy to rollback to a situation where the application still works.
480478
@@ -614,21 +612,21 @@ First, we execute the code to be tested, meaning that we generate a reverse for
614612
615613
As expected, all of the tests pass:
616614
617-
![terminal output from npm test](../../images/4/1x.png)
615+
![terminal output from npm test with all tests passing](../../images/4/1x.png)
618616
619617
Jest expects by default that the names of test files contain <i>.test</i>. In this course, we will follow the convention of naming our tests files with the extension <i>.test.js</i>.
620618
621619
Jest has excellent error messages, let's break the test to demonstrate this:
622620
623621
```js
624-
test('palindrome of react', () => {
622+
test('reverse of react', () => {
625623
const result = reverse('react')
626624

627625
expect(result).toBe('tkaer')
628626
})
629627
```
630628
631-
Running the tests above results in the following error message:
629+
Running this test results in the following error message:
632630
633631
![terminal output shows failure from npm test](../../images/4/2x.png)
634632
@@ -702,7 +700,7 @@ test('of empty array is zero', () => {
702700
703701
Let's create a collection of helper functions that are meant to assist in dealing with the blog list. Create the functions into a file called <i>utils/list_helper.js</i>. Write your tests into an appropriately named test file under the <i>tests</i> directory.
704702
705-
#### 4.3: helper functions and unit tests, step1
703+
#### 4.3: Helper Functions and Unit Tests, step 1
706704
707705
First, define a _dummy_ function that receives an array of blog posts as a parameter and always returns the value 1. The contents of the <i>list_helper.js</i> file at this point should be the following:
708706
@@ -729,7 +727,7 @@ test('dummy returns one', () => {
729727
})
730728
```
731729
732-
#### 4.4: helper functions and unit tests, step2
730+
#### 4.4: Helper Functions and Unit Tests, step 2
733731
734732
Define a new _totalLikes_ function that receives a list of blog posts as a parameter. The function returns the total sum of <i>likes</i> in all of the blog posts.
735733
@@ -746,7 +744,7 @@ describe('total likes', () => {
746744
_id: '5a422aa71b54a676234d17f8',
747745
title: 'Go To Statement Considered Harmful',
748746
author: 'Edsger W. Dijkstra',
749-
url: 'http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html',
747+
url: 'https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.pdf',
750748
likes: 5,
751749
__v: 0
752750
}
@@ -771,7 +769,7 @@ Another way of running a single test (or describe block) is to specify the name
771769
npm test -- -t 'when list has only one blog, equals the likes of that'
772770
```
773771
774-
#### 4.5*: helper functions and unit tests, step3
772+
#### 4.5*: Helper Functions and Unit Tests, step 3
775773
776774
Define a new _favoriteBlog_ function that receives a list of blogs as a parameter. The function finds out which blog has the most likes. If there are many top favorites, it is enough to return one of them.
777775
@@ -789,7 +787,7 @@ The value returned by the function could be in the following format:
789787
790788
Write the tests for this exercise inside of a new <i>describe</i> block. Do the same for the remaining exercises as well.
791789
792-
#### 4.6*: helper functions and unit tests, step4
790+
#### 4.6*: Helper Functions and Unit Tests, step 4
793791
794792
This and the next exercise are a little bit more challenging. Finishing these two exercises is not required to advance in the course material, so it may be a good idea to return to these once you're done going through the material for this part in its entirety.
795793
@@ -806,7 +804,7 @@ Define a function called _mostBlogs_ that receives an array of blogs as a parame
806804
807805
If there are many top bloggers, then it is enough to return any one of them.
808806
809-
#### 4.7*: helper functions and unit tests, step5
807+
#### 4.7*: Helper Functions and Unit Tests, step 5
810808
811809
Define a function called _mostLikes_ that receives an array of blogs as its parameter. The function returns the author, whose blog posts have the largest amount of likes. The return value also contains the total number of likes that the author has received:
812810

src/content/4/es/part4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ lang: es
66

77
<div class="intro">
88

9-
En esta parte, continuaremos nuestro trabajo en el backend . Nuestro primer tema principal será escribir pruebas de unidad e integración para el backend. Una vez que hayamos cubierto las pruebas, analizaremos la implementación de la autenticación y autorización de usuario.
9+
En esta parte, continuaremos nuestro trabajo en el backend. Nuestro primer tema principal será escribir pruebas de unidad e integración para el backend. Una vez que hayamos cubierto las pruebas, analizaremos la implementación de la autenticación y autorización de usuario.
1010

1111
<i>Parte actualizada el 22 de enero de 2023</i>
1212
- <i>No hay cambios importantes</i>

0 commit comments

Comments
 (0)