Skip to content

Commit d5bfcc2

Browse files
committed
02/02: add exercise
1 parent ab7d551 commit d5bfcc2

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Mock databases
2+
3+
Problem: Your app under test **must not** communicate with the actual database.
4+
5+
Mocking database connections is database-specific. There are serveral kinds of databases you might be using:
6+
7+
- **File-based** (SQLite). Just point it to a local file;
8+
- **Server-based** (Postgres). You can run that DB instance locally in a Docker image and point your DB client to that locally running DB instance.
9+
- **In-memory databases** (Redis). Run database locally (that's usually easier and doesn't require Docker), connect to the locally running instance.
10+
11+
> Some database clients, like Supabase, might also expose an additional layer between your application and the database. You might decide to tap into that, too.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "exercises_02.test-setup_02.problem.mock-databases"
3+
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Mock databases
22

3-
**This exercise MUST preceed the Authentication exercise** because we are using Prisma to create test users for authentication purposes. Without this setup, it will try creating real users in the real database.
3+
Good job! 👏
44

5-
- **Set up mock databases _per test_.** `testInfo.testId` to the rescue! But then it's not environment variable-driven so be cautious.
5+
Take a quick rest and let's continue.
66

7-
1. Create `.env.test` and load it in Playwright.
8-
1. Set `DATABASE_URL` environment variable to point to `./prisma.data.db`.
9-
1. Show how that datbase after the test run (see the created user).
7+
## Related materials
8+
9+
- [PostgreSQL test setup with Prisma](https://www.prisma.io/docs/orm/prisma-client/testing/integration-testing)
10+
- [Redus test setup (Node.js)](https://redis.io/docs/latest/develop/clients/nodejs/)

exercises/02.test-setup/04.solution.api-mocking/prisma/data-new.db

Whitespace-only changes.

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
{
2323
"path": "exercises/02.test-setup/01.solution.custom-fixtures"
2424
},
25+
{
26+
"path": "exercises/02.test-setup/02.problem.mock-databases"
27+
},
2528
{
2629
"path": "exercises/02.test-setup/02.solution.mock-databases"
2730
},

0 commit comments

Comments
 (0)