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
Copy file name to clipboardExpand all lines: src/content/4/en/part4a.md
+18-20Lines changed: 18 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ module.exports = {
52
52
53
53
The logger has two functions, __info__ for printing normal log messages, and __error__ for all error messages.
54
54
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.
56
56
57
57
The handling of environment variables is extracted into a separate <i>utils/config.js</i> file:
58
58
@@ -178,13 +178,13 @@ All routes are now defined for the router object, similar to what I did before w
178
178
It's worth noting that the paths in the route handlers have shortened. In the previous version, we had:
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
323
323
324
324
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.
325
325
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.
327
327
328
328
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).
329
329
@@ -401,25 +401,23 @@ The nature of VS Code bleeding into how you write your code is probably not idea
401
401
402
402
</div>
403
403
404
-
405
-
406
404
<div class="tasks">
407
405
408
406
### Exercises 4.1.-4.2.
409
407
410
408
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.
411
409
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:
413
411
414
412
```bash
415
413
npm install mongoose@7.6.5
416
414
```
417
415
418
416
since the most recent Mongoose version does not support a library that we will be using in a later part of the course!
419
417
420
-
#### 4.1 Blog list, step1
418
+
#### 4.1 Blog List, step 1
421
419
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:
423
421
424
422
```js
425
423
constexpress=require('express')
@@ -470,11 +468,11 @@ Turn the application into a functioning <i>npm</i> project. To keep your develop
470
468
471
469
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.
472
470
473
-
#### 4.2 Blog list, step2
471
+
#### 4.2 Blog List, step 2
474
472
475
473
Refactor the application into separate modules as shown earlier in this part of the course material.
476
474
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.
478
476
479
477
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.
480
478
@@ -614,21 +612,21 @@ First, we execute the code to be tested, meaning that we generate a reverse for
614
612
615
613
As expected, all of the tests pass:
616
614
617
-

615
+

618
616
619
617
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>.
620
618
621
619
Jest has excellent error messages, let's break the test to demonstrate this:
622
620
623
621
```js
624
-
test('palindrome of react', () => {
622
+
test('reverse of react', () => {
625
623
constresult=reverse('react')
626
624
627
625
expect(result).toBe('tkaer')
628
626
})
629
627
```
630
628
631
-
Running the tests above results in the following error message:
629
+
Running this test results in the following error message:
632
630
633
631

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.
704
702
705
-
#### 4.3: helper functions and unit tests, step1
703
+
#### 4.3: Helper Functions and Unit Tests, step 1
706
704
707
705
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:
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.
@@ -771,7 +769,7 @@ Another way of running a single test (or describe block) is to specify the name
771
769
npm test ---t 'when list has only one blog, equals the likes of that'
772
770
```
773
771
774
-
#### 4.5*: helper functions and unit tests, step3
772
+
#### 4.5*: Helper Functions and Unit Tests, step 3
775
773
776
774
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.
777
775
@@ -789,7 +787,7 @@ The value returned by the function could be in the following format:
789
787
790
788
Write the tests for this exercise inside of a new <i>describe</i> block. Do the same for the remaining exercises as well.
791
789
792
-
#### 4.6*: helper functions and unit tests, step4
790
+
#### 4.6*: Helper Functions and Unit Tests, step 4
793
791
794
792
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.
795
793
@@ -806,7 +804,7 @@ Define a function called _mostBlogs_ that receives an array of blogs as a parame
806
804
807
805
If there are many top bloggers, then it is enough to return any one of them.
808
806
809
-
#### 4.7*: helper functions and unit tests, step5
807
+
#### 4.7*: Helper Functions and Unit Tests, step 5
810
808
811
809
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:
Copy file name to clipboardExpand all lines: src/content/4/es/part4.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ lang: es
6
6
7
7
<divclass="intro">
8
8
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.
0 commit comments