From 531509a04da62d33f65393f2dd0e2354c48638b1 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Tue, 4 Aug 2020 18:30:59 -0700 Subject: [PATCH 1/2] Codegen for openapi f71053e --- lib/stripe/object_types.rb | 1 + lib/stripe/resources.rb | 1 + lib/stripe/resources/promotion_code.rb | 12 ++++++++++++ 3 files changed, 14 insertions(+) create mode 100644 lib/stripe/resources/promotion_code.rb diff --git a/lib/stripe/object_types.rb b/lib/stripe/object_types.rb index 48bd292ce..2e141488e 100644 --- a/lib/stripe/object_types.rb +++ b/lib/stripe/object_types.rb @@ -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, diff --git a/lib/stripe/resources.rb b/lib/stripe/resources.rb index 2b35744b3..c8587a6f9 100644 --- a/lib/stripe/resources.rb +++ b/lib/stripe/resources.rb @@ -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" diff --git a/lib/stripe/resources/promotion_code.rb b/lib/stripe/resources/promotion_code.rb new file mode 100644 index 000000000..3d3130e20 --- /dev/null +++ b/lib/stripe/resources/promotion_code.rb @@ -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 From 31a6eb99630ab2ff1582321d9c9d66405cc09a4e Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Tue, 4 Aug 2020 18:42:16 -0700 Subject: [PATCH 2/2] Add tests --- .travis.yml | 2 +- test/stripe/promotion_code_test.rb | 42 +++++++++++++++++++++++++++ test/stripe/subscription_item_test.rb | 2 +- test/test_helper.rb | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 test/stripe/promotion_code_test.rb diff --git a/.travis.yml b/.travis.yml index f4fa188bd..1c40a689f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/test/stripe/promotion_code_test.rb b/test/stripe/promotion_code_test.rb new file mode 100644 index 000000000..b09a8d941 --- /dev/null +++ b/test/stripe/promotion_code_test.rb @@ -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 diff --git a/test/stripe/subscription_item_test.rb b/test/stripe/subscription_item_test.rb index a1155cef8..16f7a4525 100644 --- a/test/stripe/subscription_item_test.rb +++ b/test/stripe/subscription_item_test.rb @@ -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" ) diff --git a/test/test_helper.rb b/test/test_helper.rb index 2a4f618cc..e296bec64 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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