Skip to content

Commit

Permalink
Add support for the PromotionCode resource and APIs (#937)
Browse files Browse the repository at this point in the history
* Codegen for openapi f71053e

* Add tests
  • Loading branch information
remi-stripe authored Aug 5, 2020
1 parent f240405 commit cf8b2c5
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/object_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def self.object_names_to_classes
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,
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
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"
Expand Down
12 changes: 12 additions & 0 deletions lib/stripe/resources/promotion_code.rb
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions test/stripe/promotion_code_test.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/stripe/subscription_item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SubscriptionItemTest < Test::Unit::TestCase

should "be creatable" do
item = Stripe::SubscriptionItem.create(
plan: "sapphire-elite",
price: "sapphire-elite",
quantity: 3,
subscription: "sub_123"
)
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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
Expand Down

0 comments on commit cf8b2c5

Please sign in to comment.