Skip to content

Commit

Permalink
decouples server testing environment from dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
agosmou committed Nov 22, 2023
1 parent 917c6d4 commit d68fa66
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 60 deletions.
26 changes: 1 addition & 25 deletions .github/workflows/tdm-server-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: tdm-server-test
run-name: ${{ github.actor }} is running tests for the server
on:
push:
pull_request:
branches:
- develop
Expand All @@ -24,31 +25,6 @@ jobs:
run: npm install
working-directory: server

- name: Set up environment variables
run: |
echo "TEST_ENV=true" >> .env
echo "PORT=5002" >> .env
echo "NODE_OPTIONS=--trace-deprecation" >> .env
echo "JWT_SECRET_KEY=testingSecretKey" >> .env
echo "CLIENT_URL=http://localhost:3001" >> .env
echo "SERVER_URL=http://localhost:5002" >> .env
echo "SENDGRID_API_KEY=SG.testAPIkey" >> .env
echo "[email protected]" >> .env
echo "EMAIL_PUBLIC_COMMENT_LA_CITY=tdm+devpubliccommentplanning@test.org" >> .env
echo "[email protected]" >> .env
echo "APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus.livediagnostics.monitor.azure.com/" >> .env
echo "[email protected]" >> .env
echo "SECURITY_ADMIN_PASSWORD=Dogfood1!" >> .env
echo "[email protected]" >> .env
echo "ADMIN_PASSWORD=Dogfood1!" >> .env
echo "SQL_SERVER_NAME=localhost" >> .env
echo "SQL_SERVER_PORT=1434" >> .env
echo "SQL_DATABASE_NAME=tdmtestdb" >> .env
echo "SQL_USER_NAME=sa" >> .env
echo "SQL_PASSWORD=TestPassw0rd" >> .env
echo "SQL_ENCRYPT=false" >> .env
working-directory: server

- name: Run tests
run: npm test
working-directory: server
6 changes: 5 additions & 1 deletion push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ else
fi

# Run backend tests if the server directory has changes on the current branch and is different from origin/develop
if ! docker info > /dev/null 2>&1; then
echo "The server tests use docker, and it isn't running - please start docker and try again."
exit 1
fi
SERVER_FILE_COUNT=$(git diff --name-only origin/develop HEAD | grep -c ^server)
if [ "$SERVER_FILE_COUNT" -gt 0 ]
then
echo '************* BACKEND SERVER TESTS *************'
cd $PROJECT_ROOT_DIRECTORY/server
npm run lint:fix
npm run test || exit 1
npm test || exit 1
else
echo 'Skipping backend server tests because no relevant changes were found'
fi
Expand Down
34 changes: 0 additions & 34 deletions server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,3 @@ APPLICATIONINSIGHTS_CONNECTION_STRING=
# SQL_TRUST_SERVER_CERTIFICATE=
# EMAIL_SENDER=
# APPLICATIONINSIGHTS_CONNECTION_STRING=

###############################################################
## Testing (Comment out ALL the above variables) ##
###############################################################
# TEST_ENV=true

# PORT=5002
# NODE_OPTIONS=--trace-deprecation

# JWT_SECRET_KEY=testingSecretKey

# CLIENT_URL=http://localhost:3001
# SERVER_URL=http://localhost:5002

# SENDGRID_API_KEY=SG.testAPIkey
# [email protected]
# EMAIL_PUBLIC_COMMENT_LA_CITY=tdm+devpubliccommentplanning@test.org
# [email protected]

# APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus.livediagnostics.monitor.azure.com/

# # Server Test Accounts
# [email protected]
# SECURITY_ADMIN_PASSWORD=Dogfood1!
# [email protected]
# ADMIN_PASSWORD=Dogfood1!

# # testingcontainer Environment Variables
# SQL_SERVER_NAME=localhost
# SQL_SERVER_PORT=1434
# SQL_DATABASE_NAME=tdmtestdb
# SQL_USER_NAME=sa
# SQL_PASSWORD=TestPassw0rd
# SQL_ENCRYPT = false
1 change: 1 addition & 0 deletions server/_jest-setup_/global-setup/global-setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require("../utils/env-setup");
const { start } = require("../utils/mssql-container-setup");

module.exports = async () => {
Expand Down
31 changes: 31 additions & 0 deletions server/_jest-setup_/utils/env-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// env variables for testing
process.env.TEST_ENV = "true";

process.env.PORT = "5002";
process.env.NODE_OPTIONS = "--trace-deprecation";

process.env.JWT_SECRET_KEY = "testingSecretKey";

process.env.CLIENT_URL = "http://localhost:3001";
process.env.SERVER_URL = "http://localhost:5002";

process.env.SENDGRID_API_KEY = "SG.testAPIkey";
process.env.EMAIL_SENDER = "[email protected]";
process.env.EMAIL_PUBLIC_COMMENT_LA_CITY =
"[email protected]";
process.env.EMAIL_PUBLIC_COMMENT_WEB_TEAM = "[email protected]";

process.env.APPLICATIONINSIGHTS_CONNECTION_STRING =
"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus.livediagnostics.monitor.azure.com/";

process.env.SECURITY_ADMIN_EMAIL = "[email protected]";
process.env.SECURITY_ADMIN_PASSWORD = "Dogfood1!";
process.env.ADMIN_EMAIL = "[email protected]";
process.env.ADMIN_PASSWORD = "Dogfood1!";

process.env.SQL_SERVER_NAME = "localhost";
process.env.SQL_SERVER_PORT = "1434";
process.env.SQL_DATABASE_NAME = "tdmtestdb";
process.env.SQL_USER_NAME = "sa";
process.env.SQL_PASSWORD = "TestPassw0rd";
process.env.SQL_ENCRYPT = "false";

0 comments on commit d68fa66

Please sign in to comment.