-
-
Notifications
You must be signed in to change notification settings - Fork 708
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
[Stripe, VCR] Updates credit_card_remover_spec.rb #12104
[Stripe, VCR] Updates credit_card_remover_spec.rb #12104
Conversation
81fe5ad
to
3810006
Compare
b8d8cc3
to
a161238
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. This is good basic coverage with real interaction. We don't need to cover everything. We can add more specs if we find bugs somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great to see more and more real-world tests, good work!
I have a question to discuss/consider, which doesn't have to be addressed immediately.
±
But I think we should update the example description, as suggested below:
let!(:enterprise) { create(:enterprise) } | ||
|
||
describe "#remove", :vcr, :stripe_version do | ||
before { Stripe.api_key = secret } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting a system config, without later un-setting it makes me uncomfortable (it means the test leaves the system in a different state to when it started).
It looks like you developed the with_stripe_setup helper to do this safely, so I would suggest using that.
But... I'm not sure that's even necessary. Do you know why we have a different environment variable for the test api_key? Why don't we just set the test key in STRIPE_INSTANCE_SECRET_KEY
for test environments? This will be loaded automatically (like it is on production environments).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Thanks for this comment.
I've changed the ./config/initializers/stripe.rb
on the last commit to take the test API key for test and CI environments. I think this PR would need to be staged and tested, so we're sure the key is still taken for staging and production environments - right? What do you think @dacook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that simplifies things, and clarifies my suggestion a little bit.
My suggestion was to go even further, to remove the variable STRIPE_SECRET_TEST_API_KEY
altogether.
We can then add STRIPE_INSTANCE_SECRET_KEY
to .env.test.local
, and add the secret test key there.
Then I think we wouldn't need to change ./config/initializers/stripe.rb
at all, meaning we don't need any manual testing.
a161238
to
c68c090
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one @filipefurtad0 !
I added a few suggestions, see my comments.
Stripe::CreditCardRemover.new(credit_card).call | ||
context 'and is deleted' do | ||
it 'deletes the credit card clone' do | ||
customer = double('customer', deleted?: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum. I believe I must have screwed up my git history: this should not be here, in fact it is possible to delete the customer within a before block, and then run the test... I'll try to replace this stub as well. Moving back to in dev.
7bda02d
to
ddc1296
Compare
Hum. I think I see why we're not really deleting cards, if we call this separately, we get:
So, there are no clones, because none were created. So the tests are only catching customer deletion. Maybe this is ok for now, but the descriptions on the Still, I guess the PR brings improvements, and reviews have been addressed. I'd move to code review (and open an issue to explicitly address card deletion if we opt for merging this one as is). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, I agree that this is a good improvement and we can proceed with other changes for deleting cloned cards in a new PR.
As you suggested, it would be a good idea to manually test, because we're updating the stipe initialiser.
In that case, it might be worth considering my comment, which removes the need for testing. I'll move to in dev in case you'd like to try that, but if not (or it doesn't work), then this is fine as it is.
fcbd561
to
0d2419c
Compare
Apologies @dacook , I did not read your comment correctly before:
The changes on stripe.rb initializer were undone on the last commit. In addition to these changes, we need to change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, except we need to re-record the cassettes to be sure.
I did this, and found that we need to update the vcr config to ensure the key is filtered out.
I did that, but a couple of specs failed 😢
- This might be because I was missing
STRIPE_CUSTOMER
in my config. Can you please check if that is in bitwarden? I also don't haveSTRIPE_ACCOUNT
, should I?
Stripe::InvalidRequestError:
No such customer: 'bogus_customer'
# ./spec/lib/stripe/credit_card_cloner_spec.rb:63:in `block (4 levels) in <module:Stripe>'
- At first glance, I'm not sure about this one, do you know?
expected: "requires_capture"
got: "requires_action"
(compared using ==)
Shared Example Group: "payments intents" called from ./spec/lib/stripe/payment_intent_validator_spec.rb:90
# ./spec/lib/stripe/payment_intent_validator_spec.rb:60:in `block (6 levels) in <main>'
Yes... I believe this is the case too. The reason for this is that I've mistakenly hard-coded these two on a previous PR, and am proposing the correct approach here. Maybe we should wait till #12127 is merged, and then rebase this branch? I've taken the liberty to mark this PR as blocked.
Edited
I've investigated this a bit further, and am not convinced points 1. and 2. are related. At least I don't see it now. I've opened a PR to make the build green again (when re-recording requests). |
This is also discussed here #12113 (comment) for reference |
Maybe not needed but, brings perhaps some structure to the spec, an creates a place holder for the required setup
deletes previous cassette
Updates spec accordingly
Sets instance key in .env.test file
If the working directory is dirty, git rm might fail.
And also STRIPE_ENDPOINT_SECRET just in case it's ever used in tests. Re-records Stripe tests. But some failed... :'( Failed examples: rspec ./spec/lib/stripe/credit_card_cloner_spec.rb:71 # Stripe::CreditCardCloner#find_or_clone when called with a valid customer and payment_method clones both the payment method and the customer rspec ./spec/lib/stripe/payment_intent_validator_spec.rb[1:1:1:1:17:1:2] # Stripe::PaymentIntentValidator#call when payment intent is valid valid non-3D credit cards are correctly handled behaves like payments intents from UnionPay (debit) captures the payment
97b18ee
to
60c03f6
Compare
Alright, quite a journey on this one 😅 PS: in case reviewers wish to re-record the tapes -> we need to rename the api key in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hooray, great work pulling it all together!
Closes #12001, as I think:
./spec/lib/stripe/credit_card_remover_spec.rb
requires./lib/stripe/credit_card_clone_destroyer.rb
to work.Not too sure my approach is correct:
delete
called over customers... not sure.Still, I think this provides value and perhaps some food for thought.
What? Why?
Updates
credit_card_remover_spec.rb
, by replacing remove stubs with real HTTP/vcr calls.Addresses a loose end, from a previous PR, here.
What should we test?
Release notes
Changelog Category (reviewers may add a label for the release notes):
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates