stripe-ruby-mock 2.5.7 → 2.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c1a6cfda90439e30a5198b5e83135070138179b
4
- data.tar.gz: d1a78b4802fe6b7d37c11b104eec9a0c08f06b40
3
+ metadata.gz: a15c09639e0a93df5b15cc5a45646c0fb189460e
4
+ data.tar.gz: b8cdf0692aba8099229f66e1906e691dd40075aa
5
5
  SHA512:
6
- metadata.gz: 9bd40fd514426cb1a58c52bd2b1c3841bff41a5c8a2a73e8a3dbfb43fc98422b3c51f8b7761e7e7f2a010afd0bb260db5778e2796dd501ce0c28d63e53dca783
7
- data.tar.gz: bedeb87ade1eeba6a46e9573628187bb66f1bd886233cf21f60383668350f95a9562b53f16f4d7068169393782e54d62e5f9ea680ea8b7a6849c2fe225ace4ea
6
+ metadata.gz: 9d70a5de8ae26c090632d00c1013d5ca63933fee41e40561b2e713b511a1c1347b21485b1d1c4eb8ee6837b6f4ec9a9f8e857a7bfa0785ac2182b8190180bfbb
7
+ data.tar.gz: 542f7a6f6c8743269e0337c1fc0b4fabef97003fe4d945c077ab4e16fe908bf7c21996dcb8c25ade7a4975a273a51972621d8d997e35a86f00dcb5287ae63d89
data/README.md CHANGED
@@ -12,7 +12,7 @@ This gem has unexpectedly grown in popularity and I've gotten pretty busy, so I'
12
12
 
13
13
  In your gemfile:
14
14
 
15
- gem 'stripe-ruby-mock', '~> 2.5.7', :require => 'stripe_mock'
15
+ gem 'stripe-ruby-mock', '~> 2.5.8', :require => 'stripe_mock'
16
16
 
17
17
  ## Features
18
18
 
@@ -67,10 +67,12 @@ require 'stripe_mock/request_handlers/refunds.rb'
67
67
  require 'stripe_mock/request_handlers/transfers.rb'
68
68
  require 'stripe_mock/request_handlers/payouts.rb'
69
69
  require 'stripe_mock/request_handlers/subscriptions.rb'
70
+ require 'stripe_mock/request_handlers/subscription_items.rb'
70
71
  require 'stripe_mock/request_handlers/tokens.rb'
71
72
  require 'stripe_mock/request_handlers/country_spec.rb'
72
73
  require 'stripe_mock/request_handlers/ephemeral_key.rb'
73
74
  require 'stripe_mock/request_handlers/products.rb'
75
+ require 'stripe_mock/request_handlers/tax_rates.rb'
74
76
  require 'stripe_mock/instance'
75
77
 
76
78
  require 'stripe_mock/test_strategies/base.rb'
@@ -50,6 +50,8 @@ module StripeMock
50
50
  'charge.dispute.created',
51
51
  'charge.dispute.updated',
52
52
  'charge.dispute.closed',
53
+ 'charge.dispute.funds_reinstated',
54
+ 'charge.dispute.funds_withdrawn',
53
55
  'customer.source.created',
54
56
  'customer.source.deleted',
55
57
  'customer.source.updated',
@@ -101,6 +101,22 @@ module StripeMock
101
101
  }.merge(params)
102
102
  end
103
103
 
104
+ def self.mock_tax_rate(params)
105
+ {
106
+ id: 'test_cus_default',
107
+ object: 'tax_rate',
108
+ active: true,
109
+ created: 1559079603,
110
+ description: nil,
111
+ display_name: 'VAT',
112
+ inclusive: false,
113
+ jurisdiction: 'EU',
114
+ livemode: false,
115
+ metadata: {},
116
+ percentage: 21.0
117
+ }.merge(params)
118
+ end
119
+
104
120
  def self.mock_customer(sources, params)
105
121
  cus_id = params[:id] || "test_cus_default"
106
122
  currency = params[:currency] || StripeMock.default_currency
@@ -111,6 +127,7 @@ module StripeMock
111
127
  object: "customer",
112
128
  created: 1372126710,
113
129
  id: cus_id,
130
+ name: nil,
114
131
  livemode: false,
115
132
  delinquent: false,
116
133
  discount: nil,
@@ -335,6 +352,9 @@ module StripeMock
335
352
  lines << Data.mock_line_item() if lines.empty?
336
353
  invoice = {
337
354
  id: 'in_test_invoice',
355
+ status: 'open',
356
+ invoice_pdf: 'pdf_url',
357
+ hosted_invoice_url: 'hosted_invoice_url',
338
358
  created: 1349738950,
339
359
  period_end: 1349738950,
340
360
  period_start: 1349738950,
@@ -356,12 +376,13 @@ module StripeMock
356
376
  paid: false,
357
377
  receipt_number: nil,
358
378
  statement_descriptor: nil,
359
- tax: nil,
379
+ tax: 10,
360
380
  tax_percent: nil,
361
381
  webhooks_delivered_at: 1349825350,
362
382
  livemode: false,
363
383
  attempt_count: 0,
364
- amount_due: nil,
384
+ amount_due: 100,
385
+ amount_paid: 0,
365
386
  currency: currency,
366
387
  starting_balance: 0,
367
388
  ending_balance: nil,
@@ -396,6 +417,11 @@ module StripeMock
396
417
  start: 1349738920,
397
418
  end: 1349738920
398
419
  },
420
+ tax_amounts: [
421
+ {
422
+ amount: 10
423
+ }
424
+ ],
399
425
  quantity: nil,
400
426
  subscription: nil,
401
427
  plan: nil,
@@ -28,6 +28,7 @@ module StripeMock
28
28
  include StripeMock::RequestHandlers::Cards
29
29
  include StripeMock::RequestHandlers::Sources
30
30
  include StripeMock::RequestHandlers::Subscriptions # must be before Customers
31
+ include StripeMock::RequestHandlers::SubscriptionItems
31
32
  include StripeMock::RequestHandlers::Customers
32
33
  include StripeMock::RequestHandlers::Coupons
33
34
  include StripeMock::RequestHandlers::Disputes
@@ -44,11 +45,12 @@ module StripeMock
44
45
  include StripeMock::RequestHandlers::CountrySpec
45
46
  include StripeMock::RequestHandlers::Payouts
46
47
  include StripeMock::RequestHandlers::EphemeralKey
48
+ include StripeMock::RequestHandlers::TaxRates
47
49
 
48
50
  attr_reader :accounts, :balance, :balance_transactions, :bank_tokens, :charges, :coupons, :customers,
49
51
  :disputes, :events, :invoices, :invoice_items, :orders, :plans, :recipients,
50
52
  :refunds, :transfers, :payouts, :subscriptions, :country_spec, :subscriptions_items,
51
- :products
53
+ :products, :tax_rates
52
54
 
53
55
  attr_accessor :error_queue, :debug, :conversion_rate, :account_balance
54
56
 
@@ -73,8 +75,9 @@ module StripeMock
73
75
  @transfers = {}
74
76
  @payouts = {}
75
77
  @subscriptions = {}
76
- @subscriptions_items = []
78
+ @subscriptions_items = {}
77
79
  @country_spec = {}
80
+ @tax_rates = {}
78
81
 
79
82
  @debug = false
80
83
  @error_queue = ErrorQueue.new
@@ -158,10 +158,6 @@ module StripeMock
158
158
  params[:amount] && params[:amount] < 1
159
159
  end
160
160
 
161
- def require_param(param)
162
- raise Stripe::InvalidRequestError.new("Missing required param: #{param}", param.to_s, http_status: 400)
163
- end
164
-
165
161
  def allowed_params(params)
166
162
  allowed = [:description, :metadata, :receipt_email, :fraud_details, :shipping, :destination]
167
163
 
@@ -8,10 +8,12 @@ module StripeMock
8
8
 
9
9
  def resolve_subscription_changes(subscription, plans, customer, options = {})
10
10
  subscription.merge!(custom_subscription_params(plans, customer, options))
11
+ items = options[:items]
12
+ items = items.values if items.respond_to?(:values)
11
13
  subscription[:items][:data] = plans.map do |plan|
12
- if options[:items] && options[:items].size == plans.size
13
- quantity = options[:items] &&
14
- options[:items].detect { |item| item[:plan] == plan[:id] }[:quantity] || 1
14
+ if items && items.size == plans.size
15
+ quantity = items &&
16
+ items.detect { |item| item[:plan] == plan[:id] }[:quantity] || 1
15
17
  Data.mock_subscription_item({ plan: plan, quantity: quantity })
16
18
  else
17
19
  Data.mock_subscription_item({ plan: plan })
@@ -0,0 +1,36 @@
1
+ module StripeMock
2
+ module RequestHandlers
3
+ module SubscriptionItems
4
+
5
+ def SubscriptionItems.included(klass)
6
+ klass.add_handler 'get /v1/subscription_items', :retrieve_subscription_items
7
+ klass.add_handler 'post /v1/subscription_items/([^/]*)', :update_subscription_item
8
+ klass.add_handler 'post /v1/subscription_items', :create_subscription_items
9
+ end
10
+
11
+ def retrieve_subscription_items(route, method_url, params, headers)
12
+ route =~ method_url
13
+
14
+ require_param(:subscription) unless params[:subscription]
15
+
16
+ Data.mock_list_object(subscriptions_items, params)
17
+ end
18
+
19
+ def create_subscription_items(route, method_url, params, headers)
20
+ params[:id] ||= new_id('si')
21
+
22
+ require_param(:subscription) unless params[:subscription]
23
+ require_param(:plan) unless params[:plan]
24
+
25
+ subscriptions_items[params[:id]] = Data.mock_subscription_item(params.merge(plan: plans[params[:plan]]))
26
+ end
27
+
28
+ def update_subscription_item(route, method_url, params, headers)
29
+ route =~ method_url
30
+
31
+ subscription_item = assert_existence :subscription_item, $1, subscriptions_items[$1]
32
+ subscription_item.merge!(params.merge(plan: plans[params[:plan]]))
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ module StripeMock
2
+ module RequestHandlers
3
+ module TaxRates
4
+ def TaxRates.included(klass)
5
+ klass.add_handler 'post /v1/tax_rates', :new_tax_rate
6
+ klass.add_handler 'post /v1/tax_rates/([^/]*)', :update_tax_rate
7
+ klass.add_handler 'get /v1/tax_rates/([^/]*)', :get_tax_rate
8
+ klass.add_handler 'get /v1/tax_rates', :list_tax_rates
9
+ end
10
+
11
+ def update_tax_rate(route, method_url, params, headers)
12
+ route =~ method_url
13
+ rate = assert_existence :tax_rate, $1, tax_rates[$1]
14
+ rate.merge!(params)
15
+ rate
16
+ end
17
+
18
+ def new_tax_rate(route, method_url, params, headers)
19
+ params[:id] ||= new_id('txr')
20
+ tax_rates[ params[:id] ] = Data.mock_tax_rate(params)
21
+ tax_rates[ params[:id] ]
22
+ end
23
+
24
+ def list_tax_rates(route, method_url, params, headers)
25
+ Data.mock_list_object(tax_rates.values, params)
26
+ end
27
+
28
+ def get_tax_rate(route, method_url, params, headers)
29
+ route =~ method_url
30
+ tax_rate = assert_existence :tax_rate, $1, tax_rates[$1]
31
+ tax_rate.clone
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -24,6 +24,9 @@ module StripeMock
24
24
  end
25
25
  end
26
26
 
27
+ def require_param(param_name)
28
+ raise Stripe::InvalidRequestError.new("Missing required param: #{param_name}.", param_name.to_s, http_status: 400)
29
+ end
27
30
  end
28
31
  end
29
32
  end
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "2.5.7"
3
+ VERSION = "2.5.8"
4
4
  end
@@ -0,0 +1,88 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "charge.dispute.funds_reinstated",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2017-12-14",
10
+ "data": {
11
+ "object": {
12
+ "id": "dp_00000000000000",
13
+ "object": "dispute",
14
+ "amount": 25000,
15
+ "balance_transaction": "txn_00000000000000",
16
+ "balance_transactions": [
17
+ {
18
+ "id": "txn_1Bl3mMGWCopOTFn18p8iALq8",
19
+ "object": "balance_transaction",
20
+ "amount": -25000,
21
+ "available_on": 1516233600,
22
+ "created": 1516145022,
23
+ "currency": "usd",
24
+ "description": "Chargeback withdrawal for ch_1Bl3mKGWCopOTFn1LKoN557r",
25
+ "exchange_rate": null,
26
+ "fee": 1500,
27
+ "fee_details": [
28
+ {
29
+ "amount": 1500,
30
+ "application": null,
31
+ "currency": "usd",
32
+ "description": "Dispute fee",
33
+ "type": "stripe_fee"
34
+ }
35
+ ],
36
+ "net": -26500,
37
+ "source": "dp_1Bl3mMGWCopOTFn1jpVaJDrU",
38
+ "status": "pending",
39
+ "type": "adjustment"
40
+ }
41
+ ],
42
+ "charge": "ch_00000000000000",
43
+ "created": 1516145022,
44
+ "currency": "usd",
45
+ "evidence": {
46
+ "access_activity_log": null,
47
+ "billing_address": null,
48
+ "cancellation_policy": null,
49
+ "cancellation_policy_disclosure": null,
50
+ "cancellation_rebuttal": null,
51
+ "customer_communication": null,
52
+ "customer_email_address": "amitree.apu@gmail.com",
53
+ "customer_name": "amitree.apu@gmail.com",
54
+ "customer_purchase_ip": "157.131.133.10",
55
+ "customer_signature": null,
56
+ "duplicate_charge_documentation": null,
57
+ "duplicate_charge_explanation": null,
58
+ "duplicate_charge_id": null,
59
+ "product_description": null,
60
+ "receipt": null,
61
+ "refund_policy": null,
62
+ "refund_policy_disclosure": null,
63
+ "refund_refusal_explanation": null,
64
+ "service_date": null,
65
+ "service_documentation": null,
66
+ "shipping_address": null,
67
+ "shipping_carrier": null,
68
+ "shipping_date": null,
69
+ "shipping_documentation": null,
70
+ "shipping_tracking_number": null,
71
+ "uncategorized_file": null,
72
+ "uncategorized_text": null
73
+ },
74
+ "evidence_details": {
75
+ "due_by": 1517529599,
76
+ "has_evidence": false,
77
+ "past_due": false,
78
+ "submission_count": 0
79
+ },
80
+ "is_charge_refundable": false,
81
+ "livemode": false,
82
+ "metadata": {
83
+ },
84
+ "reason": "fraudulent",
85
+ "status": "needs_response"
86
+ }
87
+ }
88
+ }
@@ -0,0 +1,88 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "charge.dispute.funds_withdrawn",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2017-12-14",
10
+ "data": {
11
+ "object": {
12
+ "id": "dp_00000000000000",
13
+ "object": "dispute",
14
+ "amount": 25000,
15
+ "balance_transaction": "txn_00000000000000",
16
+ "balance_transactions": [
17
+ {
18
+ "id": "txn_1Bl3mMGWCopOTFn18p8iALq8",
19
+ "object": "balance_transaction",
20
+ "amount": -25000,
21
+ "available_on": 1516233600,
22
+ "created": 1516145022,
23
+ "currency": "usd",
24
+ "description": "Chargeback withdrawal for ch_1Bl3mKGWCopOTFn1LKoN557r",
25
+ "exchange_rate": null,
26
+ "fee": 1500,
27
+ "fee_details": [
28
+ {
29
+ "amount": 1500,
30
+ "application": null,
31
+ "currency": "usd",
32
+ "description": "Dispute fee",
33
+ "type": "stripe_fee"
34
+ }
35
+ ],
36
+ "net": -26500,
37
+ "source": "dp_1Bl3mMGWCopOTFn1jpVaJDrU",
38
+ "status": "pending",
39
+ "type": "adjustment"
40
+ }
41
+ ],
42
+ "charge": "ch_00000000000000",
43
+ "created": 1516145022,
44
+ "currency": "usd",
45
+ "evidence": {
46
+ "access_activity_log": null,
47
+ "billing_address": null,
48
+ "cancellation_policy": null,
49
+ "cancellation_policy_disclosure": null,
50
+ "cancellation_rebuttal": null,
51
+ "customer_communication": null,
52
+ "customer_email_address": "amitree.apu@gmail.com",
53
+ "customer_name": "amitree.apu@gmail.com",
54
+ "customer_purchase_ip": "157.131.133.10",
55
+ "customer_signature": null,
56
+ "duplicate_charge_documentation": null,
57
+ "duplicate_charge_explanation": null,
58
+ "duplicate_charge_id": null,
59
+ "product_description": null,
60
+ "receipt": null,
61
+ "refund_policy": null,
62
+ "refund_policy_disclosure": null,
63
+ "refund_refusal_explanation": null,
64
+ "service_date": null,
65
+ "service_documentation": null,
66
+ "shipping_address": null,
67
+ "shipping_carrier": null,
68
+ "shipping_date": null,
69
+ "shipping_documentation": null,
70
+ "shipping_tracking_number": null,
71
+ "uncategorized_file": null,
72
+ "uncategorized_text": null
73
+ },
74
+ "evidence_details": {
75
+ "due_by": 1517529599,
76
+ "has_evidence": false,
77
+ "past_due": false,
78
+ "submission_count": 0
79
+ },
80
+ "is_charge_refundable": false,
81
+ "livemode": false,
82
+ "metadata": {
83
+ },
84
+ "reason": "fraudulent",
85
+ "status": "needs_response"
86
+ }
87
+ }
88
+ }
@@ -3,6 +3,7 @@
3
3
  "livemode": false,
4
4
  "id": "evt_00000000000000",
5
5
  "type": "invoice.created",
6
+ "status": "paid",
6
7
  "object": "event",
7
8
  "data": {
8
9
  "object": {
@@ -3,6 +3,7 @@
3
3
  "livemode": false,
4
4
  "id": "evt_00000000000000",
5
5
  "type": "invoice.updated",
6
+ "status": "paid",
6
7
  "object": "event",
7
8
  "data": {
8
9
  "object": {
@@ -78,6 +78,15 @@ shared_examples 'Customer API' do
78
78
  expect(customer.sources.data.first.exp_year).to eq 2024
79
79
  end
80
80
 
81
+ it 'creates a customer with name' do
82
+ customer = Stripe::Customer.create(
83
+ source: gen_card_tk,
84
+ name: 'John Appleseed'
85
+ )
86
+ expect(customer.id).to match(/^test_cus/)
87
+ expect(customer.name).to eq('John Appleseed')
88
+ end
89
+
81
90
  it 'creates a customer with a plan' do
82
91
  plan = stripe_helper.create_plan(id: 'silver')
83
92
  customer = Stripe::Customer.create(id: 'test_cus_plan', source: gen_card_tk, :plan => 'silver')
@@ -267,6 +276,7 @@ shared_examples 'Customer API' do
267
276
 
268
277
  expect(customer.id).to eq(original.id)
269
278
  expect(customer.email).to eq(original.email)
279
+ expect(customer.name).to eq(nil)
270
280
  expect(customer.default_source).to eq(original.default_source)
271
281
  expect(customer.default_source).not_to be_a(Stripe::Card)
272
282
  expect(customer.subscriptions.count).to eq(0)
@@ -52,7 +52,7 @@ shared_examples 'Invoice API' do
52
52
  end
53
53
 
54
54
  it "stores all invoices in memory" do
55
- expect(Stripe::Invoice.all.map(&:id)).to eq([@invoice.id, @invoice2.id])
55
+ expect(Stripe::Invoice.all.map(&:id).sort).to eq([@invoice.id, @invoice2.id].sort)
56
56
  end
57
57
 
58
58
  it "defaults count to 10 invoices" do
@@ -79,7 +79,7 @@ shared_examples 'Invoice API' do
79
79
  end
80
80
 
81
81
  it 'updates attempted and paid flags' do
82
- @invoice.pay
82
+ @invoice = @invoice.pay
83
83
  expect(@invoice.attempted).to eq(true)
84
84
  expect(@invoice.paid).to eq(true)
85
85
  end
@@ -89,7 +89,7 @@ shared_examples 'Invoice API' do
89
89
  end
90
90
 
91
91
  it 'sets the charge attribute' do
92
- @invoice.pay
92
+ @invoice = @invoice.pay
93
93
  expect(@invoice.charge).to be_a String
94
94
  expect(@invoice.charge.length).to be > 0
95
95
  end
@@ -9,6 +9,9 @@ shared_examples 'Plan API' do
9
9
  :amount => 9900,
10
10
  :currency => 'USD',
11
11
  :interval => 1,
12
+ :product => {
13
+ :name => 'A product'
14
+ },
12
15
  :metadata => {
13
16
  :description => "desc text",
14
17
  :info => "info text"
@@ -36,6 +39,9 @@ shared_examples 'Plan API' do
36
39
  :amount => 9900,
37
40
  :currency => 'USD',
38
41
  :interval => 1,
42
+ :product => {
43
+ :name => 'A product'
44
+ }
39
45
  )
40
46
 
41
47
  expect(plan.id).to match(/^test_plan/)
@@ -47,14 +53,20 @@ shared_examples 'Plan API' do
47
53
  :name => 'The Memory Plan',
48
54
  :amount => 1100,
49
55
  :currency => 'USD',
50
- :interval => 1
56
+ :interval => 1,
57
+ :product => {
58
+ :name => 'A product'
59
+ }
51
60
  )
52
61
  plan2 = Stripe::Plan.create(
53
62
  :id => 'pid_3',
54
63
  :name => 'The Bonk Plan',
55
64
  :amount => 7777,
56
65
  :currency => 'USD',
57
- :interval => 1
66
+ :interval => 1,
67
+ :product => {
68
+ :name => 'A product'
69
+ }
58
70
  )
59
71
  data = test_data_source(:plans)
60
72
  expect(data[plan.id]).to_not be_nil
@@ -136,7 +148,10 @@ shared_examples 'Plan API' do
136
148
  :name => 'The Mock Plan',
137
149
  :amount => 99.99,
138
150
  :currency => 'USD',
139
- :interval => 'month'
151
+ :interval => 'month',
152
+ :product => {
153
+ :name => 'A product'
154
+ }
140
155
  )
141
156
  }.to raise_error(Stripe::InvalidRequestError, "Invalid integer: 99.99")
142
157
  end
@@ -552,6 +552,19 @@ shared_examples 'Customer Subscriptions' do
552
552
  sub2 = Stripe::Subscription.create({ items: [{ plan: 'silver' }], customer: customer.id }, another_subscription_header)
553
553
  expect(sub1).not_to eq(sub2)
554
554
  end
555
+
556
+ it "accepts a hash of items" do
557
+ silver = stripe_helper.create_plan(id: 'silver')
558
+ customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk)
559
+
560
+ sub = Stripe::Subscription.create({ items: { '0' => { plan: 'silver' } }, customer: customer.id })
561
+ sub.delete(at_period_end: true)
562
+
563
+ expect(sub.cancel_at_period_end).to be_truthy
564
+ expect(sub.save).to be_truthy
565
+ expect(sub.cancel_at_period_end).to be_falsey
566
+ end
567
+
555
568
  end
556
569
 
557
570
  context "updating a subscription" do
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'Subscription Items API' do
4
+ let(:stripe_helper) { StripeMock.create_test_helper }
5
+ let(:plan) { stripe_helper.create_plan }
6
+ let(:plan2) { stripe_helper.create_plan(amount: 100, id: 'one_more_1_plan') }
7
+ let(:customer) { Stripe::Customer.create(source: stripe_helper.generate_card_token) }
8
+ let(:subscription) { Stripe::Subscription.create(customer: customer.id, items: [{ plan: plan.id }]) }
9
+
10
+ context 'creates an item' do
11
+ it 'when required params only' do
12
+ item = Stripe::SubscriptionItem.create(plan: plan.id, subscription: subscription.id)
13
+
14
+ expect(item.id).to match(/^test_si/)
15
+ expect(item.plan.id).to eq(plan.id)
16
+ expect(item.subscription).to eq(subscription.id)
17
+ end
18
+ it 'when no subscription params' do
19
+ expect { Stripe::SubscriptionItem.create(plan: plan.id) }.to raise_error { |e|
20
+ expect(e).to be_a(Stripe::InvalidRequestError)
21
+ expect(e.param).to eq('subscription')
22
+ expect(e.message).to eq('Missing required param: subscription.')
23
+ }
24
+ end
25
+ it 'when no plan params' do
26
+ expect { Stripe::SubscriptionItem.create(subscription: subscription.id) }.to raise_error { |e|
27
+ expect(e).to be_a(Stripe::InvalidRequestError)
28
+ expect(e.param).to eq('plan')
29
+ expect(e.message).to eq('Missing required param: plan.')
30
+ }
31
+ end
32
+ end
33
+
34
+ context 'updates an item' do
35
+ let(:item) { Stripe::SubscriptionItem.create(plan: plan.id, subscription: subscription.id, quantity: 2 ) }
36
+
37
+ it 'updates plan' do
38
+ updated_item = Stripe::SubscriptionItem.update(item.id, plan: plan2.id)
39
+
40
+ expect(updated_item.plan.id).to eq(plan2.id)
41
+ end
42
+ it 'updates quantity' do
43
+ updated_item = Stripe::SubscriptionItem.update(item.id, quantity: 23)
44
+
45
+ expect(updated_item.quantity).to eq(23)
46
+ end
47
+ it 'when no existing item' do
48
+ expect { Stripe::SubscriptionItem.update('some_id') }.to raise_error { |e|
49
+ expect(e).to be_a(Stripe::InvalidRequestError)
50
+ expect(e.param).to eq('subscription_item')
51
+ expect(e.message).to eq('No such subscription_item: some_id')
52
+ }
53
+ end
54
+ end
55
+
56
+ context 'retrieves a list of items' do
57
+ before do
58
+ Stripe::SubscriptionItem.create(plan: plan.id, subscription: subscription.id, quantity: 2 )
59
+ Stripe::SubscriptionItem.create(plan: plan2.id, subscription: subscription.id, quantity: 20)
60
+ end
61
+
62
+ it 'retrieves all subscription items' do
63
+ all = Stripe::SubscriptionItem.list(subscription: subscription.id)
64
+
65
+ expect(all.count).to eq(2)
66
+ end
67
+ it 'when no subscription param' do
68
+ expect { Stripe::SubscriptionItem.list }.to raise_error { |e|
69
+ expect(e).to be_a(Stripe::InvalidRequestError)
70
+ expect(e.param).to eq('subscription')
71
+ expect(e.message).to eq('Missing required param: subscription.')
72
+ }
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'TaxRate API' do
4
+ context 'with created tax rate' do
5
+ let!(:rate) { Stripe::TaxRate.create }
6
+
7
+ it 'returns list of tax rates' do
8
+ rates = Stripe::TaxRate.list
9
+ expect(rates.count).to eq(1)
10
+ end
11
+
12
+ it 'retrieves tax rate' do
13
+ ret_rate = Stripe::TaxRate.retrieve(rate.id)
14
+ expect(ret_rate.id).not_to be_nil
15
+ expect(ret_rate.object).to eq('tax_rate')
16
+ expect(ret_rate.display_name).to eq('VAT')
17
+ expect(ret_rate.percentage).to eq(21.0)
18
+ expect(ret_rate.jurisdiction).to eq('EU')
19
+ expect(ret_rate.inclusive).to eq(false)
20
+ end
21
+
22
+ it 'updates tax rate' do
23
+ ret_rate = Stripe::TaxRate.update(rate.id, percentage: 30.5)
24
+ expect(ret_rate.id).not_to be_nil
25
+ expect(ret_rate.object).to eq('tax_rate')
26
+ expect(ret_rate.display_name).to eq('VAT')
27
+ expect(ret_rate.percentage).to eq(30.5)
28
+ expect(ret_rate.jurisdiction).to eq('EU')
29
+ expect(ret_rate.inclusive).to eq(false)
30
+ end
31
+ end
32
+
33
+ it 'creates tax rate' do
34
+ rate = Stripe::TaxRate.create
35
+ expect(rate.id).not_to be_nil
36
+ expect(rate.object).to eq('tax_rate')
37
+ expect(rate.display_name).to eq('VAT')
38
+ expect(rate.percentage).to eq(21.0)
39
+ expect(rate.jurisdiction).to eq('EU')
40
+ expect(rate.inclusive).to eq(false)
41
+ end
42
+ end
@@ -27,9 +27,11 @@ def it_behaves_like_stripe(&block)
27
27
  it_behaves_like 'Payout API', &block
28
28
  it_behaves_like 'Stripe Error Mocking', &block
29
29
  it_behaves_like 'Customer Subscriptions', &block
30
+ it_behaves_like 'Subscription Items API', &block
30
31
  it_behaves_like 'Webhook Events API', &block
31
32
  it_behaves_like 'Country Spec API', &block
32
33
  it_behaves_like 'EphemeralKey API', &block
34
+ it_behaves_like 'TaxRate API', &block
33
35
 
34
36
  # Integration tests
35
37
  it_behaves_like 'Multiple Customer Cards'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-ruby-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.7
4
+ version: 2.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-26 00:00:00.000000000 Z
11
+ date: 2019-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stripe
@@ -163,7 +163,9 @@ files:
163
163
  - lib/stripe_mock/request_handlers/recipients.rb
164
164
  - lib/stripe_mock/request_handlers/refunds.rb
165
165
  - lib/stripe_mock/request_handlers/sources.rb
166
+ - lib/stripe_mock/request_handlers/subscription_items.rb
166
167
  - lib/stripe_mock/request_handlers/subscriptions.rb
168
+ - lib/stripe_mock/request_handlers/tax_rates.rb
167
169
  - lib/stripe_mock/request_handlers/tokens.rb
168
170
  - lib/stripe_mock/request_handlers/transfers.rb
169
171
  - lib/stripe_mock/request_handlers/validators/param_validators.rb
@@ -181,6 +183,8 @@ files:
181
183
  - lib/stripe_mock/webhook_fixtures/balance.available.json
182
184
  - lib/stripe_mock/webhook_fixtures/charge.dispute.closed.json
183
185
  - lib/stripe_mock/webhook_fixtures/charge.dispute.created.json
186
+ - lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json
187
+ - lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json
184
188
  - lib/stripe_mock/webhook_fixtures/charge.dispute.updated.json
185
189
  - lib/stripe_mock/webhook_fixtures/charge.failed.json
186
190
  - lib/stripe_mock/webhook_fixtures/charge.refunded.json
@@ -252,6 +256,8 @@ files:
252
256
  - spec/shared_stripe_examples/recipient_examples.rb
253
257
  - spec/shared_stripe_examples/refund_examples.rb
254
258
  - spec/shared_stripe_examples/subscription_examples.rb
259
+ - spec/shared_stripe_examples/subscription_items_examples.rb
260
+ - spec/shared_stripe_examples/tax_rate_examples.rb
255
261
  - spec/shared_stripe_examples/transfer_examples.rb
256
262
  - spec/shared_stripe_examples/validation_examples.rb
257
263
  - spec/shared_stripe_examples/webhook_event_examples.rb
@@ -321,6 +327,8 @@ test_files:
321
327
  - spec/shared_stripe_examples/recipient_examples.rb
322
328
  - spec/shared_stripe_examples/refund_examples.rb
323
329
  - spec/shared_stripe_examples/subscription_examples.rb
330
+ - spec/shared_stripe_examples/subscription_items_examples.rb
331
+ - spec/shared_stripe_examples/tax_rate_examples.rb
324
332
  - spec/shared_stripe_examples/transfer_examples.rb
325
333
  - spec/shared_stripe_examples/validation_examples.rb
326
334
  - spec/shared_stripe_examples/webhook_event_examples.rb