Written HW
- What is Express in Node.js and why is it used?
- How does Mongoose help in using MongoDB with Node.js?
- Can you explain the role of Mongoose in managing relationships between data?
- What is a software design pattern? Give an example.
- Can you explain the MVC architecture in detail?
- What roles do Model, View, and Controller play in the MVC architecture?
- Define Latency and Throughput in the context of APIs.
- Why is it important to minimize latency and maximize throughput in APIs?
- What is Authentication in terms of web development?
- How does the authorization process start?
- What is
express.static
used for in Express? - Can you give an example of serving static files using
express.static
? - What is Jest and why is it used?
- How can Supertest be helpful when working with Jest?
- Can you describe how manual and automated tests are executed?
- What is the difference between unit testing, integration testing, and end-to-end testing?
- Can you provide examples of functional, regression, smoke, and performance tests?
- What is meant by positive testing and negative testing in a functional testing context?
- How does load testing assess the behavior of software?
- What aspects does usability testing assess in a software application?
- Why is security testing crucial in a software development life cycle?
- Can you explain what compatibility testing is?
- What is the aim of recovery testing and why is it important?
- What is User Acceptance Testing (UAT) and who typically performs it?
- Can you describe a scenario in which you would use each of the different testing types mentioned in the notes?
Practical HW
Homework Assignment: Building a Todo API and Testing with Jest, Supertest, and Artillery
Your task for this assignment is to develop a Todo API using Express and Mongoose. You will then be required to write unit tests for your API using Jest and Supertest, and finally perform load testing using Artillery.
Part 1: Building the Todo API
- Initialize a new Node.js project and install the necessary dependencies: Express, Mongoose, Morgan.
-
Design your
Todo
schema using Mongoose. Each todo item should have the following fields:title
: String, requireddescription
: Stringcompleted
: Boolean, default: falsecreated_at
: Date, default: Date.now
-
Implement the following API endpoints:
GET /todos
: Get all todo items.POST /todos
: Create a new todo item.GET /todos/:id
: Get a specific todo item.PUT /todos/:id
: Update a specific todo item.DELETE /todos/:id
: Delete a specific todo item.
- Make sure to handle any potential errors and return appropriate HTTP status codes and messages.
Part 2: Unit Testing with Jest, Supertest and Mongodb Memory Server
- Install MongoDB Memory Server Jest and Supertest.
- Write unit tests for each of your API endpoints. Your tests should cover both successful cases and edge cases such as invalid inputs or todo item not found.
- Run your tests and make sure all of them pass.
Part 3: Load Testing with Artillery
- Install Artillery.
-
Define a basic scenario for Artillery to simulate multiple users interacting with your API:
- Users should send a
POST /todos
request to create a new todo item. - Users should send a
GET /todos
request to fetch all todo items.
- Users should send a
- Run the load test and observe the results. If there are any performance issues, try to identify possible causes and make improvements to your API.
Deliverables:
- A GitHub repository containing your project code.
- A
README.md
file in the root of your repository, explaining the design of your Todo API, instructions for how to run and test your API, and a brief discussion of your load testing results.
Evaluation Criteria:
- Correctness and completeness of your Todo API.
- Quality and thoroughness of your unit tests.
- Appropriateness and execution of your load tests.
- Clarity and thoroughness of your
README.md
file.
Happy coding!
Theoretical HW
Recursion
Overview
This assignment introduces the wonders of recursion.
There are two components to this assignemnt:
- myGA module: Recursion // Look under algorithms if the link doesn't work
- Writing Recursive Functions
Note: The myGA module contains a link to an exercise in CodePen. The code in CodePen is the exact same as the code for the exercises. Try out the exercise in CodePen and see how far you can get with it. Leave off where you get stuck and i'll share the solution in class.
Learning Objectives
By the end of this lesson, you will be able to:
- Define recursion.
- Write the base case and recursive cases of a recursive function.
- Identify functions that use recursion and explain why it’s used.
Duration
1.5 hours total:
- 0.5 hour myGA
- 1 hour in on your own
Prerequisites
- Big O Notation
Additional Resources
- How recursion comes up in job interviews.
- More thoughts on recursion in job interviews.
- Sketching out a recursive function.
- Just for fun: The recursion subreddit.
Code
// Write code inside the functions
// You will have to figure out what parameters to include
// All functions must use recursion
function lengthOfString(str, len = 0) {
// If the length is 0 (base case), return len (0).
// if (str.length === 0) return len;
if (!str.length) return len;
// Remove the first letter of the string
let restOfString = str.substring(1);
// Call function again, with updated string and len
return lengthOfString(restOfString, ++len);
}
function sumOfArray() {
// This function returns the sum of all of the numbers in a given array.
}
function findMax() {
// This function returns the largest number in a given array.
}
function factorial() {
// This function returns the factorial of a given number.
}
function fibonacci() {
// This function returns the Nth number in the fibonacci sequence.
// https://en.wikipedia.org/wiki/Fibonacci_number
// For this function, the first two fibonacci numbers are 1 and 1
}
function coinFlips() {
// This function returns an array of all possible outcomes from flipping a coin N times.
// Input type: Integer
// For example, coinFlips(2) would return the following:
// ["HH", "HT", "TH", "TT"]
// H stands for Heads and T stands for tails
// Represent the two outcomes of each flip as "H" or "T"
}
function letterCombinations() {
// This function returns an array of all combinations of the given letters
// Input type: Array of single characters
// For example, letterCombinations(["a","b","c"]) would return the following:
// ["a","b","c","ab","ac","ba","bc","ca","cb","abc","acb","bac","bca","cab","cba"]
}
module.exports = {
lengthOfString,
sumOfArray,
findMax,
factorial,
fibonacci,
coinFlips,
letterCombinations,
};
HUNGRY FOR MORE
Unit Test this see this lesson - Bonus Testing Unit1 Apps Arthur Bernier Jr Former CTO, Technical Lead Ground Software at Astranis Space Technologies