stripe-ruby-mock 2.5.6 → 3.1.0.rc2

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 (97) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/.travis.yml +6 -9
  4. data/CHANGELOG.md +35 -0
  5. data/Gemfile +1 -0
  6. data/README.md +17 -11
  7. data/lib/stripe_mock.rb +11 -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 +7 -0
  12. data/lib/stripe_mock/client.rb +2 -1
  13. data/lib/stripe_mock/data.rb +323 -13
  14. data/lib/stripe_mock/data/list.rb +42 -9
  15. data/lib/stripe_mock/instance.rb +52 -5
  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 +13 -12
  19. data/lib/stripe_mock/request_handlers/checkout.rb +15 -0
  20. data/lib/stripe_mock/request_handlers/checkout_session.rb +16 -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 +14 -10
  25. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +22 -7
  26. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
  27. data/lib/stripe_mock/request_handlers/invoices.rb +11 -5
  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 +44 -0
  33. data/lib/stripe_mock/request_handlers/refunds.rb +6 -3
  34. data/lib/stripe_mock/request_handlers/setup_intents.rb +93 -0
  35. data/lib/stripe_mock/request_handlers/sources.rb +12 -6
  36. data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
  37. data/lib/stripe_mock/request_handlers/subscriptions.rb +82 -41
  38. data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
  39. data/lib/stripe_mock/request_handlers/tokens.rb +8 -6
  40. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +130 -9
  41. data/lib/stripe_mock/test_strategies/base.rb +68 -8
  42. data/lib/stripe_mock/test_strategies/live.rb +23 -12
  43. data/lib/stripe_mock/test_strategies/mock.rb +6 -2
  44. data/lib/stripe_mock/version.rb +1 -1
  45. data/lib/stripe_mock/webhook_fixtures/balance.available.json +6 -0
  46. data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
  47. data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
  48. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +166 -38
  49. data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
  50. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
  51. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +2 -1
  52. data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +1 -1
  53. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +2 -1
  54. data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +186 -0
  55. data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +164 -0
  56. data/lib/stripe_mock/webhook_fixtures/product.created.json +34 -0
  57. data/lib/stripe_mock/webhook_fixtures/product.deleted.json +34 -0
  58. data/lib/stripe_mock/webhook_fixtures/product.updated.json +38 -0
  59. data/spec/instance_spec.rb +10 -12
  60. data/spec/list_spec.rb +38 -0
  61. data/spec/server_spec.rb +6 -3
  62. data/spec/shared_stripe_examples/account_examples.rb +1 -1
  63. data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
  64. data/spec/shared_stripe_examples/balance_examples.rb +6 -0
  65. data/spec/shared_stripe_examples/balance_transaction_examples.rb +3 -3
  66. data/spec/shared_stripe_examples/bank_examples.rb +3 -3
  67. data/spec/shared_stripe_examples/card_examples.rb +4 -4
  68. data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
  69. data/spec/shared_stripe_examples/charge_examples.rb +32 -36
  70. data/spec/shared_stripe_examples/checkout_examples.rb +38 -0
  71. data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
  72. data/spec/shared_stripe_examples/customer_examples.rb +103 -53
  73. data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
  74. data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
  75. data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
  76. data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
  77. data/spec/shared_stripe_examples/invoice_examples.rb +43 -41
  78. data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
  79. data/spec/shared_stripe_examples/payment_intent_examples.rb +147 -0
  80. data/spec/shared_stripe_examples/payment_method_examples.rb +449 -0
  81. data/spec/shared_stripe_examples/payout_examples.rb +2 -2
  82. data/spec/shared_stripe_examples/plan_examples.rb +135 -77
  83. data/spec/shared_stripe_examples/price_examples.rb +183 -0
  84. data/spec/shared_stripe_examples/product_examples.rb +155 -0
  85. data/spec/shared_stripe_examples/refund_examples.rb +41 -31
  86. data/spec/shared_stripe_examples/setup_intent_examples.rb +68 -0
  87. data/spec/shared_stripe_examples/subscription_examples.rb +546 -295
  88. data/spec/shared_stripe_examples/subscription_items_examples.rb +76 -0
  89. data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
  90. data/spec/shared_stripe_examples/transfer_examples.rb +9 -9
  91. data/spec/shared_stripe_examples/webhook_event_examples.rb +11 -11
  92. data/spec/spec_helper.rb +7 -4
  93. data/spec/stripe_mock_spec.rb +4 -4
  94. data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
  95. data/spec/support/stripe_examples.rb +12 -2
  96. data/stripe-ruby-mock.gemspec +8 -3
  97. 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 = Stripe::Plan.create(
7
- :id => 'pid_1',
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('USD')
24
- expect(plan.interval).to eq(1)
36
+ expect(plan.currency).to eq('usd')
37
+ expect(plan.interval).to eq("month")
25
38
 
26
- expect(plan.metadata.description).to eq('desc text')
27
- 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')
28
41
 
29
- expect(plan.trial_period_days).to eq(30)
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
- plan = Stripe::Plan.create(
35
- :name => 'The Mock Plan',
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 = Stripe::Plan.create(
46
- :id => 'pid_2',
47
- :name => 'The Memory Plan',
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(1100)
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(7777)
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.all
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.all(limit: 100)
118
+ all = Stripe::Plan.list(limit: 100)
128
119
 
129
120
  expect(all.count).to eq(100)
130
121
  end
131
122
 
132
- it 'validates the amount' do
133
- expect {
134
- Stripe::Plan.create(
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 "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
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("requires a name") { @name = :name }
161
- it("requires an amount") { @name = :amount }
162
- it("requires a currency") { @name = :currency }
163
- 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
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, "Plan already exists.")
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