-
Notifications
You must be signed in to change notification settings - Fork 552
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
How to stub subscritption status with mocha? #849
Comments
Mocking I would recommend using the subscription = Stripe::Subscription.construct_from({id: 'sub_123', object: 'subscription', status: 'incomplete'}) Or if you already have a full subscription object and just want to replace the # subscription is an existing Stripe::Subscription
incomplete_subscription = Stripe::Subscription.construct_from(subscription.to_h.merge({status: 'incomplete'})) Does this answer your question? |
Thanks @ob-stripe for the response but unfortunately I don't have access to the |
Hey @lefterisnik, In that case, I'd suggest doing the first option that OB subscription = Stripe::Subscription.construct_from({
id: 'sub_123',
object: 'subscription'
})
Stripe::Subscription.construct_from(subscription.to_h.merge({status: 'incomplete'})) Just having the Your other option is to use stripe-ruby-mock to generate a require 'stripe_mock'
Stripe.api_key = 'sk_test_123'
StripeMock.start
stripe_helper = StripeMock.create_test_helper
customer = Stripe::Customer.create(
currency: "USD",
source: stripe_helper.generate_card_token,
)
plan = Stripe::Plan.create(
amount: 1000,
currency: "USD",
interval: "month",
product: {name: "My Plan"},
)
subscription = Stripe::Subscription.create(
customer: customer.id,
plan: plan.id
)
p subscription You can then feed that subscription back into the code from Stripe::Subscription.construct_from(subscription.to_h.merge({status: 'incomplete'})) I'm not sure that I'd completely recommend this last Anyway, we know that the library's testing story isn't |
Closing due to age, but feel free to reply. |
I am trying to test our migration to SCA and I want to stub the subscription status to
incomplete
. The code I am using follows:The backend creates a subscription using the
stripe-mock-ruby
which currently is not able to handle sophisticated sca workflows, so it returns a subscription withstatus="active"
. For that reason, I would like to stub the subscription as above to make sure that my code which checks for extra authentication is working properly. Any help would be appreciate.The text was updated successfully, but these errors were encountered: