Skip to content

Conversation

brarnaudovski
Copy link

@brarnaudovski brarnaudovski commented Jul 22, 2025

WIP

Fixes #10755 Closes #10829

Summary of the problem

Summary from the issue #10755

There are several tests in our test suite making real API calls to Stripe and other services. We should consider stubbing these out with a gem like https://rubygems.org/gems/vcr or https://rubygems.org/gems/webmock so they're easier to run.

This might also let us reduce the number of credentials needed (or completely eliminate them) so anyone outside of HCB can run things.

Describe your changes

webmock integration as library used in test group that mocks web requests.

integration of the library involves fixing the existing web requests called in the specs. Otherwise, specs that make real web requests fail with webmock exception.
Following is all the spec files that need fixing:

  • spec/controllers/ach_transfers_controller_spec.rb
  • UserService::SyncWithLoops
  • others tba

@davidcornu
Copy link
Member

@brarnaudovski this is great! You might not actually need the Loops stuff now that #11140 has shipped.

github-merge-queue bot pushed a commit that referenced this pull request Sep 29, 2025
…11751)

## Summary of the problem

**Prior art**
- #10755
- #8945
- #10829
- #11061
- #11230 (which added WebMock)

Because our test suite makes external API calls and relies on certain
credentials being available,
- It does not run successfully for third-party (including Dependabot)
PRs as we don't provision all the environment variables
- It is a pain to get running locally as you need credentials for a
bunch of services
- It does not run without a network connection

## Describe your changes

I commented out my local `.env` file, configured WebMock to block all
requests, and chipped away at all the errors until the whole thing ran
successfully. This ended up involving:

1. Adding fallback values for `TEST_URL_HOST` (this seems like an odd
thing to require in the first place)
2. Generating a fake Stripe API key when one isn't configured (only in
the test env)
3. Generating an ephemeral encryption key for `Lockbox` if one isn't
configured (only in the test env)
4. Generating ephemeral encryption keys for `ActoveRecord::Encryption`
if they aren't configured (only in the test env)
5. Added a cached version of the `EuCentralBank` values for use in the
test env
6. Added stubs and/or performed additional refactors to impacted tests

When (2), (3), and (4) take effect we log the ephemeral values to
STDERR:

<img width="880" height="223" alt="CleanShot 2025-09-24 at 16 40 37"
src="https://github.com/user-attachments/assets/a2faa6b8-d51f-494c-8a44-b739417b1090"
/>

I've also removed `WebMock.allow_net_connect!` so any newly-introduced
network calls will fail.

## Notes

- Some of the changes in this PR were extracted into
#11750
- This was purposefully opened from a fork to see if we can get a clean
CI run from an outside contribution
@davidcornu
Copy link
Member

Closing this on account of #11751.

Thanks for having taken a stab at this @brarnaudovski ❤️

@davidcornu davidcornu closed this Sep 29, 2025
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.

[DX] Stub out remote calls in the test suite

2 participants