Skip to content

Commit

Permalink
Add more tests for request opts flow (#1398)
Browse files Browse the repository at this point in the history
* Add more tests for request opts flow

* spurious change

* fix return url
  • Loading branch information
anniel-stripe committed May 6, 2024
1 parent 6e4f40f commit f538d42
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/stripe/api_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ class NestedTestAPIResource < APIResource
ch = Stripe::Charge.retrieve("ch_123", "sk_test_local")
ch.refunds.create
end

should "use the per-object credential when making subsequent requests on the object" do
stub_request(:get, "#{Stripe.api_base}/v1/customers/cus_123")
.with(headers: { "Authorization" => "Bearer sk_test_local", "Stripe-Account" => "acct_12345" })
.to_return(body: JSON.generate(charge_fixture))
stub_request(:delete, "#{Stripe.api_base}/v1/customers/cus_123")
.with(headers: { "Authorization" => "Bearer sk_test_local", "Stripe-Account" => "acct_12345" })
.to_return(body: "{}")

cus = Stripe::Customer.retrieve("cus_123", { api_key: "sk_test_local", stripe_account: "acct_12345" })
cus.delete
end
end
end

Expand Down
22 changes: 22 additions & 0 deletions test/stripe/list_object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@ class ListObjectTest < Test::Unit::TestCase
assert_equal expected, list.auto_paging_each.to_a
end

should "forward api key through #auto_paging_iter" do
arr = [
{ id: "ch_001" },
{ id: "ch_002" },
]
expected = Util.convert_to_stripe_object(arr, {})

stub_request(:get, "#{Stripe.api_base}/v1/charges")
.with(headers: { "Authorization" => "Bearer sk_test_iter_forwards_options" })
.to_return(body: JSON.generate(data: [{ id: "ch_001" }], has_more: true, url: "/v1/charges",
object: "list"))
stub_request(:get, "#{Stripe.api_base}/v1/charges")
.with(headers: { "Authorization" => "Bearer sk_test_iter_forwards_options" })
.with(query: { starting_after: "ch_001" })
.to_return(body: JSON.generate(data: [{ id: "ch_002" }], has_more: false, url: "/v1/charges",
object: "list"))

list = Stripe::Charge.list({}, { api_key: "sk_test_iter_forwards_options" })

assert_equal expected, list.auto_paging_each.to_a
end

should "provide #auto_paging_each that responds to a block" do
arr = [
{ id: 1 },
Expand Down

0 comments on commit f538d42

Please sign in to comment.