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

fix: remove env variable dependencies from tests #4471

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Conversation

ludtkemorgan
Copy link
Collaborator

This PR addresses #4419

  • Addresses the issue in full
  • Addresses only certain aspects of the issue

Description

When setting up the circle-ci for the new forked Detroit repo I noticed there was a heavy reliance on environment variables in order to work.

This PR does the following:

  • Removes references to the env variables in unit/integration tests
  • Update the circle-ci configuration file to have all of the need environment variables (none of them are secret) in cypress tests
  • Mock calls to cloudinary in cypress tests
  • mock calls to mapbox in cypress tests

How Can This Be Tested/Reviewed?

This is hard to show that it works locally and also the circle-ci run of this PR will still have all of the previously saved environment variables.

I tested this by creating a PR in bloom-detroit and didn't add any env variables to the circle-ci UI. bloom-housing#1

Author Checklist:

  • Added QA notes to the issue with applicable URLs
  • Reviewed in a desktop view
  • Reviewed in a mobile view
  • Reviewed considering accessibility
  • Added tests covering the changes
  • Made corresponding changes to the documentation
  • Ran yarn generate:client and/or created a migration when required

Review Process:

  • Read and understand the issue
  • Ensure the author has added QA notes
  • Review the code itself from a style point of view
  • Pull the changes down locally and test that the acceptance criteria is met
  • Either (1) explicitly ask a clarifying question, (2) request changes, or (3) approve the PR, even if there are very small remaining changes, if you don't need to re-review after the updates

Copy link

netlify bot commented Nov 8, 2024

Deploy Preview for partners-bloom-dev ready!

Name Link
🔨 Latest commit 334852b
🔍 Latest deploy log https://app.netlify.com/sites/partners-bloom-dev/deploys/67365e4337140b00085d0d19
😎 Deploy Preview https://deploy-preview-4471--partners-bloom-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Nov 8, 2024

Deploy Preview for bloom-exygy-dev ready!

Name Link
🔨 Latest commit 334852b
🔍 Latest deploy log https://app.netlify.com/sites/bloom-exygy-dev/deploys/67365e43860ac80008cc610c
😎 Deploy Preview https://deploy-preview-4471--bloom-exygy-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ludtkemorgan ludtkemorgan marked this pull request as ready for review November 8, 2024 16:30
@ludtkemorgan ludtkemorgan added the 1 review needed Requires 1 more review before ready to merge label Nov 8, 2024
@jaredcwhite
Copy link
Collaborator

@ludtkemorgan It does seem surprising to me to see references to setting environment variables within individual tests. I understand having a set of explicit variables set somewhere in a test environment as it boots up, but I think it feels fragile to be referencing env vars at all in the code of unit tests.

Copy link
Collaborator

@mcgarrye mcgarrye left a comment

Choose a reason for hiding this comment

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

Functionally this looks good, not sure how you think of Jared's comment

api/test/integration/lottery.e2e-spec.ts Outdated Show resolved Hide resolved
@mcgarrye mcgarrye removed the 1 review needed Requires 1 more review before ready to merge label Nov 12, 2024
@ludtkemorgan
Copy link
Collaborator Author

@jaredcwhite If you run the tests locally right now it expects your local .env file to contain the appropriate variables. So if you are missing some (or in some cases have the wrong value) the tests would fail locally.

This PR does a few things:

  • Cypress tests mock some calls. This means the env variables aren't even needed for this aspect of the test
  • Cypress tests circle ci configuration have the values so we don't have to manually set it in cypress every new repo
  • Backend e2e tests set the environment variables needed for the tested module set in the "beforeAll".
    • Looks like I put one variable within the specific test, I can move that to the top
  • Backend unit tests. When an environment variable is referenced in the function we are testing then I set the env variable at the beginning of the test.

As for your question about unit tests, my thought was this makes it less flaky since it will be the same in all environments - locally and deployed. Also it gives us the benefit of testing scenarios where the environment variable is something different.

We can talk about this more in standup or a eng workshop

@ludtkemorgan ludtkemorgan merged commit a519fdd into main Nov 14, 2024
20 checks passed
@ludtkemorgan ludtkemorgan deleted the circle-ci branch November 14, 2024 22:13
ludtkemorgan added a commit to metrotranscom/doorway that referenced this pull request Nov 18, 2024
ludtkemorgan added a commit to metrotranscom/doorway that referenced this pull request Nov 19, 2024
ludtkemorgan added a commit to metrotranscom/doorway that referenced this pull request Nov 20, 2024
ludtkemorgan added a commit to metrotranscom/doorway that referenced this pull request Nov 25, 2024
ludtkemorgan added a commit to housingbayarea/bloom that referenced this pull request Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants