stripe-ruby-mock 2.5.6 → 3.1.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -1
- data/.travis.yml +6 -9
- data/CHANGELOG.md +35 -0
- data/Gemfile +1 -0
- data/README.md +17 -11
- data/lib/stripe_mock.rb +11 -0
- data/lib/stripe_mock/api/client.rb +1 -1
- data/lib/stripe_mock/api/errors.rb +34 -28
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +7 -0
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data.rb +323 -13
- data/lib/stripe_mock/data/list.rb +42 -9
- data/lib/stripe_mock/instance.rb +52 -5
- data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/balance_transactions.rb +2 -2
- data/lib/stripe_mock/request_handlers/charges.rb +13 -12
- data/lib/stripe_mock/request_handlers/checkout.rb +15 -0
- data/lib/stripe_mock/request_handlers/checkout_session.rb +16 -0
- data/lib/stripe_mock/request_handlers/customers.rb +35 -18
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
- data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +14 -10
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +22 -7
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/invoices.rb +11 -5
- data/lib/stripe_mock/request_handlers/payment_intents.rb +182 -0
- data/lib/stripe_mock/request_handlers/payment_methods.rb +120 -0
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/prices.rb +44 -0
- data/lib/stripe_mock/request_handlers/products.rb +44 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +6 -3
- data/lib/stripe_mock/request_handlers/setup_intents.rb +93 -0
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +82 -41
- data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
- data/lib/stripe_mock/request_handlers/tokens.rb +8 -6
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +130 -9
- data/lib/stripe_mock/test_strategies/base.rb +68 -8
- data/lib/stripe_mock/test_strategies/live.rb +23 -12
- data/lib/stripe_mock/test_strategies/mock.rb +6 -2
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/balance.available.json +6 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +166 -38
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +2 -1
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +2 -1
- data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +186 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +164 -0
- data/lib/stripe_mock/webhook_fixtures/product.created.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +38 -0
- data/spec/instance_spec.rb +10 -12
- data/spec/list_spec.rb +38 -0
- data/spec/server_spec.rb +6 -3
- data/spec/shared_stripe_examples/account_examples.rb +1 -1
- data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
- data/spec/shared_stripe_examples/balance_examples.rb +6 -0
- data/spec/shared_stripe_examples/balance_transaction_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_examples.rb +3 -3
- data/spec/shared_stripe_examples/card_examples.rb +4 -4
- data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/charge_examples.rb +32 -36
- data/spec/shared_stripe_examples/checkout_examples.rb +38 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +103 -53
- data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
- data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
- data/spec/shared_stripe_examples/invoice_examples.rb +43 -41
- data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
- data/spec/shared_stripe_examples/payment_intent_examples.rb +147 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +449 -0
- data/spec/shared_stripe_examples/payout_examples.rb +2 -2
- data/spec/shared_stripe_examples/plan_examples.rb +135 -77
- data/spec/shared_stripe_examples/price_examples.rb +183 -0
- data/spec/shared_stripe_examples/product_examples.rb +155 -0
- data/spec/shared_stripe_examples/refund_examples.rb +41 -31
- data/spec/shared_stripe_examples/setup_intent_examples.rb +68 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +546 -295
- data/spec/shared_stripe_examples/subscription_items_examples.rb +76 -0
- data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
- data/spec/shared_stripe_examples/transfer_examples.rb +9 -9
- data/spec/shared_stripe_examples/webhook_event_examples.rb +11 -11
- data/spec/spec_helper.rb +7 -4
- data/spec/stripe_mock_spec.rb +4 -4
- data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
- data/spec/support/stripe_examples.rb +12 -2
- data/stripe-ruby-mock.gemspec +8 -3
- metadata +81 -32
@@ -1,81 +1,73 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
shared_examples 'Plan API' do
|
4
|
+
let(:product) { stripe_helper.create_product }
|
5
|
+
let(:product_id) { product.id }
|
6
|
+
|
7
|
+
let(:plan_attributes) { {
|
8
|
+
:id => "plan_abc123",
|
9
|
+
:product => product_id,
|
10
|
+
:nickname => "My Mock Plan",
|
11
|
+
:amount => 9900,
|
12
|
+
:currency => "usd",
|
13
|
+
:interval => "month"
|
14
|
+
} }
|
15
|
+
let(:plan) { Stripe::Plan.create(plan_attributes) }
|
16
|
+
|
17
|
+
let(:plan_attributes_without_id){ plan_attributes.merge(id: nil) }
|
18
|
+
let(:plan_without_id){ Stripe::Plan.create(plan_attributes_without_id) }
|
19
|
+
|
20
|
+
let(:plan_attributes_with_trial) { plan_attributes.merge(id: "prod_TRIAL", :trial_period_days => 30) }
|
21
|
+
let(:plan_with_trial) { Stripe::Plan.create(plan_attributes_with_trial) }
|
22
|
+
|
23
|
+
let(:metadata) { {:description => "desc text", :info => "info text"} }
|
24
|
+
let(:plan_attributes_with_metadata) { plan_attributes.merge(id: "prod_META", metadata: metadata) }
|
25
|
+
let(:plan_with_metadata) { Stripe::Plan.create(plan_attributes_with_metadata) }
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
product
|
29
|
+
end
|
4
30
|
|
5
31
|
it "creates a stripe plan" do
|
6
|
-
plan
|
7
|
-
|
8
|
-
:name => 'The Mock Plan',
|
9
|
-
:amount => 9900,
|
10
|
-
:currency => 'USD',
|
11
|
-
:interval => 1,
|
12
|
-
:metadata => {
|
13
|
-
:description => "desc text",
|
14
|
-
:info => "info text"
|
15
|
-
},
|
16
|
-
:trial_period_days => 30
|
17
|
-
)
|
18
|
-
|
19
|
-
expect(plan.id).to eq('pid_1')
|
20
|
-
expect(plan.name).to eq('The Mock Plan')
|
32
|
+
expect(plan.id).to eq('plan_abc123')
|
33
|
+
expect(plan.nickname).to eq('My Mock Plan')
|
21
34
|
expect(plan.amount).to eq(9900)
|
22
35
|
|
23
|
-
expect(plan.currency).to eq('
|
24
|
-
expect(plan.interval).to eq(
|
36
|
+
expect(plan.currency).to eq('usd')
|
37
|
+
expect(plan.interval).to eq("month")
|
25
38
|
|
26
|
-
expect(
|
27
|
-
expect(
|
39
|
+
expect(plan_with_metadata.metadata.description).to eq('desc text')
|
40
|
+
expect(plan_with_metadata.metadata.info).to eq('info text')
|
28
41
|
|
29
|
-
expect(
|
42
|
+
expect(plan_with_trial.trial_period_days).to eq(30)
|
30
43
|
end
|
31
44
|
|
32
|
-
|
33
45
|
it "creates a stripe plan without specifying ID" do
|
34
|
-
|
35
|
-
|
36
|
-
:amount => 9900,
|
37
|
-
:currency => 'USD',
|
38
|
-
:interval => 1,
|
39
|
-
)
|
40
|
-
|
41
|
-
expect(plan.id).to match(/^test_plan/)
|
46
|
+
expect(plan_attributes_without_id[:id]).to be_nil
|
47
|
+
expect(plan_without_id.id).to match(/^test_plan_1/)
|
42
48
|
end
|
43
49
|
|
44
50
|
it "stores a created stripe plan in memory" do
|
45
|
-
plan
|
46
|
-
|
47
|
-
|
48
|
-
:amount => 1100,
|
49
|
-
:currency => 'USD',
|
50
|
-
:interval => 1
|
51
|
-
)
|
52
|
-
plan2 = Stripe::Plan.create(
|
53
|
-
:id => 'pid_3',
|
54
|
-
:name => 'The Bonk Plan',
|
55
|
-
:amount => 7777,
|
56
|
-
:currency => 'USD',
|
57
|
-
:interval => 1
|
58
|
-
)
|
51
|
+
plan
|
52
|
+
plan2 = Stripe::Plan.create(plan_attributes.merge(id: "plan_def456", amount: 299))
|
53
|
+
|
59
54
|
data = test_data_source(:plans)
|
60
55
|
expect(data[plan.id]).to_not be_nil
|
61
|
-
expect(data[plan.id][:amount]).to eq(
|
62
|
-
|
56
|
+
expect(data[plan.id][:amount]).to eq(9900)
|
63
57
|
expect(data[plan2.id]).to_not be_nil
|
64
|
-
expect(data[plan2.id][:amount]).to eq(
|
58
|
+
expect(data[plan2.id][:amount]).to eq(299)
|
65
59
|
end
|
66
60
|
|
67
|
-
|
68
61
|
it "retrieves a stripe plan" do
|
69
|
-
original = stripe_helper.create_plan(amount: 1331)
|
62
|
+
original = stripe_helper.create_plan(product: product_id, amount: 1331, id: 'plan_943843')
|
70
63
|
plan = Stripe::Plan.retrieve(original.id)
|
71
64
|
|
72
65
|
expect(plan.id).to eq(original.id)
|
73
66
|
expect(plan.amount).to eq(original.amount)
|
74
67
|
end
|
75
68
|
|
76
|
-
|
77
69
|
it "updates a stripe plan" do
|
78
|
-
stripe_helper.create_plan(id: 'super_member', amount: 111)
|
70
|
+
stripe_helper.create_plan(id: 'super_member', product: product_id, amount: 111)
|
79
71
|
|
80
72
|
plan = Stripe::Plan.retrieve('super_member')
|
81
73
|
expect(plan.amount).to eq(111)
|
@@ -86,7 +78,6 @@ shared_examples 'Plan API' do
|
|
86
78
|
expect(plan.amount).to eq(789)
|
87
79
|
end
|
88
80
|
|
89
|
-
|
90
81
|
it "cannot retrieve a stripe plan that doesn't exist" do
|
91
82
|
expect { Stripe::Plan.retrieve('nope') }.to raise_error {|e|
|
92
83
|
expect(e).to be_a Stripe::InvalidRequestError
|
@@ -96,7 +87,7 @@ shared_examples 'Plan API' do
|
|
96
87
|
end
|
97
88
|
|
98
89
|
it "deletes a stripe plan" do
|
99
|
-
stripe_helper.create_plan(id: 'super_member', amount: 111)
|
90
|
+
stripe_helper.create_plan(id: 'super_member', product: product_id, amount: 111)
|
100
91
|
|
101
92
|
plan = Stripe::Plan.retrieve('super_member')
|
102
93
|
expect(plan).to_not be_nil
|
@@ -111,10 +102,10 @@ shared_examples 'Plan API' do
|
|
111
102
|
end
|
112
103
|
|
113
104
|
it "retrieves all plans" do
|
114
|
-
stripe_helper.create_plan(id: 'Plan One', amount: 54321)
|
115
|
-
stripe_helper.create_plan(id: 'Plan Two', amount: 98765)
|
105
|
+
stripe_helper.create_plan(id: 'Plan One', product: product_id, amount: 54321)
|
106
|
+
stripe_helper.create_plan(id: 'Plan Two', product: product_id, amount: 98765)
|
116
107
|
|
117
|
-
all = Stripe::Plan.
|
108
|
+
all = Stripe::Plan.list
|
118
109
|
expect(all.count).to eq(2)
|
119
110
|
expect(all.map &:id).to include('Plan One', 'Plan Two')
|
120
111
|
expect(all.map &:amount).to include(54321, 98765)
|
@@ -122,30 +113,31 @@ shared_examples 'Plan API' do
|
|
122
113
|
|
123
114
|
it 'retrieves plans with limit' do
|
124
115
|
101.times do | i|
|
125
|
-
stripe_helper.create_plan(id: "Plan #{i}", amount: 11)
|
116
|
+
stripe_helper.create_plan(id: "Plan #{i}", product: product_id, amount: 11)
|
126
117
|
end
|
127
|
-
all = Stripe::Plan.
|
118
|
+
all = Stripe::Plan.list(limit: 100)
|
128
119
|
|
129
120
|
expect(all.count).to eq(100)
|
130
121
|
end
|
131
122
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
:id => 'pid_1',
|
136
|
-
:name => 'The Mock Plan',
|
137
|
-
:amount => 99.99,
|
138
|
-
:currency => 'USD',
|
139
|
-
:interval => 'month'
|
140
|
-
)
|
141
|
-
}.to raise_error(Stripe::InvalidRequestError, "Invalid integer: 99.99")
|
142
|
-
end
|
143
|
-
|
144
|
-
describe "Validation", :live => true do
|
145
|
-
let(:params) { stripe_helper.create_plan_params }
|
123
|
+
describe "Validations", :live => true do
|
124
|
+
include_context "stripe validator"
|
125
|
+
let(:params) { stripe_helper.create_plan_params(product: product_id) }
|
146
126
|
let(:subject) { Stripe::Plan.create(params) }
|
147
127
|
|
148
|
-
describe "
|
128
|
+
describe "Associations" do
|
129
|
+
let(:not_found_product_id){ "prod_NONEXIST" }
|
130
|
+
let(:not_found_message) { stripe_validator.not_found_message(Stripe::Product, not_found_product_id) }
|
131
|
+
let(:params) { stripe_helper.create_plan_params(product: not_found_product_id) }
|
132
|
+
let(:products) { stripe_helper.list_products(100).data }
|
133
|
+
|
134
|
+
it "validates associated product" do
|
135
|
+
expect(products.map(&:id)).to_not include(not_found_product_id)
|
136
|
+
expect { subject }.to raise_error(Stripe::InvalidRequestError, not_found_message)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "Presence" do
|
149
141
|
after do
|
150
142
|
params.delete(@name)
|
151
143
|
message =
|
@@ -157,13 +149,49 @@ shared_examples 'Plan API' do
|
|
157
149
|
expect { subject }.to raise_error(Stripe::InvalidRequestError, message)
|
158
150
|
end
|
159
151
|
|
160
|
-
it("
|
161
|
-
it("
|
162
|
-
it("
|
163
|
-
it("
|
152
|
+
it("validates presence of interval") { @name = :interval }
|
153
|
+
it("validates presence of currency") { @name = :currency }
|
154
|
+
it("validates presence of product") { @name = :product }
|
155
|
+
it("validates presence of amount") { @name = :amount }
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "Inclusion" do
|
159
|
+
let(:invalid_interval) { "OOPS" }
|
160
|
+
let(:invalid_interval_message) { stripe_validator.invalid_plan_interval_message }
|
161
|
+
let(:invalid_interval_params) { params.merge({interval: invalid_interval}) }
|
162
|
+
let(:plan_with_invalid_interval) { Stripe::Plan.create(invalid_interval_params) }
|
163
|
+
|
164
|
+
before(:each) do
|
165
|
+
product
|
166
|
+
end
|
167
|
+
|
168
|
+
it "validates inclusion of interval" do
|
169
|
+
expect { plan_with_invalid_interval }.to raise_error(Stripe::InvalidRequestError, invalid_interval_message)
|
170
|
+
end
|
171
|
+
|
172
|
+
let(:invalid_currency) { "OOPS" }
|
173
|
+
let(:invalid_currency_message) { stripe_validator.invalid_currency_message(invalid_currency) }
|
174
|
+
let(:invalid_currency_params) { params.merge({currency: invalid_currency}) }
|
175
|
+
let(:plan_with_invalid_currency) { Stripe::Plan.create(invalid_currency_params) }
|
176
|
+
|
177
|
+
it "validates inclusion of currency" do
|
178
|
+
expect { plan_with_invalid_currency }.to raise_error(Stripe::InvalidRequestError, invalid_currency_message)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "Numericality" do
|
183
|
+
let(:invalid_integer) { 99.99 }
|
184
|
+
let(:invalid_integer_message) { stripe_validator.invalid_integer_message(invalid_integer)}
|
185
|
+
|
186
|
+
it 'validates amount is an integer' do
|
187
|
+
expect {
|
188
|
+
Stripe::Plan.create( plan_attributes.merge({amount: invalid_integer}) )
|
189
|
+
}.to raise_error(Stripe::InvalidRequestError, invalid_integer_message)
|
190
|
+
end
|
164
191
|
end
|
165
192
|
|
166
193
|
describe "Uniqueness" do
|
194
|
+
let(:already_exists_message) { stripe_validator.already_exists_message(Stripe::Plan) }
|
167
195
|
|
168
196
|
it "validates for uniqueness" do
|
169
197
|
stripe_helper.delete_plan(params[:id])
|
@@ -171,9 +199,39 @@ shared_examples 'Plan API' do
|
|
171
199
|
Stripe::Plan.create(params)
|
172
200
|
expect {
|
173
201
|
Stripe::Plan.create(params)
|
174
|
-
}.to raise_error(Stripe::InvalidRequestError,
|
202
|
+
}.to raise_error(Stripe::InvalidRequestError, already_exists_message)
|
175
203
|
end
|
176
204
|
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "Mock Data" do
|
209
|
+
let(:mock_object) { StripeMock::Data.mock_plan }
|
210
|
+
let(:known_attributes) { [
|
211
|
+
:id,
|
212
|
+
:object,
|
213
|
+
:active,
|
214
|
+
:aggregate_usage,
|
215
|
+
:amount,
|
216
|
+
:billing_scheme,
|
217
|
+
:created,
|
218
|
+
:currency,
|
219
|
+
:interval,
|
220
|
+
:interval_count,
|
221
|
+
:livemode,
|
222
|
+
:metadata,
|
223
|
+
:nickname,
|
224
|
+
:product,
|
225
|
+
:tiers,
|
226
|
+
:tiers_mode,
|
227
|
+
:transform_usage,
|
228
|
+
:trial_period_days,
|
229
|
+
:usage_type
|
230
|
+
] }
|
231
|
+
|
232
|
+
it "includes all retreived attributes" do
|
233
|
+
expect(mock_object.keys).to eql(known_attributes)
|
234
|
+
end
|
177
235
|
end
|
178
236
|
|
179
237
|
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Price API' do
|
4
|
+
let(:product) { stripe_helper.create_product }
|
5
|
+
let(:product_id) { product.id }
|
6
|
+
|
7
|
+
let(:price_attributes) { {
|
8
|
+
:id => "price_abc123",
|
9
|
+
:product => product_id,
|
10
|
+
:nickname => "My Mock price",
|
11
|
+
:amount => 9900,
|
12
|
+
:currency => "usd",
|
13
|
+
:interval => "month"
|
14
|
+
} }
|
15
|
+
let(:price) { Stripe::Price.create(price_attributes) }
|
16
|
+
|
17
|
+
let(:price_attributes_without_id){ price_attributes.merge(id: nil) }
|
18
|
+
let(:price_without_id){ Stripe::Price.create(price_attributes_without_id) }
|
19
|
+
|
20
|
+
let(:price_attributes_with_trial) { price_attributes.merge(id: "prod_TRIAL", :trial_period_days => 30) }
|
21
|
+
let(:price_with_trial) { Stripe::Price.create(price_attributes_with_trial) }
|
22
|
+
|
23
|
+
let(:metadata) { {:description => "desc text", :info => "info text"} }
|
24
|
+
let(:price_attributes_with_metadata) { price_attributes.merge(id: "prod_META", metadata: metadata) }
|
25
|
+
let(:price_with_metadata) { Stripe::Price.create(price_attributes_with_metadata) }
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
product
|
29
|
+
end
|
30
|
+
|
31
|
+
it "creates a stripe price" do
|
32
|
+
expect(price.id).to eq('price_abc123')
|
33
|
+
expect(price.nickname).to eq('My Mock price')
|
34
|
+
expect(price.amount).to eq(9900)
|
35
|
+
|
36
|
+
expect(price.currency).to eq('usd')
|
37
|
+
expect(price.interval).to eq("month")
|
38
|
+
|
39
|
+
expect(price_with_metadata.metadata.description).to eq('desc text')
|
40
|
+
expect(price_with_metadata.metadata.info).to eq('info text')
|
41
|
+
|
42
|
+
expect(price_with_trial.trial_period_days).to eq(30)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "creates a stripe price without specifying ID" do
|
46
|
+
expect(price_attributes_without_id[:id]).to be_nil
|
47
|
+
expect(price_without_id.id).to match(/^test_price_1/)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "stores a created stripe price in memory" do
|
51
|
+
price
|
52
|
+
price2 = Stripe::Price.create(price_attributes.merge(id: "price_def456", amount: 299))
|
53
|
+
|
54
|
+
data = test_data_source(:prices)
|
55
|
+
expect(data[price.id]).to_not be_nil
|
56
|
+
expect(data[price.id][:amount]).to eq(9900)
|
57
|
+
expect(data[price2.id]).to_not be_nil
|
58
|
+
expect(data[price2.id][:amount]).to eq(299)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "retrieves a stripe price" do
|
62
|
+
original = stripe_helper.create_price(product: product_id, amount: 1331, id: 'price_943843')
|
63
|
+
price = Stripe::Price.retrieve(original.id)
|
64
|
+
|
65
|
+
expect(price.id).to eq(original.id)
|
66
|
+
expect(price.amount).to eq(original.amount)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "updates a stripe price" do
|
70
|
+
stripe_helper.create_price(id: 'super_member', product: product_id, amount: 111)
|
71
|
+
|
72
|
+
price = Stripe::Price.retrieve('super_member')
|
73
|
+
expect(price.amount).to eq(111)
|
74
|
+
|
75
|
+
price.amount = 789
|
76
|
+
price.save
|
77
|
+
price = Stripe::Price.retrieve('super_member')
|
78
|
+
expect(price.amount).to eq(789)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "cannot retrieve a stripe price that doesn't exist" do
|
82
|
+
expect { Stripe::Price.retrieve('nope') }.to raise_error {|e|
|
83
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
84
|
+
expect(e.param).to eq('price')
|
85
|
+
expect(e.http_status).to eq(404)
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
it "retrieves all prices" do
|
90
|
+
stripe_helper.create_price(id: 'price One', product: product_id, amount: 54321)
|
91
|
+
stripe_helper.create_price(id: 'price Two', product: product_id, amount: 98765)
|
92
|
+
|
93
|
+
all = Stripe::Price.list
|
94
|
+
expect(all.count).to eq(2)
|
95
|
+
expect(all.map &:id).to include('price One', 'price Two')
|
96
|
+
expect(all.map &:amount).to include(54321, 98765)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'retrieves prices with limit' do
|
100
|
+
101.times do | i|
|
101
|
+
stripe_helper.create_price(id: "price #{i}", product: product_id, amount: 11)
|
102
|
+
end
|
103
|
+
all = Stripe::Price.list(limit: 100)
|
104
|
+
|
105
|
+
expect(all.count).to eq(100)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "retrieves prices with lookup keys" do
|
109
|
+
stripe_helper.create_price(id: 'price One', product: product_id, amount: 54321, lookup_key: 'one')
|
110
|
+
stripe_helper.create_price(id: 'price Two', product: product_id, amount: 98765, lookup_key: 'two')
|
111
|
+
|
112
|
+
all = Stripe::Price.list({lookup_keys: ['one', 'two']})
|
113
|
+
expect(all.count).to eq(2)
|
114
|
+
expect(all.map &:id).to include('price One', 'price Two')
|
115
|
+
expect(all.map &:amount).to include(54321, 98765)
|
116
|
+
|
117
|
+
one = Stripe::Price.list({lookup_keys: ['one']})
|
118
|
+
expect(one.count).to eq(1)
|
119
|
+
expect(one.map &:id).to include('price One')
|
120
|
+
expect(one.map &:amount).to include(54321)
|
121
|
+
|
122
|
+
two = Stripe::Price.list({lookup_keys: ['two']})
|
123
|
+
expect(two.count).to eq(1)
|
124
|
+
expect(two.map &:id).to include('price Two')
|
125
|
+
expect(two.map &:amount).to include(98765)
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "Validations", :live => true do
|
129
|
+
include_context "stripe validator"
|
130
|
+
let(:params) { stripe_helper.create_price_params(product: product_id) }
|
131
|
+
let(:subject) { Stripe::Price.create(params) }
|
132
|
+
|
133
|
+
describe "Associations" do
|
134
|
+
let(:not_found_product_id){ "prod_NONEXIST" }
|
135
|
+
let(:not_found_message) { stripe_validator.not_found_message(Stripe::Product, not_found_product_id) }
|
136
|
+
let(:params) { stripe_helper.create_price_params(product: not_found_product_id) }
|
137
|
+
let(:products) { stripe_helper.list_products(100).data }
|
138
|
+
|
139
|
+
it "validates associated product" do
|
140
|
+
expect(products.map(&:id)).to_not include(not_found_product_id)
|
141
|
+
expect { subject }.to raise_error(Stripe::InvalidRequestError, not_found_message)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "Presence" do
|
146
|
+
after do
|
147
|
+
params.delete(@name)
|
148
|
+
message = "Missing required param: #{@name}."
|
149
|
+
expect { subject }.to raise_error(Stripe::InvalidRequestError, message)
|
150
|
+
end
|
151
|
+
|
152
|
+
it("validates presence of currency") { @name = :currency }
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "Mock Data" do
|
157
|
+
let(:mock_object) { StripeMock::Data.mock_price }
|
158
|
+
let(:known_attributes) { [
|
159
|
+
:id,
|
160
|
+
:object,
|
161
|
+
:active,
|
162
|
+
:billing_scheme,
|
163
|
+
:created,
|
164
|
+
:currency,
|
165
|
+
:livemode,
|
166
|
+
:lookup_key,
|
167
|
+
:metadata,
|
168
|
+
:nickname,
|
169
|
+
:product,
|
170
|
+
:recurring,
|
171
|
+
:tiers_mode,
|
172
|
+
:transform_quantity,
|
173
|
+
:type,
|
174
|
+
:unit_amount,
|
175
|
+
:unit_amount_decimal
|
176
|
+
] }
|
177
|
+
|
178
|
+
it "includes all retreived attributes" do
|
179
|
+
expect(mock_object.keys).to eql(known_attributes)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|