stripe-ruby/test/stripe/ephemeral_key_test.rb
helenye-stripe 41f5d0a594
Merge and codegen from master stripe-ruby v13.0.0 (#1465)
* Support for APIs in the new API version 2024-09-30.acacia (#1458)

* remove parseSnapshotEvent (#1463)

* Bump version to 13.0.0

* Fixed API Version

---------

Co-authored-by: Ramya Rao <100975018+ramya-stripe@users.noreply.github.com>
Co-authored-by: Ramya Rao <ramya@stripe.com>
Co-authored-by: Prathmesh Ranaut <prathmesh@stripe.com>
2024-10-03 16:31:59 -04:00

95 lines
2.5 KiB
Ruby

# frozen_string_literal: true
require File.expand_path("../test_helper", __dir__)
module Stripe
class EphemeralKeyTest < Test::Unit::TestCase
context "#create" do
should "succeed" do
key = Stripe::EphemeralKey.create(
{ customer: "cus_123" },
stripe_version: "2017-05-25"
)
assert_requested(
:post,
"#{Stripe.api_base}/v1/ephemeral_keys",
headers: { "Stripe-Version" => "2017-05-25" }
)
assert key.is_a?(Stripe::EphemeralKey)
end
context "#no global version" do
should "use the correct api version" do
key = Stripe::EphemeralKey.create(
{ customer: "cus_123" },
stripe_version: "2017-06-05"
)
assert_requested(
:post,
"#{Stripe.api_base}/v1/ephemeral_keys",
headers: { "Stripe-Version" => "2017-06-05" }
)
assert key.is_a?(Stripe::EphemeralKey)
end
should "error without an explicit api version" do
e = assert_raises(ArgumentError) do
Stripe::EphemeralKey.create(customer: "cus_123")
end
assert_match("stripe_version must be specified", e.message)
end
end
context "#with global version" do
setup do
@old_api_version = Stripe.api_version
Stripe.api_version = "2017-05-25"
end
teardown do
Stripe.api_version = @old_api_version
end
should "use the correct api version" do
key = Stripe::EphemeralKey.create(
{ customer: "cus_123" },
stripe_version: "2017-05-25"
)
assert key.is_a?(Stripe::EphemeralKey)
end
should "error without an explicit api version" do
e = assert_raises(ArgumentError) do
Stripe::EphemeralKey.create(customer: "cus_123")
end
assert_match("stripe_version must be specified", e.message)
end
end
end
context "#delete" do
should "succeed" do
key = Stripe::EphemeralKey.create(
{ customer: "cus_123" },
stripe_version: "2017-05-25"
)
key.delete
assert_requested :delete, "#{Stripe.api_base}/v1/ephemeral_keys/#{key.id}"
end
end
context ".delete" do
should "succeed" do
Stripe::EphemeralKey.delete("ephkey_123")
assert_requested :delete, "#{Stripe.api_base}/v1/ephemeral_keys/ephkey_123"
end
end
end
end