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

Tests app/services/stripe_payment_status.rb #11963

Merged

Conversation

filipefurtad0
Copy link
Contributor

What? Why?

Related to Epic #11890.
Closes #11962

Tests app/services/stripe_payment_status.rb by replacing receive_message_chain Rspec mocks with responses from VCR calls.

What should we test?

  • green build

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@filipefurtad0 filipefurtad0 self-assigned this Dec 21, 2023
@filipefurtad0
Copy link
Contributor Author

This PR seems to interfere with other VCR tapes, I'll move this back to In Dev till this is clarified.

@filipefurtad0 filipefurtad0 added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Dec 21, 2023
@@ -162,6 +162,9 @@
vcr_config.default_cassette_options = { record: :none } if ENV["CI"]
end
example.run
VCR.configure do |vcr_config|
vcr_config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems VCR was looking for a cassette in the Stripe folder, although this one is not related to Stripe:

       VCR is currently using the following cassette:
         - /home/runner/work/openfoodnetwork/openfoodnetwork/spec/fixtures/vcr_cassettes/Stripe-v10.3.0/ConnectAppJob/stores_connection_data_on_the_app.yml

Somehow, the around block on base spec helper is not really resetting the VCR configs. This change might just do it, but I'm not sure there isn't a better way.

Copy link
Member

Choose a reason for hiding this comment

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

This makes sense: we are setting a different config value, and need to re-set it back after the example is completed. This would be relevant for the other config change too (default_cassette_options).

I couldn't find a built-in method for achieving this, so would be tempted to build one..
For now, I'd suggest saving the current vcr_config before example.run, then applying it again after.

I've pushed a new commit to demonstrate, let me know what you think.

I couldn't find a built-in way to do it, and couldn't even directly access the vcr config outside of VCR.configure. So this is the best way I could think of.
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great, the spec updates look good.

I've added a suggested improvement, and have a comment about further simplifying the setup.

I think this is good as-is, but will await a second review for my code updates.

@@ -162,6 +162,9 @@
vcr_config.default_cassette_options = { record: :none } if ENV["CI"]
end
example.run
VCR.configure do |vcr_config|
vcr_config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
end
Copy link
Member

Choose a reason for hiding this comment

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

This makes sense: we are setting a different config value, and need to re-set it back after the example is completed. This would be relevant for the other config change too (default_cassette_options).

I couldn't find a built-in method for achieving this, so would be tempted to build one..
For now, I'd suggest saving the current vcr_config before example.run, then applying it again after.

I've pushed a new commit to demonstrate, let me know what you think.

preferred_enterprise_id: create(:enterprise).id)
}

before { Stripe.api_key = secret }
Copy link
Member

Choose a reason for hiding this comment

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

I was going to suggest that we should reset the api key back after the end of the test. But then I realised that this key is the only key that would be used during tests, so we might as well set it once in envrionment config.

Then I realised we already do, in STRIPE_INSTANCE_SECRET_KEY. Do you know why we set the test key in a special STRIPE_SECRET_TEST_API_KEY?

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Good team work.

@mkllnk mkllnk merged commit 1f0c5fc into openfoodfoundation:master Jan 2, 2024
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Integration/API tests] app/services/stripe_payment_status.rb
3 participants