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

Integration tests #33

Open
octopusinvitro opened this issue Jan 19, 2018 · 1 comment
Open

Integration tests #33

octopusinvitro opened this issue Jan 19, 2018 · 1 comment

Comments

@octopusinvitro
Copy link
Contributor

octopusinvitro commented Jan 19, 2018

See our contributing guides.

Stripe is more or less stable now. The tests in the resource creator have just one success test and the rest of tests are testing what we do when something fails. For the success test and for the failure tests we are doing real requests that are then replayed by VCR.

At the moment we may be in a position where we can avoid those cassettes completely by adding this to each of the parameter tests in resource_creator_spec.rb, right before the call to expect_creation_to_fail_with():

allow(resource).to receive(:create).with(fields).and_raise(Stripe::EXCEPTION_NAME_HERE)

Then we should have a spec/donation_system/integration_spec.rb file in the top level that creates one donation of each type (Stripe one-off, Stripe recurring, PayPal one-off, PayPal recurring, etc.) passing an instance of RawRequestData with the relevant fields for each donation to the Payment object. These tests will then do real requests so we would use VCR or webmock for those tests only (VCR and webmock fixtures are a pain to maintain and add a lot of noise to git, so better to keep them either small or out of the git history completely as we are doing at the moment).

@octopusinvitro
Copy link
Contributor Author

octopusinvitro commented Jan 31, 2018

P.S. Meanwhile, if you ever hit Stripe's 25-subscriptions-per-customer limit, you can use this script:

# frozen_string_literal: true

require 'stripe'

Stripe.api_key = ENV['STRIPE_SECRET_KEY']

def delete
  customer_used_in_tests = 'cus_CAISMYrOdzMtdE'

  Stripe::Customer.list.data.each do |customer|
    test_customer = Stripe::Customer.retrieve(customer.id)
    test_customer.subscriptions.data.each(&:delete) if customer.id == customer_used_in_tests
    test_customer.delete unless customer.id == customer_used_in_tests # this is not needed but while you're at it why not clean a bit
  end
end

50.times { delete }
$ bundle exec ruby delete.rb

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

No branches or pull requests

1 participant