From 5b66592eb7671a76532bdf9693055ce51457c0d0 Mon Sep 17 00:00:00 2001
From: Jxkz <107039597+jxkz3@users.noreply.github.com>
Date: Mon, 15 Dec 2025 14:20:21 +0530
Subject: [PATCH 1/2] fix(docs): correct broken markdown links and filename
typo
---
README.md | 14 +-
...ment-process.md => development-process.md} | 124 +++++++++---------
2 files changed, 69 insertions(+), 69 deletions(-)
rename introduction-to-nodejs/Putting-it-all-together/{developement-process.md => development-process.md} (78%)
diff --git a/README.md b/README.md
index a3e88b8..28b89fa 100644
--- a/README.md
+++ b/README.md
@@ -43,11 +43,11 @@ More details regarding the licensing history of this content can be found in [th
### Putting it all together
-7. [Development environment](./introduction-to-nodejs/Putting-it-all-together/developement-process.md)
+7. [Development environment](./introduction-to-nodejs/Putting-it-all-together/development-process.md)
### Milestone
-9. [Milestone](./introduction-to-nodejs/milestone/README.md)
+8. [Milestone](./introduction-to-nodejs/milestone/README.md)
## L2. Working with NPM
@@ -57,7 +57,7 @@ More details regarding the licensing history of this content can be found in [th
2. [What is NPM?](./working-with-npm/about-npm-and-uses/README.md)
3. [What is package.json](./working-with-npm/package-json-in-npm/README.md)
4. [What are NPM scripts](./working-with-npm/npm-scripts/README.md)
-5. [Explore built in fs module](./working-with-npm/nodejs-fs-module/README.md)
+5. [Explore built-in fs module](./working-with-npm/nodejs-fs-module/README.md)
6. [Explore streams](./working-with-npm/nodejs-stream-module/README.md)
7. [Working with npm install](./working-with-npm/npm-install-packages/README.md)
8. [Accepting command line arguments](./working-with-npm/accepting-cli-commands/README.md)
@@ -146,18 +146,18 @@ More details regarding the licensing history of this content can be found in [th
### Sequelize associations
1. [Introduction](./user-authentication/introduction/README.md)
-2. [Create the `users` table with a sequelize migration]('./../user-authentication/create-users-table-with-sequelize-migration/README.md)
-3. [Associations: adding owners to todo]('./user-authentication/../../user-authentication/associations-adding-owners-to-todo/README.md)
+2. [Create the `users` table with a sequelize migration](./../user-authentication/create-users-table-with-sequelize-migration/README.md)
+3. [Associations: adding owners to todo](./user-authentication/../../user-authentication/associations-adding-owners-to-todo/README.md)
### Signing up new users
4. [Creating a user sign-up page](./user-authentication/create-user-signup-page/README.md)
-5. [Add user authentication using passport.js]('./../user-authentication/authentication-using-passport/README.md)
+5. [Add user authentication using passport.js](./../user-authentication/authentication-using-passport/README.md)
6. [Storing passwords with bcrypt](./user-authentication/storing-password-using-bcrypt/README.md)
### Cookies, sessions, and the user authentication workflow
-7. [Create a simple sign-in page which verifies the user's password]('./../user-authentication/signin-with-password-verification/README.md)
+7. [Create a simple sign-in page which verifies the user's password](./../user-authentication/signin-with-password-verification/README.md)
8. [What exactly is a cookie and why should you care?](./user-authentication/why-cookies/README.md)
9. [Implement sign-out by resetting the user session](./user-authentication/sign-out/README.md)
10. [A logged-in user should see and modify only their own to-dos and nobody else's](./user-authentication/show-todos-for-logged-in-user/README.md)
diff --git a/introduction-to-nodejs/Putting-it-all-together/developement-process.md b/introduction-to-nodejs/Putting-it-all-together/development-process.md
similarity index 78%
rename from introduction-to-nodejs/Putting-it-all-together/developement-process.md
rename to introduction-to-nodejs/Putting-it-all-together/development-process.md
index dab6ded..6db526d 100644
--- a/introduction-to-nodejs/Putting-it-all-together/developement-process.md
+++ b/introduction-to-nodejs/Putting-it-all-together/development-process.md
@@ -35,42 +35,42 @@ Hello, everyone! Over our last few lessons, we've focussed setting up our develo
-
-
+
+
- Todo List App
+ Todo List App
-
-
+ />
+
-
-
+
+
Todo List App
-
-
-
+
+
+
-
+
-
-
+
+
```
@@ -81,24 +81,24 @@ Hello, everyone! Over our last few lessons, we've focussed setting up our develo
```javascript
let todos = [];
- function addTodo() {
- const input = document.getElementById('todo-input');
- if (input.value.trim() !== '') {
- todos.push(input.value.trim());
- input.value = '';
- renderTodos();
- }
- }
-
- function renderTodos() {
- const list = document.getElementById('todo-list');
- list.innerHTML = '';
- todos.forEach((todo, index) => {
- const listItem = document.createElement('li');
- listItem.textContent = todo;
- list.appendChild(listItem);
- });
- }
+ function addTodo() {
+ const input = document.getElementById("todo-input");
+ if (input.value.trim() !== "") {
+ todos.push(input.value.trim());
+ input.value = "";
+ renderTodos();
+ }
+ }
+
+ function renderTodos() {
+ const list = document.getElementById("todo-list");
+ list.innerHTML = "";
+ todos.forEach((todo, index) => {
+ const listItem = document.createElement("li");
+ listItem.textContent = todo;
+ list.appendChild(listItem);
+ });
+ }
```
**Version Control with Git**
@@ -131,19 +131,19 @@ Refer to this [target](https://www.pupilfirst.school/targets/18691) for Installi
todos = []; // Missing 'let' keyword
function addTodo() {
- const input = document.getElementById('todo-input');
- if (input.value.trim() !== '') {
+ const input = document.getElementById("todo-input");
+ if (input.value.trim() !== "") {
todos.push(input.value.trim());
- input.value = '';
+ input.value = "";
renderTodos();
}
}
function renderTodos() {
- const list = document.getElementById('todo-list');
- list.innerHTML = '';
+ const list = document.getElementById("todo-list");
+ list.innerHTML = "";
todos.forEach((todo, index) => {
- const listItem = document.createElement('li');
+ const listItem = document.createElement("li");
listItem.textContent = todo;
list.appendChild(listItem);
});
@@ -158,19 +158,19 @@ Refer to this [target](https://www.pupilfirst.school/targets/18691) for Installi
let todos = [];
function addTodo() {
- const input = document.getElementById('todo-input');
- if (input.value.trim() !== '') {
+ const input = document.getElementById("todo-input");
+ if (input.value.trim() !== "") {
todos.push(input.value.trim());
- input.value = '';
+ input.value = "";
renderTodos();
}
}
function renderTodos() {
- const list = document.getElementById('todo-list');
- list.innerHTML = '';
+ const list = document.getElementById("todo-list");
+ list.innerHTML = "";
todos.forEach((todo, index) => {
- const listItem = document.createElement('li');
+ const listItem = document.createElement("li");
listItem.textContent = todo;
list.appendChild(listItem);
});
@@ -178,7 +178,7 @@ Refer to this [target](https://www.pupilfirst.school/targets/18691) for Installi
```
By adhering to ESLint's suggestions and declaring `todos` properly with `let`, our code becomes more reliable and less prone to errors.
-
+
Refer to this [target](https://www.pupilfirst.school/targets/18909) for detailed instructions on Code quality using ESLint.
- With our code refined by Prettier and ESLint, it's time for the commit. Run `git add .` and then `git commit -m 'Refine code with Prettier and ESLint.'` Lastly, we push our project to GitHub with `git push origin main`, showcasing our clean, well-maintained project to the world.
@@ -193,17 +193,17 @@ Building upon our existing JavaScript code, let's enhance our Todo application b
```javascript
function renderTodos() {
- const list = document.getElementById('todo-list');
- list.innerHTML = '';
+ const list = document.getElementById("todo-list");
+ list.innerHTML = "";
todos.forEach((todo, index) => {
- const listItem = document.createElement('li');
+ const listItem = document.createElement("li");
listItem.textContent = todo;
// Create a remove button for each todo
- const removeBtn = document.createElement('button');
- removeBtn.textContent = 'Delete';
- removeBtn.style.marginLeft = '10px';
- removeBtn.style.color = 'red';
+ const removeBtn = document.createElement("button");
+ removeBtn.textContent = "Delete";
+ removeBtn.style.marginLeft = "10px";
+ removeBtn.style.color = "red";
removeBtn.onclick = function () {
removeTodo(index);
}; // Attach click handler to remove todo
From 2c1c72e52bbd084c4e2e15c572db98b81ffd28bc Mon Sep 17 00:00:00 2001
From: Jxkz <107039597+jxkz3@users.noreply.github.com>
Date: Mon, 15 Dec 2025 14:58:47 +0530
Subject: [PATCH 2/2] fix: correct typos in route comments and function names
---
.../create-and-update-todo/README.md | 203 ++++++++++--------
.../milestone-test/README.md | 9 +-
.../routes-in-express/README.md | 72 ++++---
testing/tdd/README.md | 2 +-
testing/why-need-testing/README.md | 18 +-
5 files changed, 171 insertions(+), 133 deletions(-)
diff --git a/backend-dev-with-express/create-and-update-todo/README.md b/backend-dev-with-express/create-and-update-todo/README.md
index 59770ef..d6c5c6b 100644
--- a/backend-dev-with-express/create-and-update-todo/README.md
+++ b/backend-dev-with-express/create-and-update-todo/README.md
@@ -1,158 +1,181 @@
# Text
-
+
Previously, you've learned, how to define routes in an **Express.JS** application. There we've also defined routes to create a TO-DO, update a TODO and to get details of a TO-DO. But the real implementation inside the callback function is not complete yet. And in this lesson we are about to do that. So, let's get started.
-
+
# Video Script
-Hey there, in this video we will write some logic inside our route definitions, to *create* and *update* a TO-DO. We will also use Sequelize to persist our data in PostgreSQL database. And to test our routes, we will respond back in JSON format, as our user interface is not ready yet.
-
+
+Hey there, in this video we will write some logic inside our route definitions, to _create_ and _update_ a TO-DO. We will also use Sequelize to persist our data in PostgreSQL database. And to test our routes, we will respond back in JSON format, as our user interface is not ready yet.
+
### Step 1: Define the TO-DO model using Sequelize
-Before we can write logic inside our TO-DO endpoints, we have to define the **TODO** *model* using Sequelize.
-
+
+Before we can write logic inside our TO-DO endpoints, we have to define the **TODO** _model_ using Sequelize.
+
To generate the **Todo** model, we will use the `db:generate` command of `sequelize-cli`. In this command, we have to pass the attributes of **Todo** along with their types. A **Todo** will have a `title` with type `string`, then `dueDate` of type `date` and a `complete` of type `boolean`.
-
+
```sh
npx sequelize-cli model:generate --name Todo --attributes title:string,dueDate:dateonly,completed:boolean
```
-
+
The above command will create a `todo.js` file in `model` folder and migration file in the `migrations` folder.
-
+
> Action: Show both files in VS Code
-
+
### Step 2: Create database table
+
The migration file has all the codes that we need to create the `Todos` table in the database. To simply run the migration file, we will execute the following command in the terminal:
-
+
```sh
npx sequelize-cli db:migrate
```
+
This will create the `Todos` table in the database.
+
> Action: Show the Todos table using PGAdmin.
-
-### Step 3: Complete the `create Todo` endpoint implementation
+
+### Step 3: Completed the `create Todo` endpoint implementation
+
In order to perform any operation for Todo, first we have to import the model in our primary `index.js` file.
+
```js
const { Todo } = require("./models");
```
-
-Next, in the **create TODO** endpoint, we have to read the request body to look for the To-Do *title* and *dueDate*.
-
+
+Next, in the **create TODO** endpoint, we have to read the request body to look for the To-Do _title_ and _dueDate_.
+
Here we need the `body-parser` module to accept and parse JSON request body. Nowadays, the `body-parser` package comes by default with Express and we just have to `require` it:
+
```js
-const bodyParser = require('body-parser');
+const bodyParser = require("body-parser");
app.use(bodyParser.json());
```
-
-Next, inside the `create` TO-DO route, we will use the `.create()` method from **Sequelize**, to insert a *todo* into the database, based on the request body:
+
+Next, inside the `create` TO-DO route, we will use the `.create()` method from **Sequelize**, to insert a _todo_ into the database, based on the request body:
+
```js
-app.post('/todos', async function (request, response) {
- console.log('Creating new Todo: ', request.body)
- try {
- const todo = await Todo.create({ title: request.body.title, dueDate: request.body.dueDate, completed: false })
- return response.json(todo);
- } catch (error) {
- console.log(error)
- return response.status(422).json(error);
- }
-})
-```
-
+app.post("/todos", async function (request, response) {
+ console.log("Creating new Todo: ", request.body);
+ try {
+ const todo = await Todo.create({
+ title: request.body.title,
+ dueDate: request.body.dueDate,
+ completed: false,
+ });
+ return response.json(todo);
+ } catch (error) {
+ console.log(error);
+ return response.status(422).json(error);
+ }
+});
+```
+
To test it out, first we have to make sure that the server is running:
+
```
node index.js
```
Then we will send a simple `curl` request from our terminal:
-````
+
+```
curl -d '{"title":"Go the gym","dueDate":"2022-07-02"}' -H "Content-Type: application/json" -X POST http://localhost:3000/todos
-````
-
+```
+
This `curl` call will create a new **todo** entry in our database, and will return the new database object to us.
-
-We can further refractor the code by defining a `addTodo` class method in the `Todo` model, and moving the `Todo.create` method there itself.
+
+We can further refractor the code by defining a `addTodo` class method in the `Todo` model, and moving the `Todo.create` method there itself.
+
```js
- class Todo extends Model {
- /**
- * Helper method for defining associations.
- * This method is not a part of Sequelize lifecycle.
- * The `models/index` file will call this method automatically.
- */
- static associate(models) {
- // define association here
- }
-
- static addTodo({ title, dueDate }) {
- return this.create({ title: title, dueDate: dueDate, completed: false });
- }
+class Todo extends Model {
+ /**
+ * Helper method for defining associations.
+ * This method is not a part of Sequelize lifecycle.
+ * The `models/index` file will call this method automatically.
+ */
+ static associate(models) {
+ // define association here
}
+
+ static addTodo({ title, dueDate }) {
+ return this.create({ title: title, dueDate: dueDate, completed: false });
+ }
+}
```
+
Here, inside the `addTodo` method, `this` refers to the class Todo itself.
Now we can call this class method `addTodo` from our route definition:
+
```js
-app.post('/todos', async function (request, response) {
- console.log('Creating new Todo: ', request.body)
+app.post("/todos", async function (request, response) {
+ console.log("Creating new Todo: ", request.body);
try {
const todo = await Todo.addTodo(request.body);
- return response.json(todo);
+ return response.json(todo);
} catch (error) {
- console.log(error)
- return response.status(422).json(error);
+ console.log(error);
+ return response.status(422).json(error);
}
-})
+});
```
### Step 4: Complete the `markAsCompleted Todo` endpoint implementation
-To update the TO-DO that we've just created, we will use the `.update()` method of Sequelize.
+
+To update the TO-DO that we've just created, we will use the `.update()` method of Sequelize.
But first, we have to find out the Todo that we want to update. In that case, we will use the `findByPk` method, where we have to pass the Todo ID that we are getting as part of the query parameter.
+
```js
-app.put('/todos/:id/markAsCompleted', async function (request, response) {
- console.log('We have to update a Todo with ID: ', request.params.id)
- const todo = await Todo.findByPk(request.params.id)
-})
+app.put("/todos/:id/markAsCompleted", async function (request, response) {
+ console.log("We have to update a Todo with ID: ", request.params.id);
+ const todo = await Todo.findByPk(request.params.id);
+});
```
Next, we will define an instance method in Todo model named `markAsCompleted`, where we will actually update the Todo using `.update()`
+
```js
- class Todo extends Model {
- /**
- * Helper method for defining associations.
- * This method is not a part of Sequelize lifecycle.
- * The `models/index` file will call this method automatically.
- */
- static associate(models) {
- // define association here
- }
-
- static addTodo({ title, dueDate }) {
- return this.create({ title, dueDate, completed: false });
- }
-
- markAsCompleted() {
- return this.update({ completed: true })
- }
+class Todo extends Model {
+ /**
+ * Helper method for defining associations.
+ * This method is not a part of Sequelize lifecycle.
+ * The `models/index` file will call this method automatically.
+ */
+ static associate(models) {
+ // define association here
+ }
+
+ static addTodo({ title, dueDate }) {
+ return this.create({ title, dueDate, completed: false });
}
+
+ markAsCompleted() {
+ return this.update({ completed: true });
+ }
+}
```
+
Here, inside the `markAsCompleted` method, `this` refers to an instance of class Todo. Now we can call this method from our route definition.
+
```js
-app.put('/todos/:id/markAsCompleted', async function (request, response) {
- console.log('We have to update a Todo with ID: ', request.params.id)
- const todo = await Todo.findByPk(request.params.id)
+app.put("/todos/:id/markAsCompleted", async function (request, response) {
+ console.log("We have to update a Todo with ID: ", request.params.id);
+ const todo = await Todo.findByPk(request.params.id);
try {
- const updatedTodo = await todo.markAsCompleted()
+ const updatedTodo = await todo.markAsCompleted();
return response.json(updatedTodo);
} catch (error) {
- console.log(error)
- return response.status(422).json(error);
+ console.log(error);
+ return response.status(422).json(error);
}
-})
+});
```
-
+
Let's test it out using `curl`:
-````
+
+```
curl -d '' -H "Content-Type: application/json" -X PUT http://localhost:3000/todos/1/markAsCompleted
-````
+```
-Great! This request updates the to-do with *ID 1* and sets `completed` as `true`.
-
-That's all for this video, see you in the next one.
+Great! This request updates the to-do with _ID 1_ and sets `completed` as `true`.
+That's all for this video, see you in the next one.
diff --git a/backend-dev-with-express/milestone-test/README.md b/backend-dev-with-express/milestone-test/README.md
index 3953f50..fefb1d2 100644
--- a/backend-dev-with-express/milestone-test/README.md
+++ b/backend-dev-with-express/milestone-test/README.md
@@ -3,7 +3,8 @@
## Milestone Evaluation Specs
1. Validate the `GET /todos` endpoint whether it's returning list of all todos in JSON format or not.
-The sample output will be something like this:
+ The sample output will be something like this:
+
```json
[
{
@@ -22,8 +23,8 @@ The sample output will be something like this:
"createdAt": "2022-08-01T09:50:55.759Z",
"updatedAt": "2022-08-01T09:50:55.759Z"
}
-]
+]
```
-2. Validate the `DELETE /todos/:id` endpoint whether it's deleting a specific To-Do by it's ID or not. After successful deletion, the endpoint should return `true` or `false`. To cross check, you can call the `GET /todos/:id` API with the To-Do ID that we've just deleted. If deletion functionality implemented properly, this (`GET /todos/:id`) endpint should return `404`
-3. Validate the Jest file written for testing the `DELETE /todos/:id` endpoint.
\ No newline at end of file
+2. Validate the `DELETE /todos/:id` endpoint whether it's deleting a specific To-Do by it's ID or not. After successful deletion, the endpoint should return `true` or `false`. To cross check, you can call the `GET /todos/:id` API with the To-Do ID that we've just deleted. If deletion functionality implemented properly, this (`GET /todos/:id`) endpoint should return `404`
+3. Validate the Jest file written for testing the `DELETE /todos/:id` endpoint.
diff --git a/backend-dev-with-express/routes-in-express/README.md b/backend-dev-with-express/routes-in-express/README.md
index db41a23..25e391a 100644
--- a/backend-dev-with-express/routes-in-express/README.md
+++ b/backend-dev-with-express/routes-in-express/README.md
@@ -1,81 +1,95 @@
# Text
+
Routing is an important part of a Web framework. It defines how the application should handle all the incoming HTTP requests. In this lesson we are about to explore, how to define routes in an express.js application.
We will work on the same express application that we've created in the **Hello world with Express.js!** lesson.
### Fundamentals of Routing
+
**Routing** refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, PUT, DELETE etc.).
The structure of route definition is:
-````
+
+```
app.METHOD(PATH, HANDLER)
-or
+or
app.METHOD(path, callback [, callback ...])
-````
+```
An example route:
+
```js
app.get("/", function (request, response) {
- response.send('Hello World')
-})
+ response.send("Hello World");
+});
```
- Here:
- - `app` is the instance of `express`
- - `METHOD` is nothing but a **HTTP verb**, it could be GET, POST, PUT, PATCH, DELETE etc. While defining a route, we have to keep it in lowercase, like: `app.get()`, `app.post()`, `app.delete()`, and so on.
- - `PATH` is a path on the server. This is very important as it determines the actual endpoint where clients would send requests to. For example, let's say we are defining route for our Todo application, and the first route we got to define, is to get list of all Todos. So, our path would be, `/todos` and method would be `GET`.
- - `HANDLER` is the callback function which executed when the `PATH` and the `METHOD` are matched. This callback function that takes a `request` object and a `response` object. The *request* object contains information about the request that came from the client, for example: request headers, query parameters, request body, etc. The *response* object contains information that we want to send as a response back to the client. In the above example, the `response.send('hello world');` function sends a response with content in the body of the response (the plain text `hello world`).
+
+Here:
+
+- `app` is the instance of `express`
+- `METHOD` is nothing but a **HTTP verb**, it could be GET, POST, PUT, PATCH, DELETE etc. While defining a route, we have to keep it in lowercase, like: `app.get()`, `app.post()`, `app.delete()`, and so on.
+- `PATH` is a path on the server. This is very important as it determines the actual endpoint where clients would send requests to. For example, let's say we are defining route for our Todo application, and the first route we got to define, is to get list of all Todos. So, our path would be, `/todos` and method would be `GET`.
+- `HANDLER` is the callback function which executed when the `PATH` and the `METHOD` are matched. This callback function that takes a `request` object and a `response` object. The _request_ object contains information about the request that came from the client, for example: request headers, query parameters, request body, etc. The _response_ object contains information that we want to send as a response back to the client. In the above example, the `response.send('hello world');` function sends a response with content in the body of the response (the plain text `hello world`).
### Let's define routes for our Todo app
+
1. Endpoint to get list of all Todos:
+
```js
-app.get('/todos', function (request, response) {
- console.log('Processing list of all Todos ...')
- // First, we have to query our PostgerSQL database using Sequelize to get list of all Todos.
+app.get("/todos", function (request, response) {
+ console.log("Processing list of all Todos ...");
+ // First, we have to query our PostgreSQL database using Sequelize to get list of all Todos.
// Then, we have to respond with all Todos, like:
// response.send(todos)
-})
+});
```
2. Route to get details of a specific Todo by it's ID:
+
```js
-app.get('/todos/:id', function (request, response) {
- console.log('Looking for Todo with ID: ', request.params.id)
+app.get("/todos/:id", function (request, response) {
+ console.log("Looking for Todo with ID: ", request.params.id);
// First, we have to query our database to get details of a Todo with a specific ID.
// Then, we have to respond back:
// response.send(todo)
-})
+});
```
-In this route definition, we have to send the Todo ID as a part of the endpoint URL. So the complete endpoint could look something like this: `GET http://mytodoapp.com/todos/123`, here **123** is the Todo ID.
+
+In this route definition, we have to send the Todo ID as a part of the endpoint URL. So the complete endpoint could look something like this: `GET http://mytodoapp.com/todos/123`, here **123** is the Todo ID.
In this route definition, the ID is coming as parameter, which can be accessed inside the callback function with: `request.params.id`.
3. Route for creating a new Todo:
+
```js
-app.post('/todos', function (request, response) {
- console.log('Creating new Todo: ', request.body)
+app.post("/todos", function (request, response) {
+ console.log("Creating new Todo: ", request.body);
// First, we have to query our database to create the new Todo with all relevant attributes coming inside the request body.
// Then, we have to respond back with the new Todo instance:
// response.send(todo)
-})
+});
```
-In this route definition, we've used the `POST` HTTP method, as we are creating a new entry in the database. Another important point to observe, the `PATH` value of this endpoint matches with the route to *get list of all Todos*, but notice the HTTP method is different there. So, whenever you are defining any routes, remember to keep the combination of `HTTP METHOD + PATH` unique, throughout the application.
+
+In this route definition, we've used the `POST` HTTP method, as we are creating a new entry in the database. Another important point to observe, the `PATH` value of this endpoint matches with the route to _get list of all Todos_, but notice the HTTP method is different there. So, whenever you are defining any routes, remember to keep the combination of `HTTP METHOD + PATH` unique, throughout the application.
4. Route to update a specific Todo by it's ID, to mark it as `completed`:
+
```js
-app.put('/todos/:id/markAsCompleted', function (request, response) {
- console.log('We have to update a Todo with ID: ', request.params.id)
+app.put("/todos/:id/markAsCompleted", function (request, response) {
+ console.log("We have to update a Todo with ID: ", request.params.id);
// First, we have to query our database to update details of a Todo with a specific ID.
// Then, we have to respond back with the updated Todo
-})
+});
```
5. Route to delete a specific Todo by it's ID:
+
```js
-app.delete('/todos/:id', function (request, response) {
- console.log('We have to delete a Todo with ID: ', request.params.id)
+app.delete("/todos/:id", function (request, response) {
+ console.log("We have to delete a Todo with ID: ", request.params.id);
// First, we have to query our database to delete a Todo by ID.
- // Then, we have to respond back with some simplete message like "To-Do deleted successfully":
+ // Then, we have to respond back with some simple message like "To-Do deleted successfully":
// response.send("Todo deleted successfully")
-})
+});
```
So, in this lesson, we've learned to define routes in a Node.js application. See you in the next one.
diff --git a/testing/tdd/README.md b/testing/tdd/README.md
index e687234..f7ec166 100644
--- a/testing/tdd/README.md
+++ b/testing/tdd/README.md
@@ -4,7 +4,7 @@
Test-driven development reverses traditional development and testing. Usually, we write code first, then write tests to verify if the feature is working properly or not. But with TDD, you will write a test first, then add code until the test passes.
-### TDD work flow
+### TDD Workflow
TDD is a cyclic process from Red - Green - Blue.
diff --git a/testing/why-need-testing/README.md b/testing/why-need-testing/README.md
index 8dc78a9..b59996b 100644
--- a/testing/why-need-testing/README.md
+++ b/testing/why-need-testing/README.md
@@ -17,7 +17,7 @@ There are various types of testing. But, we will mainly look into:
### Unit testing
-Unit testing is a software development process in which the minor testable parts of an application, called units, are individually and independently scrutinized for proper operation. By writing unit tests, we ensure that different system parts perform their function correctly. This can act as a building block for the validation of the entire system. Let's see how we can write a unit test for the sample todo application. We can write a test to validate if the function `toggleTodoCompleteStatus` works as intended. We can use `console.assert` to assert the conditions.
+Unit testing is a software development process in which the minor testable parts of an application, called units, are individually and independently scrutinized for proper operation. By writing unit tests, we ensure that different system parts perform their function correctly. This can act as a building block for the validation of the entire system. Let's see how we can write a unit test for the sample todo application. We can write a test to validate if the function `toggleTodoCompletedStatus` works as intended. We can use `console.assert` to assert the conditions.
We have a wrong implementation here, which doesn't change the completion status.
@@ -30,22 +30,23 @@ let toggleTodoCompletedStatus = (todoItem) => {
let testToggleCompletion = () => {
let item = {
- title: 'Buy Milk',
+ title: "Buy Milk",
completed: false,
- }
+ };
item = toggleTodoCompletedStatus(item);
- console.assert(item.completed === true, 'Todo item should be completed');
-
-}
+ console.assert(item.completed === true, "Todo item should be completed");
+};
-testToggleCompletion()
+testToggleCompletion();
```
+
If we run the following program, we will get an `Assertion failed: Todo item should be completed` error message.
```sh
node assert.js
```
+
If we replace the `toggleTodoCompletedStatus` with the correct implementation, the error goes away.
```js
@@ -54,8 +55,8 @@ let toggleTodoCompletedStatus = (todoItem) => {
return todoItem;
};
```
-Here, we only tested a single function, which is how unit tests can help test each component in an extensive system.
+Here, we only tested a single function, which is how unit tests can help test each component in an extensive system.
### Integration test
@@ -63,5 +64,4 @@ Integration tests ensure that different modules or units in the system work toge
An example for an integration test will be to check if the todo `title` text field has been cleared on adding a new entry. Another example will be to verify if the user gets redirected to the homepage after authentication etc.
-
We write the tests using a `Test Framework` and these tests are run using a special tool called `Test Runner`.