Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup test database for running tests for database #350

Merged
merged 6 commits into from
Mar 18, 2023
Merged
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: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ $ npm run db:studio

> **Note** `npm run build` needs to be executed the first time running the project. As it generates a `build/server.js` script that `npm run dev` depends on. Subsequent times, only `npm run dev` is needed to run the app in development mode.

> **Note** If you are running test scripts for the first time, change `DATABASE_URL` in `.env` to `DATABASE_URL="mysql://starchart:[email protected]:3306/starchart"` and run `npm run setup` to setup the test database. You can change this back afterward.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be done in this PR, but would it be worth to add a new setup:test script to do this instead?

Copy link
Contributor Author

@cychu42 cychu42 Mar 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps. If someone can write a script that has a command to parse the file to change the variable, runs npm run setup, then changes it back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think we can simply copy the setup command to setup:test, and override the value for DATABASE_URL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eakam1007 do you want to file an issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I might just create a PR for this today. Seems simple enough (unless I am missing something)


## SAML Accounts to use in Dev

Our IDP is configured with a few accounts that exist for testing, the usernames and passwords to use are as follows:
Expand Down
6 changes: 6 additions & 0 deletions config/01-databases.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- create test databases
CREATE DATABASE IF NOT EXISTS `starchart_test`;

-- create root user and grant rights
CREATE USER 'root'@'localhost' IDENTIFIED BY 'root_password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ services:
volumes:
# Persist data to ./mysql-data. Remove if you want to clear the db.
- ./mysql-data:/var/lib/mysql
# Locate SQL file to setup test database
- ./config/01-databases.sql:/docker-entrypoint-initdb.d/init/01-databases.sql
environment:
MYSQL_DATABASE: starchart
MYSQL_USER: starchart
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"setup": "run-s db:generate db:push db:seed",
"start": "cross-env NODE_ENV=production node ./build/server.js",
"start:e2e": "cross-env NODE_ENV=test node --require dotenv/config ./build/server.js",
"test": "cross-env SECRETS_OVERRIDE=1 NODE_OPTIONS=--require=dotenv/config vitest",
"test:e2e:dev": "cross-env PORT=8080 start-server-and-test dev http://localhost:8080 \"playwright test\"",
"test": "cross-env SECRETS_OVERRIDE=1 DATABASE_URL='mysql://root:[email protected]:3306/starchart_test' NODE_OPTIONS=--require=dotenv/config vitest",
"test:e2e:dev": "cross-env PORT=8080 DATABASE_URL='mysql://root:[email protected]:3306/starchart_test' start-server-and-test dev http://localhost:8080 \"playwright test\"",
"pretest:e2e:run": "cross-env NODE_ENV=test SECRETS_OVERRIDE=1 run-s build",
"test:e2e:run": "cross-env SECRETS_OVERRIDE=1 PORT=8080 start-server-and-test start:e2e http://localhost:8080 \"playwright test\"",
"test:e2e:run": "cross-env SECRETS_OVERRIDE=1 PORT=8080 DATABASE_URL='mysql://root:[email protected]:3306/starchart_test' start-server-and-test start:e2e http://localhost:8080 \"playwright test\"",
"typecheck": "tsc",
"validate": "run-p \"test -- --run\" lint typecheck test:e2e:run",
"prepare": "husky install"
Expand Down