Skip to content

Commit

Permalink
Setup test db (#132)
Browse files Browse the repository at this point in the history
* add test db in compose and gh actions

* add test db setup script

* move cleanDatabase to a helper file

* rm unused test

* adjustments to make it work

* remove header param from playwright and add NODE_ENV=test in gh test action

Also adjust DATABASE_URL in env example

* install browsers with deps

* fix seeds
  • Loading branch information
tonioriol authored Feb 12, 2024
1 parent 1411633 commit 65bdb9a
Show file tree
Hide file tree
Showing 11 changed files with 619 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DATABASE_URL=postgres://postgres:postgres@localhost:6532/taco
DATABASE_URL=postgres://postgres:postgres@localhost:6532/db
SECRET_KEY=
POSTMARK_API_KEY=
EMAIL_SENDER_SIGNATURE=
Expand Down
38 changes: 29 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ on:
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: db
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTMARK_API_KEY: SECRET
PUBLIC_SITE_NAME: TACO [TEST]
EMAIL_SENDER_SIGNATURE: [email protected]
PUBLIC_SENTRY_DSN: SECRET
PUBLIC_SENTRY_ENV: test
PUBLIC_SITE_URL: http://localhost:5173/
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/db
NODE_ENV: test

steps:
- name: Checkout repository
Expand All @@ -22,15 +46,11 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Install Playwright browsers
run: npx playwright install
- name: Install Playwright Browsers
run: npx playwright install --with-deps

- name: Run Prisma migrations
run: npx prisma migrate deploy

- name: Run tests
run: npm test
env:
POSTMARK_API_KEY: 'SECRET'
PUBLIC_SITE_NAME: 'TACO [TEST]'
EMAIL_SENDER_SIGNATURE: '[email protected]'
PUBLIC_SENTRY_DSN: 'SECRET'
PUBLIC_SENTRY_ENV: 'test'
PUBLIC_SITE_URL: 'http://localhost:5173/'
16 changes: 12 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
version: "3.8"
services:
db:
image: postgres:latest
image: postgres:15
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=taco
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: db
ports:
- "6532:5432"
volumes:
- db:/var/lib/postgresql/data
test-db:
image: postgres:15
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: db
ports:
- "3432:5432"

volumes:
db:
Loading

0 comments on commit 65bdb9a

Please sign in to comment.