Skip to content

README.md โ€‹

From Week 5 in-class: testing ยท original: si-679-f-26-week05-nyt-jessicadonoho/README.md ยท all files in this project

md
# Week 5 starter โ€” testing

A complete `/products` API. Nothing here is a TODO: the app works, and
`npm test` passes.

```bash
npm install
npm test
```

You should see passing tests and four marked `todo`. If you don't, say so
before we go any further.

End-to-end tests live in `src/__tests__/` and are named `*.e2e.test.ts`. Unit
tests sit beside the file they test, named `*.unit.test.ts`.

`src/mocks-and-spies.unit.test.ts` is the only unit test file you start with,
and it tests nothing about this app. It's a short tour of `vi.fn`,
`mockReturnValue` and `vi.spyOn` that we work through in class โ€” run it and
poke at it.

```bash
npm run test:e2e
npm run test:unit
```

There is no MongoDB to start this week. The tests run against
MongoMemoryServer, which they start and stop themselves.

```
src/
โ”œโ”€โ”€ db/            connection, and the products repository
โ”œโ”€โ”€ models/        types
โ”œโ”€โ”€ services/      application logic
โ”œโ”€โ”€ controllers/   requests and responses
โ”œโ”€โ”€ routes/        endpoints to controllers
โ”œโ”€โ”€ middleware/    error handling
โ”œโ”€โ”€ __tests__/     end-to-end tests, and the seed data they use
โ”œโ”€โ”€ mocks-and-spies.unit.test.ts
โ”œโ”€โ”€ app.ts
โ””โ”€โ”€ index.ts
```