Sha256: 4285807bfd44d47173601d3d505b3e6898609bb492a213a684edb551f971e3c3

Contents?: true

Size: 1.51 KB

Versions: 22

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require ::File.expand_path("../../test_helper", __FILE__)

module Stripe
  class CouponTest < Test::Unit::TestCase
    should "be listable" do
      coupons = Stripe::Coupon.list
      assert_requested :get, "#{Stripe.api_base}/v1/coupons"
      assert coupons.data.is_a?(Array)
      assert coupons.first.is_a?(Stripe::Coupon)
    end

    should "be retrievable" do
      coupon = Stripe::Coupon.retrieve("25OFF")
      assert_requested :get, "#{Stripe.api_base}/v1/coupons/25OFF"
      assert coupon.is_a?(Stripe::Coupon)
    end

    should "be creatable" do
      coupon = Stripe::Coupon.create(
        percent_off: 25,
        duration: "repeating",
        duration_in_months: 3,
        id: "25OFF"
      )
      assert_requested :post, "#{Stripe.api_base}/v1/coupons"
      assert coupon.is_a?(Stripe::Coupon)
    end

    should "be saveable" do
      coupon = Stripe::Coupon.retrieve("25OFF")
      coupon.metadata["key"] = "value"
      coupon.save
      assert_requested :post, "#{Stripe.api_base}/v1/coupons/#{coupon.id}"
    end

    should "be updateable" do
      coupon = Stripe::Coupon.update("25OFF", metadata: { key: "value" })
      assert_requested :post, "#{Stripe.api_base}/v1/coupons/25OFF"
      assert coupon.is_a?(Stripe::Coupon)
    end

    should "be deletable" do
      coupon = Stripe::Coupon.retrieve("25OFF")
      coupon = coupon.delete
      assert_requested :delete, "#{Stripe.api_base}/v1/coupons/#{coupon.id}"
      assert coupon.is_a?(Stripe::Coupon)
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
stripe-3.31.0 test/stripe/coupon_test.rb
stripe-3.30.0 test/stripe/coupon_test.rb