/
promotion_code_test.rb
42 lines (36 loc) · 1.37 KB
/
promotion_code_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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