stripe-ruby-mock 2.5.8 → 3.1.0.rc3

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.
Files changed (90) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/.travis.yml +6 -9
  4. data/CHANGELOG.md +41 -0
  5. data/Gemfile +1 -0
  6. data/README.md +17 -11
  7. data/lib/stripe_mock.rb +8 -0
  8. data/lib/stripe_mock/api/client.rb +1 -1
  9. data/lib/stripe_mock/api/errors.rb +34 -28
  10. data/lib/stripe_mock/api/instance.rb +1 -1
  11. data/lib/stripe_mock/api/webhooks.rb +5 -0
  12. data/lib/stripe_mock/client.rb +2 -1
  13. data/lib/stripe_mock/data.rb +285 -16
  14. data/lib/stripe_mock/data/list.rb +42 -9
  15. data/lib/stripe_mock/instance.rb +18 -4
  16. data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
  17. data/lib/stripe_mock/request_handlers/balance_transactions.rb +2 -2
  18. data/lib/stripe_mock/request_handlers/charges.rb +6 -4
  19. data/lib/stripe_mock/request_handlers/checkout.rb +15 -0
  20. data/lib/stripe_mock/request_handlers/checkout_session.rb +22 -0
  21. data/lib/stripe_mock/request_handlers/customers.rb +35 -18
  22. data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
  23. data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
  24. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +5 -0
  25. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +12 -7
  26. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
  27. data/lib/stripe_mock/request_handlers/invoices.rb +10 -4
  28. data/lib/stripe_mock/request_handlers/payment_intents.rb +182 -0
  29. data/lib/stripe_mock/request_handlers/payment_methods.rb +120 -0
  30. data/lib/stripe_mock/request_handlers/plans.rb +1 -1
  31. data/lib/stripe_mock/request_handlers/prices.rb +44 -0
  32. data/lib/stripe_mock/request_handlers/products.rb +1 -0
  33. data/lib/stripe_mock/request_handlers/setup_intents.rb +93 -0
  34. data/lib/stripe_mock/request_handlers/sources.rb +12 -6
  35. data/lib/stripe_mock/request_handlers/subscriptions.rb +45 -22
  36. data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
  37. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +123 -9
  38. data/lib/stripe_mock/server.rb +2 -2
  39. data/lib/stripe_mock/test_strategies/base.rb +67 -8
  40. data/lib/stripe_mock/test_strategies/live.rb +23 -12
  41. data/lib/stripe_mock/test_strategies/mock.rb +6 -2
  42. data/lib/stripe_mock/version.rb +1 -1
  43. data/lib/stripe_mock/webhook_fixtures/balance.available.json +6 -0
  44. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +166 -38
  45. data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
  46. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
  47. data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +186 -0
  48. data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +164 -0
  49. data/lib/stripe_mock/webhook_fixtures/product.created.json +34 -0
  50. data/lib/stripe_mock/webhook_fixtures/product.deleted.json +34 -0
  51. data/lib/stripe_mock/webhook_fixtures/product.updated.json +38 -0
  52. data/spec/instance_spec.rb +10 -12
  53. data/spec/list_spec.rb +38 -0
  54. data/spec/server_spec.rb +6 -3
  55. data/spec/shared_stripe_examples/account_examples.rb +1 -1
  56. data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
  57. data/spec/shared_stripe_examples/balance_examples.rb +6 -0
  58. data/spec/shared_stripe_examples/balance_transaction_examples.rb +3 -3
  59. data/spec/shared_stripe_examples/bank_examples.rb +3 -3
  60. data/spec/shared_stripe_examples/card_examples.rb +4 -4
  61. data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
  62. data/spec/shared_stripe_examples/charge_examples.rb +9 -22
  63. data/spec/shared_stripe_examples/checkout_examples.rb +47 -0
  64. data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
  65. data/spec/shared_stripe_examples/customer_examples.rb +93 -53
  66. data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
  67. data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
  68. data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
  69. data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
  70. data/spec/shared_stripe_examples/invoice_examples.rb +41 -39
  71. data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
  72. data/spec/shared_stripe_examples/payment_intent_examples.rb +147 -0
  73. data/spec/shared_stripe_examples/payment_method_examples.rb +449 -0
  74. data/spec/shared_stripe_examples/payout_examples.rb +2 -2
  75. data/spec/shared_stripe_examples/plan_examples.rb +135 -92
  76. data/spec/shared_stripe_examples/price_examples.rb +183 -0
  77. data/spec/shared_stripe_examples/product_examples.rb +147 -0
  78. data/spec/shared_stripe_examples/refund_examples.rb +25 -21
  79. data/spec/shared_stripe_examples/setup_intent_examples.rb +68 -0
  80. data/spec/shared_stripe_examples/subscription_examples.rb +430 -318
  81. data/spec/shared_stripe_examples/subscription_items_examples.rb +3 -2
  82. data/spec/shared_stripe_examples/transfer_examples.rb +6 -6
  83. data/spec/shared_stripe_examples/webhook_event_examples.rb +11 -11
  84. data/spec/spec_helper.rb +7 -4
  85. data/spec/stripe_mock_spec.rb +4 -4
  86. data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
  87. data/spec/support/stripe_examples.rb +9 -1
  88. data/stripe-ruby-mock.gemspec +8 -3
  89. metadata +72 -34
  90. data/spec/shared_stripe_examples/product_example.rb +0 -65
@@ -1,93 +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 = Stripe::Plan.create(
7
- :id => 'pid_1',
8
- :name => 'The Mock Plan',
9
- :amount => 9900,
10
- :currency => 'USD',
11
- :interval => 1,
12
- :product => {
13
- :name => 'A product'
14
- },
15
- :metadata => {
16
- :description => "desc text",
17
- :info => "info text"
18
- },
19
- :trial_period_days => 30
20
- )
21
-
22
- expect(plan.id).to eq('pid_1')
23
- 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')
24
34
  expect(plan.amount).to eq(9900)
25
35
 
26
- expect(plan.currency).to eq('USD')
27
- expect(plan.interval).to eq(1)
36
+ expect(plan.currency).to eq('usd')
37
+ expect(plan.interval).to eq("month")
28
38
 
29
- expect(plan.metadata.description).to eq('desc text')
30
- expect(plan.metadata.info).to eq('info text')
39
+ expect(plan_with_metadata.metadata.description).to eq('desc text')
40
+ expect(plan_with_metadata.metadata.info).to eq('info text')
31
41
 
32
- expect(plan.trial_period_days).to eq(30)
42
+ expect(plan_with_trial.trial_period_days).to eq(30)
33
43
  end
34
44
 
35
-
36
45
  it "creates a stripe plan without specifying ID" do
37
- plan = Stripe::Plan.create(
38
- :name => 'The Mock Plan',
39
- :amount => 9900,
40
- :currency => 'USD',
41
- :interval => 1,
42
- :product => {
43
- :name => 'A product'
44
- }
45
- )
46
-
47
- 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/)
48
48
  end
49
49
 
50
50
  it "stores a created stripe plan in memory" do
51
- plan = Stripe::Plan.create(
52
- :id => 'pid_2',
53
- :name => 'The Memory Plan',
54
- :amount => 1100,
55
- :currency => 'USD',
56
- :interval => 1,
57
- :product => {
58
- :name => 'A product'
59
- }
60
- )
61
- plan2 = Stripe::Plan.create(
62
- :id => 'pid_3',
63
- :name => 'The Bonk Plan',
64
- :amount => 7777,
65
- :currency => 'USD',
66
- :interval => 1,
67
- :product => {
68
- :name => 'A product'
69
- }
70
- )
51
+ plan
52
+ plan2 = Stripe::Plan.create(plan_attributes.merge(id: "plan_def456", amount: 299))
53
+
71
54
  data = test_data_source(:plans)
72
55
  expect(data[plan.id]).to_not be_nil
73
- expect(data[plan.id][:amount]).to eq(1100)
74
-
56
+ expect(data[plan.id][:amount]).to eq(9900)
75
57
  expect(data[plan2.id]).to_not be_nil
76
- expect(data[plan2.id][:amount]).to eq(7777)
58
+ expect(data[plan2.id][:amount]).to eq(299)
77
59
  end
78
60
 
79
-
80
61
  it "retrieves a stripe plan" do
81
- original = stripe_helper.create_plan(amount: 1331)
62
+ original = stripe_helper.create_plan(product: product_id, amount: 1331, id: 'plan_943843')
82
63
  plan = Stripe::Plan.retrieve(original.id)
83
64
 
84
65
  expect(plan.id).to eq(original.id)
85
66
  expect(plan.amount).to eq(original.amount)
86
67
  end
87
68
 
88
-
89
69
  it "updates a stripe plan" do
90
- stripe_helper.create_plan(id: 'super_member', amount: 111)
70
+ stripe_helper.create_plan(id: 'super_member', product: product_id, amount: 111)
91
71
 
92
72
  plan = Stripe::Plan.retrieve('super_member')
93
73
  expect(plan.amount).to eq(111)
@@ -98,7 +78,6 @@ shared_examples 'Plan API' do
98
78
  expect(plan.amount).to eq(789)
99
79
  end
100
80
 
101
-
102
81
  it "cannot retrieve a stripe plan that doesn't exist" do
103
82
  expect { Stripe::Plan.retrieve('nope') }.to raise_error {|e|
104
83
  expect(e).to be_a Stripe::InvalidRequestError
@@ -108,7 +87,7 @@ shared_examples 'Plan API' do
108
87
  end
109
88
 
110
89
  it "deletes a stripe plan" do
111
- stripe_helper.create_plan(id: 'super_member', amount: 111)
90
+ stripe_helper.create_plan(id: 'super_member', product: product_id, amount: 111)
112
91
 
113
92
  plan = Stripe::Plan.retrieve('super_member')
114
93
  expect(plan).to_not be_nil
@@ -123,10 +102,10 @@ shared_examples 'Plan API' do
123
102
  end
124
103
 
125
104
  it "retrieves all plans" do
126
- stripe_helper.create_plan(id: 'Plan One', amount: 54321)
127
- 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)
128
107
 
129
- all = Stripe::Plan.all
108
+ all = Stripe::Plan.list
130
109
  expect(all.count).to eq(2)
131
110
  expect(all.map &:id).to include('Plan One', 'Plan Two')
132
111
  expect(all.map &:amount).to include(54321, 98765)
@@ -134,33 +113,31 @@ shared_examples 'Plan API' do
134
113
 
135
114
  it 'retrieves plans with limit' do
136
115
  101.times do | i|
137
- stripe_helper.create_plan(id: "Plan #{i}", amount: 11)
116
+ stripe_helper.create_plan(id: "Plan #{i}", product: product_id, amount: 11)
138
117
  end
139
- all = Stripe::Plan.all(limit: 100)
118
+ all = Stripe::Plan.list(limit: 100)
140
119
 
141
120
  expect(all.count).to eq(100)
142
121
  end
143
122
 
144
- it 'validates the amount' do
145
- expect {
146
- Stripe::Plan.create(
147
- :id => 'pid_1',
148
- :name => 'The Mock Plan',
149
- :amount => 99.99,
150
- :currency => 'USD',
151
- :interval => 'month',
152
- :product => {
153
- :name => 'A product'
154
- }
155
- )
156
- }.to raise_error(Stripe::InvalidRequestError, "Invalid integer: 99.99")
157
- end
158
-
159
- describe "Validation", :live => true do
160
- 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) }
161
126
  let(:subject) { Stripe::Plan.create(params) }
162
127
 
163
- describe "Required Parameters" do
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
164
141
  after do
165
142
  params.delete(@name)
166
143
  message =
@@ -172,13 +149,49 @@ shared_examples 'Plan API' do
172
149
  expect { subject }.to raise_error(Stripe::InvalidRequestError, message)
173
150
  end
174
151
 
175
- it("requires a product") { @name = :product }
176
- it("requires an amount") { @name = :amount }
177
- it("requires a currency") { @name = :currency }
178
- it("requires an interval") { @name = :interval }
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
179
191
  end
180
192
 
181
193
  describe "Uniqueness" do
194
+ let(:already_exists_message) { stripe_validator.already_exists_message(Stripe::Plan) }
182
195
 
183
196
  it "validates for uniqueness" do
184
197
  stripe_helper.delete_plan(params[:id])
@@ -186,9 +199,39 @@ shared_examples 'Plan API' do
186
199
  Stripe::Plan.create(params)
187
200
  expect {
188
201
  Stripe::Plan.create(params)
189
- }.to raise_error(Stripe::InvalidRequestError, "Plan already exists.")
202
+ }.to raise_error(Stripe::InvalidRequestError, already_exists_message)
190
203
  end
191
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
192
235
  end
193
236
 
194
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