Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 5-database/assignments/db-assignment-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Make sure your validation is fully working, and only valid users can access the

If only users who created a recipe can make changes, that means our Schema needs to be updated to start recording who created each recipe. Each Recipe will have a `createdBy` field that stored an ObjectId, which represents a user in the database. (This is called a "foreign key", where a key from another collection is stored as a field on our documents.)

1. Add a field to the User schema that looks like this:
1. Add a field to the Recipe schema that looks like this:
- `createdBy: mongoose.Schema.ObjectId` (it doesn't need more because we don't need to specify any other constraints on this field)
1. Change your Create endpoint to add the validated user's `_id` to the Recipe object before you save it.
- How do you know what the validated user's `_id` is? Try adding the user object to the `req` during the `tokenValidation` middelware. Remember that middlewares always have access to the request and response objects, and can modify them! Those modifications will then be received by the next function in the call stack.
Expand Down
2 changes: 1 addition & 1 deletion 6-react/assignments/react-assignment-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Your app will need to use `useEffect` twice:
- Fetch "Get Available Tags" once when the app loads
- Fetch "Get a Quote by Tags" whenever a new tag is selected

Use a `<select>` element with one `<option>` for each tag that you got from the API call. Listen for changes on the `<select>` element, and when a new tag is selected from the drop-down list, save that tag to state. This should automically cause a new random quote to be fetched.
Use a `<select>` element with one `<option>` for each tag that you got from the API call. Listen for changes on the `<select>` element, and when a new tag is selected from the drop-down list, save that tag to state. This should automatically cause a new random quote to be fetched.

> Tip: You will need three separate state variables here

Expand Down
2 changes: 1 addition & 1 deletion 7-test-and-deploy/assignments/testing-assignment-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

In this assignment you'll use `vitest` and `supertest` to write automated tests for an old assignment.

### My First Server Assignment
### Testing My First Server Assignment

We're revisiting [My First Server Assignment](../../4-server/assignments/server-assignment-2.md), in which you set up four simple endpoints that return strings.

Expand Down
27 changes: 27 additions & 0 deletions 7-test-and-deploy/assignments/testing-assignment-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Testing Assignment #2: Writing Automated Client Tests

In this assignment you'll use `vitest` and `react-testing-library` to write automated tests for an old assignment.

### Testing React To-Do App

Let's revisit your [React To-Do App](../../6-react/assignments/react-assignment-2.md).

You can either copy that assignment into a new folder, or just add the tests to your old assignment. Either way is fine.

To set up:

- Install `vitest`, `@testing-library/react`, and `jsdom` into the npm project.
- Add the [test configuration settings](../test-client/vite.config.js) to `vite.config.js`
- Create an`App.test.js` file.

In that file, write tests for the following behaviors:

1. Add a new item to the to-do list
- try firing a `change` event to update the value of the input field
- then fire whatever event submits the item to the list
- then look for an element with that text on the `screen`
1. Mark an item as complete, and check that the display changes to reflect that

### Extra challenges (optional)

Did you add anything else to your app, such as deleting items? Anything you wrote into your project, write a test for it!
24 changes: 24 additions & 0 deletions 7-test-and-deploy/test-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
8 changes: 8 additions & 0 deletions 7-test-and-deploy/test-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
38 changes: 38 additions & 0 deletions 7-test-and-deploy/test-client/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import js from '@eslint/js'
import globals from 'globals'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'

export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
settings: { react: { version: '18.3' } },
plugins: {
react,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
...reactHooks.configs.recommended.rules,
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]
13 changes: 13 additions & 0 deletions 7-test-and-deploy/test-client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pizza Parlor</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Loading