-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adc0ccf
commit 23cbd8f
Showing
8 changed files
with
319 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
module Stripe | ||
module ApiVersion | ||
CURRENT = "2022-11-15" | ||
PREVIEW = "20230509T165653" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("../test_helper", __dir__) | ||
|
||
class PreviewTest < Test::Unit::TestCase | ||
context "preview raw requests" do | ||
should "send preview get request with correct default options" do | ||
expected_body = "{\"id\": \"acc_123\"}" | ||
req = nil | ||
|
||
stub_request(:get, "#{Stripe.api_base}/v2/accounts/acc_123") | ||
.with { |request| req = request } | ||
.to_return(body: expected_body) | ||
|
||
resp = Stripe::Preview.get("/v2/accounts/acc_123") | ||
|
||
assert_equal nil, req.headers["Content-Type"] | ||
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"] | ||
assert_equal expected_body, resp.http_body | ||
end | ||
|
||
should "send preview post request with correct default options" do | ||
expected_body = "{\"id\": \"acc_123\"}" | ||
req = nil | ||
|
||
stub_request(:post, "#{Stripe.api_base}/v2/accounts") | ||
.with { |request| req = request } | ||
.to_return(body: expected_body) | ||
|
||
resp = Stripe::Preview.post("/v2/accounts", { p1: 1, p2: "string" }) | ||
|
||
assert_equal "application/json", req.headers["Content-Type"] | ||
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"] | ||
assert_equal "{\"p1\":1,\"p2\":\"string\"}", req.body | ||
assert_equal expected_body, resp.http_body | ||
end | ||
|
||
should "send preview delete request with correct default options" do | ||
expected_body = "{\"id\": \"acc_123\"}" | ||
req = nil | ||
|
||
stub_request(:delete, "#{Stripe.api_base}/v2/accounts/acc_123") | ||
.with { |request| req = request } | ||
.to_return(body: expected_body) | ||
|
||
resp = Stripe::Preview.delete("/v2/accounts/acc_123") | ||
|
||
assert_equal nil, req.headers["Content-Type"] | ||
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"] | ||
assert_equal expected_body, resp.http_body | ||
end | ||
|
||
should "allow overriding default options for preview requests" do | ||
expected_body = "{\"id\": \"acc_123\"}" | ||
stripe_version_override = "2022-11-15" | ||
req = nil | ||
|
||
stub_request(:post, "#{Stripe.api_base}/v2/accounts") | ||
.with { |request| req = request } | ||
.to_return(body: expected_body) | ||
|
||
resp = Stripe::Preview.post("/v2/accounts", {}, { stripe_version: stripe_version_override }) | ||
|
||
assert_equal "application/json", req.headers["Content-Type"] | ||
assert_equal stripe_version_override, req.headers["Stripe-Version"] | ||
assert_equal expected_body, resp.http_body | ||
end | ||
|
||
should "allow setting stripe_context for preview requests" do | ||
expected_body = "{\"id\": \"acc_123\"}" | ||
stripe_context = "acc_123" | ||
req = nil | ||
|
||
stub_request(:post, "#{Stripe.api_base}/v2/accounts") | ||
.with { |request| req = request } | ||
.to_return(body: expected_body) | ||
|
||
Stripe::Preview.post("/v2/accounts", {}, { stripe_context: stripe_context }) | ||
|
||
assert_equal "application/json", req.headers["Content-Type"] | ||
assert_equal stripe_context, req.headers["Stripe-Context"] | ||
end | ||
end | ||
end |
Oops, something went wrong.