stripe-ruby-mock 1.8.4.6 → 1.8.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md
CHANGED
@@ -26,9 +26,15 @@ module StripeMock
|
|
26
26
|
|
27
27
|
customer = customers[$1]
|
28
28
|
assert_existance :customer, $1, customer
|
29
|
+
|
29
30
|
plan = plans[ params[:plan] ]
|
30
31
|
assert_existance :plan, params[:plan], plan
|
31
32
|
|
33
|
+
# Ensure customer has card to charge if plan has no trial and is not free
|
34
|
+
if customer[:default_card].nil? && plan[:trial_period_days].nil? && plan[:amount] != 0
|
35
|
+
raise Stripe::InvalidRequestError.new('You must supply a valid card', nil, 400)
|
36
|
+
end
|
37
|
+
|
32
38
|
sub = Data.mock_subscription id: new_id('su'), plan: plan, customer: $1
|
33
39
|
customer[:subscription] = sub
|
34
40
|
end
|
data/lib/stripe_mock/version.rb
CHANGED
@@ -114,7 +114,7 @@ shared_examples 'Customer API' do
|
|
114
114
|
|
115
115
|
it "updates a stripe customer's subscription" do
|
116
116
|
plan = Stripe::Plan.create(id: 'silver')
|
117
|
-
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
117
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub', card: 'tk')
|
118
118
|
sub = customer.update_subscription({ :plan => 'silver' })
|
119
119
|
|
120
120
|
expect(sub.object).to eq('subscription')
|
@@ -128,9 +128,52 @@ shared_examples 'Customer API' do
|
|
128
128
|
expect(customer.subscription.customer).to eq(customer.id)
|
129
129
|
end
|
130
130
|
|
131
|
+
it "throws an error when subscribing a customer with no card" do
|
132
|
+
plan = Stripe::Plan.create(id: 'enterprise', amount: 499)
|
133
|
+
customer = Stripe::Customer.create(id: 'cardless')
|
134
|
+
|
135
|
+
expect { customer.update_subscription({ :plan => 'enterprise' }) }.to raise_error {|e|
|
136
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
137
|
+
expect(e.http_status).to eq(400)
|
138
|
+
expect(e.message).to_not be_nil
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
it "subscribes a customer with no card to a free plan" do
|
143
|
+
plan = Stripe::Plan.create(id: 'free_tier', amount: 0)
|
144
|
+
customer = Stripe::Customer.create(id: 'cardless')
|
145
|
+
sub = customer.update_subscription({ :plan => 'free_tier' })
|
146
|
+
|
147
|
+
expect(sub.object).to eq('subscription')
|
148
|
+
expect(sub.plan.id).to eq('free_tier')
|
149
|
+
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
150
|
+
|
151
|
+
customer = Stripe::Customer.retrieve('cardless')
|
152
|
+
expect(customer.subscription).to_not be_nil
|
153
|
+
expect(customer.subscription.id).to eq(sub.id)
|
154
|
+
expect(customer.subscription.plan.id).to eq('free_tier')
|
155
|
+
expect(customer.subscription.customer).to eq(customer.id)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "subscribes a customer with no card to a plan with a free trial" do
|
159
|
+
plan = Stripe::Plan.create(id: 'trial', amount: 999, trial_period_days: 14)
|
160
|
+
customer = Stripe::Customer.create(id: 'cardless')
|
161
|
+
sub = customer.update_subscription({ :plan => 'trial' })
|
162
|
+
|
163
|
+
expect(sub.object).to eq('subscription')
|
164
|
+
expect(sub.plan.id).to eq('trial')
|
165
|
+
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
166
|
+
|
167
|
+
customer = Stripe::Customer.retrieve('cardless')
|
168
|
+
expect(customer.subscription).to_not be_nil
|
169
|
+
expect(customer.subscription.id).to eq(sub.id)
|
170
|
+
expect(customer.subscription.plan.id).to eq('trial')
|
171
|
+
expect(customer.subscription.customer).to eq(customer.id)
|
172
|
+
end
|
173
|
+
|
131
174
|
it "cancels a stripe customer's subscription" do
|
132
175
|
plan = Stripe::Plan.create(id: 'the truth')
|
133
|
-
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
176
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub', card: 'tk')
|
134
177
|
sub = customer.update_subscription({ :plan => 'the truth' })
|
135
178
|
|
136
179
|
result = customer.cancel_subscription
|