Add support for the PromotionCode resource and APIs (#937)

* Codegen for openapi f71053e

* Add tests
This commit is contained in:
remi-stripe 2020-08-05 12:33:47 -07:00 committed by GitHub
parent f240405810
commit cf8b2c5e84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 3 deletions

View File

@ -17,7 +17,7 @@ sudo: false
env:
global:
# If changing this number, please also change it in `test/test_helper.rb`.
- STRIPE_MOCK_VERSION=0.94.0
- STRIPE_MOCK_VERSION=0.95.0
cache:
directories:

View File

@ -61,6 +61,7 @@ module Stripe
Plan::OBJECT_NAME => Plan,
Price::OBJECT_NAME => Price,
Product::OBJECT_NAME => Product,
PromotionCode::OBJECT_NAME => PromotionCode,
Radar::EarlyFraudWarning::OBJECT_NAME => Radar::EarlyFraudWarning,
Radar::ValueList::OBJECT_NAME => Radar::ValueList,
Radar::ValueListItem::OBJECT_NAME => Radar::ValueListItem,

View File

@ -50,6 +50,7 @@ require "stripe/resources/person"
require "stripe/resources/plan"
require "stripe/resources/price"
require "stripe/resources/product"
require "stripe/resources/promotion_code"
require "stripe/resources/radar/early_fraud_warning"
require "stripe/resources/radar/value_list"
require "stripe/resources/radar/value_list_item"

View File

@ -0,0 +1,12 @@
# File generated from our OpenAPI spec
# frozen_string_literal: true
module Stripe
class PromotionCode < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save
OBJECT_NAME = "promotion_code"
end
end

View File

@ -0,0 +1,42 @@
# frozen_string_literal: true
require ::File.expand_path("../test_helper", __dir__)
module Stripe
class PromotionCodeTest < Test::Unit::TestCase
should "be listable" do
promotion_codes = Stripe::PromotionCode.list
assert_requested :get, "#{Stripe.api_base}/v1/promotion_codes"
assert promotion_codes.data.is_a?(Array)
assert promotion_codes.first.is_a?(Stripe::PromotionCode)
end
should "be retrievable" do
coupon = Stripe::PromotionCode.retrieve("PROMO_123")
assert_requested :get, "#{Stripe.api_base}/v1/promotion_codes/PROMO_123"
assert coupon.is_a?(Stripe::PromotionCode)
end
should "be creatable" do
coupon = Stripe::PromotionCode.create(
coupon: "co_123",
code: "MYCODE"
)
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes"
assert coupon.is_a?(Stripe::PromotionCode)
end
should "be saveable" do
coupon = Stripe::PromotionCode.retrieve("PROMO_123")
coupon.metadata["key"] = "value"
coupon.save
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes/#{coupon.id}"
end
should "be updateable" do
coupon = Stripe::PromotionCode.update("PROMO_123", metadata: { key: "value" })
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes/PROMO_123"
assert coupon.is_a?(Stripe::PromotionCode)
end
end
end

View File

@ -22,7 +22,7 @@ module Stripe
should "be creatable" do
item = Stripe::SubscriptionItem.create(
plan: "sapphire-elite",
price: "sapphire-elite",
quantity: 3,
subscription: "sub_123"
)

View File

@ -16,7 +16,7 @@ require ::File.expand_path("test_data", __dir__)
require ::File.expand_path("stripe_mock", __dir__)
# If changing this number, please also change it in `.travis.yml`.
MOCK_MINIMUM_VERSION = "0.94.0"
MOCK_MINIMUM_VERSION = "0.95.0"
MOCK_PORT = Stripe::StripeMock.start
# Disable all real network connections except those that are outgoing to