Skip to content

Commit

Permalink
Use Stripe Util to create objects
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Oct 2, 2024
1 parent 190d50e commit c7025a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/pay/stripe/webhooks/customer_updated_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Pay::Stripe::Webhooks::CustomerUpdatedTest < ActiveSupport::TestCase

test "removes default payment method if default payment method set to null" do
event = stripe_event("customer.updated")
Pay::Stripe::Customer.any_instance.expects(:api_record).returns(::Stripe::Customer.construct_from(invoice_credit_balance: Stripe::Util.convert_to_stripe_object({usd: 12345}), invoice_settings: ActiveSupport::InheritableOptions.new(default_payment_method: nil), currency: "usd"))
Pay::Stripe::Customer.any_instance.expects(:api_record).returns(::Stripe::Customer.construct_from(invoice_credit_balance: Stripe::Util.convert_to_stripe_object({usd: 12345}), invoice_settings: Stripe::Util.convert_to_stripe_object({default_payment_method: nil}), currency: "usd"))
assert_not_nil @pay_customer.default_payment_method
Pay::Stripe::Webhooks::CustomerUpdated.new.call(event)
@pay_customer.reload
Expand All @@ -22,7 +22,7 @@ class Pay::Stripe::Webhooks::CustomerUpdatedTest < ActiveSupport::TestCase

test "stripe invoice credit balance is updated" do
event = stripe_event("customer.updated")
Pay::Stripe::Customer.any_instance.expects(:api_record).returns(::Stripe::Customer.construct_from(invoice_credit_balance: Stripe::Util.convert_to_stripe_object({usd: 12345}), invoice_settings: ActiveSupport::InheritableOptions.new(default_payment_method: nil), currency: "usd"))
Pay::Stripe::Customer.any_instance.expects(:api_record).returns(::Stripe::Customer.construct_from(invoice_credit_balance: Stripe::Util.convert_to_stripe_object({usd: 12345}), invoice_settings: Stripe::Util.convert_to_stripe_object({default_payment_method: nil}), currency: "usd"))
Pay::Stripe::Webhooks::CustomerUpdated.new.call(event)
@pay_customer.reload
assert_equal "usd", @pay_customer.currency
Expand Down
4 changes: 2 additions & 2 deletions test/pay/stripe/webhooks/payment_method_updated_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class Pay::Stripe::Webhooks::PaymentMethodUpdatedTest < ActiveSupport::TestCase
payment_method = pay_payment_methods(:one)

# Spoof Stripe PaymentMethod lookup
fake_payment_method = ::Stripe::PaymentMethod.construct_from(id: payment_method.processor_id, customer: "cus_1234", type: "card", card: ActiveSupport::InheritableOptions.new(brand: "Visa", last4: "4242", exp_month: "01", exp_year: "2034"))
fake_payment_method = ::Stripe::PaymentMethod.construct_from(id: payment_method.processor_id, customer: "cus_1234", type: "card", card: Stripe::Util.convert_to_stripe_object({brand: "Visa", last4: "4242", exp_month: "01", exp_year: "2034"}))
::Stripe::PaymentMethod.expects(:retrieve).returns(fake_payment_method)

fake_customer = ::Stripe::Customer.construct_from(invoice_settings: ActiveSupport::InheritableOptions.new(default_payment_method: nil))
fake_customer = ::Stripe::Customer.construct_from(invoice_settings: Stripe::Util.convert_to_stripe_object({default_payment_method: nil}))
::Stripe::Customer.expects(:retrieve).returns(fake_customer)

assert_equal payment_method.exp_year, payment_method.exp_year
Expand Down

0 comments on commit c7025a0

Please sign in to comment.