From d68fa66d386ec6d2cd1184029a2dcd086ba2df57 Mon Sep 17 00:00:00 2001 From: Alejandro Gomez <73868258+agosmou@users.noreply.github.com> Date: Tue, 21 Nov 2023 18:37:20 -0800 Subject: [PATCH] decouples server testing environment from dev environment --- .github/workflows/tdm-server-tests.yml | 26 +------------- push.sh | 6 +++- server/.env.example | 34 ------------------- .../_jest-setup_/global-setup/global-setup.js | 1 + server/_jest-setup_/utils/env-setup.js | 31 +++++++++++++++++ 5 files changed, 38 insertions(+), 60 deletions(-) create mode 100644 server/_jest-setup_/utils/env-setup.js diff --git a/.github/workflows/tdm-server-tests.yml b/.github/workflows/tdm-server-tests.yml index 01943a5f..1c6ccf75 100644 --- a/.github/workflows/tdm-server-tests.yml +++ b/.github/workflows/tdm-server-tests.yml @@ -1,6 +1,7 @@ name: tdm-server-test run-name: ${{ github.actor }} is running tests for the server on: + push: pull_request: branches: - develop @@ -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_SENDER=tdm+sendgrid@test.org" >> .env - echo "EMAIL_PUBLIC_COMMENT_LA_CITY=tdm+devpubliccommentplanning@test.org" >> .env - echo "EMAIL_PUBLIC_COMMENT_WEB_TEAM=tdm+devpubliccomment@test.org" >> .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 "SECURITY_ADMIN_EMAIL=securityadmin@dispostable.com" >> .env - echo "SECURITY_ADMIN_PASSWORD=Dogfood1!" >> .env - echo "ADMIN_EMAIL=ladot@dispostable.com" >> .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 diff --git a/push.sh b/push.sh index d8498ca2..87759288 100755 --- a/push.sh +++ b/push.sh @@ -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 diff --git a/server/.env.example b/server/.env.example index 77cc766b..2041f933 100644 --- a/server/.env.example +++ b/server/.env.example @@ -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_SENDER=tdm+sendgrid@test.org -# EMAIL_PUBLIC_COMMENT_LA_CITY=tdm+devpubliccommentplanning@test.org -# EMAIL_PUBLIC_COMMENT_WEB_TEAM=tdm+devpubliccomment@test.org - -# 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 -# SECURITY_ADMIN_EMAIL=securityadmin@dispostable.com -# SECURITY_ADMIN_PASSWORD=Dogfood1! -# ADMIN_EMAIL=ladot@dispostable.com -# 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 \ No newline at end of file diff --git a/server/_jest-setup_/global-setup/global-setup.js b/server/_jest-setup_/global-setup/global-setup.js index a6b29b84..a805645a 100644 --- a/server/_jest-setup_/global-setup/global-setup.js +++ b/server/_jest-setup_/global-setup/global-setup.js @@ -1,3 +1,4 @@ +require("../utils/env-setup"); const { start } = require("../utils/mssql-container-setup"); module.exports = async () => { diff --git a/server/_jest-setup_/utils/env-setup.js b/server/_jest-setup_/utils/env-setup.js new file mode 100644 index 00000000..d8a70767 --- /dev/null +++ b/server/_jest-setup_/utils/env-setup.js @@ -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 = "tdm+sendgrid@test.org"; +process.env.EMAIL_PUBLIC_COMMENT_LA_CITY = + "tdm+devpubliccommentplanning@test.org"; +process.env.EMAIL_PUBLIC_COMMENT_WEB_TEAM = "tdm+devpubliccomment@test.org"; + +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 = "securityadmin@dispostable.com"; +process.env.SECURITY_ADMIN_PASSWORD = "Dogfood1!"; +process.env.ADMIN_EMAIL = "ladot@dispostable.com"; +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";