mock_chargebee 0.0.3 → 0.0.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
  SHA256:
3
- metadata.gz: 41a40358cf8b7de396636263ce6343da7bff976d8a143b9c32601974673c475d
4
- data.tar.gz: 4df45ce97b0efcaeb150289b052861c0e037712e0b2cdf88078226d3d4a2b98f
3
+ metadata.gz: eb8a639b517ffc4fc02bb867abc491e16582acfa8d5c96537f141e0e5c254a0f
4
+ data.tar.gz: 6647a61e6a627082b36a2b5cd3f922773de4c9fbc5b6067cfdbb724b1430c38b
5
5
  SHA512:
6
- metadata.gz: 30ba92494b7a80f9a775dc161e2cec20f6c6fd3fe4de7da38ebbe1365c2fffcfb61f69cddc351c68e1df1bc35e165eae03eb42ab382b3ec5ae008b6f2537db67
7
- data.tar.gz: 4d862d1fb78fff91f36c039dd3c4ea8ee79dfc6040501777bbcb2e227043c228fcf3e5d9b988c324107e1249d7f1ffc76ba43c92bc16f661cad552ad724ec6fb
6
+ metadata.gz: d4f7227d11feb543fc01dfd81f57b4666d0779f3ed8be834a6523e23e55525d0ab0d5bfbd3ac831dce150d3753eaae5bfae868d0f71a13ea10578d4078b60ec5
7
+ data.tar.gz: bd6dead1bda654909ded2de8100a6275c6ad6805c8beefb01cb2099c22f1f63a342666738c3362322dec42436b29c4bfda4cb233df7c2ce96b36fff15a4a5101
@@ -0,0 +1,24 @@
1
+ {
2
+ "addon_applicability": "all",
3
+ "charge_model": "flat_fee",
4
+ "currency_code": "USD",
5
+ "enabled_in_hosted_pages": true,
6
+ "enabled_in_portal": true,
7
+ "free_quantity": 0,
8
+ "giftable": false,
9
+ "id": "silver",
10
+ "invoice_name": "sample plan",
11
+ "is_shippable": false,
12
+ "name": "Silver",
13
+ "object": "plan",
14
+ "period": 1,
15
+ "period_unit": "month",
16
+ "price": 5000,
17
+ "pricing_model": "flat_fee",
18
+ "resource_version": 1517505797000,
19
+ "show_description_in_invoices": false,
20
+ "show_description_in_quotes": false,
21
+ "status": "active",
22
+ "taxable": true,
23
+ "updated_at": 1517505797
24
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "access_url": "https://yourapp.chargebeeportal.com/portal/access/__test__cdBbQgJg5fPSTw9qBPDIaQiVEEx0Gsrrc",
3
+ "created_at": 1517505973,
4
+ "customer_id": "__test__KyVnHhSBWm8kA2sT",
5
+ "expires_at": 1517509573,
6
+ "id": "portal___test__KyVnHhSBWm8l82sV",
7
+ "linked_customers": [
8
+ {
9
+ "customer_id": "__test__KyVnHhSBWm8kA2sT",
10
+ "has_active_subscription": false,
11
+ "has_billing_address": false,
12
+ "has_payment_method": false,
13
+ "object": "linked_customer"
14
+ }
15
+ ],
16
+ "object": "portal_session",
17
+ "redirect_url": "https://yourdomain.com/users/3490343",
18
+ "status": "created",
19
+ "token": "__test__cdBbQgJg5fPSTw9qBPDIaQiVEEx0Gsrrc"
20
+ }
@@ -11,11 +11,16 @@ module MockChargebee
11
11
  Util.generate_id(self::RESOURCE_ID_PREFIX)
12
12
  end
13
13
 
14
+ def self.already_exists!(id)
15
+ raise ChargeBee::InvalidRequestError.new(400, message: "The value #{id} is already present.")
16
+ end
17
+
14
18
  def self.load_fixtures(*args)
15
19
  args.each do |arg|
16
20
  define_singleton_method("#{arg}_fixture") do
17
21
  instance_variable_get("@#{arg}_fixture") ||
18
- instance_variable_set("@#{arg}_fixture", JSON.parse(File.read("#{File.dirname(__FILE__)}/../fixtures/#{arg}.json")))
22
+ instance_variable_set("@#{arg}_fixture",
23
+ JSON.parse(File.read("#{File.dirname(__FILE__)}/../fixtures/#{arg}.json")))
19
24
  end
20
25
  end
21
26
  end
@@ -3,7 +3,7 @@
3
3
  module MockChargebee
4
4
  module Models
5
5
  class Customer < Base
6
- RESOURCE_ID_PREFIX = "cust"
6
+ RESOURCE_ID_PREFIX = 'cust'
7
7
 
8
8
  load_fixtures :customer
9
9
 
@@ -12,9 +12,11 @@ module MockChargebee
12
12
  end
13
13
 
14
14
  def self.create(params)
15
- params["id"] ||= unique_id
15
+ already_exists!(params['id']) if already_exists?(params['id'])
16
+
17
+ params['id'] ||= unique_id
16
18
  customer = customer_fixture.merge(params)
17
- repositories.customers.store(customer["id"], customer)
19
+ repositories.customers.store(customer['id'], customer)
18
20
 
19
21
  customer
20
22
  end
@@ -22,10 +24,23 @@ module MockChargebee
22
24
  def self.update(id, params)
23
25
  customer = find(id)
24
26
  customer.merge!(params)
25
- repositories.customers.store(customer["id"], customer)
27
+ repositories.customers.store(customer['id'], customer)
26
28
 
27
29
  customer
28
30
  end
31
+
32
+ def self.delete(id)
33
+ customer = find(id)
34
+ repositories.customers.delete(id)
35
+
36
+ customer
37
+ end
38
+
39
+ def self.already_exists?(id)
40
+ return false if id.nil?
41
+
42
+ repositories.customers[id].present?
43
+ end
29
44
  end
30
45
  end
31
46
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module Models
5
+ class Plan < Base
6
+ RESOURCE_ID_PREFIX = 'plan'
7
+
8
+ load_fixtures :plan
9
+
10
+ def self.find(id)
11
+ repositories.plans.fetch(id)
12
+ end
13
+
14
+ def self.create(params)
15
+ params['id'] ||= unique_id
16
+ plan = plan_fixture.merge(params)
17
+ repositories.plans.store(plan['id'], plan)
18
+
19
+ plan
20
+ end
21
+
22
+ def self.update(id, params)
23
+ plan = find(id)
24
+ plan.merge!(params)
25
+ repositories.plans.store(plan['id'], plan)
26
+
27
+ plan
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module Models
5
+ class PortalSession < Base
6
+ RESOURCE_ID_PREFIX = 'portal'
7
+
8
+ load_fixtures :portal_session
9
+
10
+ def self.create(params)
11
+ Validations::PortalSessions::CreateParams.validate_required(params)
12
+
13
+ params['id'] ||= unique_id
14
+ params['customer_id'] = params.dig(:customer, :id)
15
+ portal_session = portal_session_fixture.merge(params)
16
+ repositories.portal_sessions.store(portal_session['id'], portal_session)
17
+
18
+ portal_session
19
+ end
20
+ end
21
+ end
22
+ end
@@ -12,7 +12,9 @@ module MockChargebee
12
12
 
13
13
  add_repositories :customers,
14
14
  :subscriptions,
15
- :coupons
15
+ :coupons,
16
+ :portal_sessions,
17
+ :plans
16
18
 
17
19
  class RepoHash < Hash
18
20
  def fetch(*)
@@ -6,12 +6,13 @@ module MockChargebee
6
6
  parsed_path = Util.parse_path_from_url(url)
7
7
  parsed_params = Util.parse_params(params)
8
8
 
9
- handler = RequestHandlers.const_get(parsed_path.resource.capitalize)
9
+ handler = RequestHandlers.const_get(parsed_path.resource.split('_').map(&:capitalize).join(''))
10
10
  resp = handler.call(method, parsed_path, parsed_params)
11
- resp = ChargeBee::Util.symbolize_keys(resp)
12
- resp
11
+ ChargeBee::Util.symbolize_keys(resp)
13
12
  rescue NameError => e
14
- raise MockChargebee::MissingRequestHandler parsed_path.resource if e.message.match?(/uninitialized constant #{parsed_path.resource.capitalize}/)
13
+ if e.message.match?(/uninitialized constant #{parsed_path.resource.capitalize}/)
14
+ raise MockChargebee::MissingRequestHandler parsed_path.resource
15
+ end
15
16
 
16
17
  raise e
17
18
  end
@@ -15,6 +15,12 @@ module MockChargebee
15
15
  { customer: customer }
16
16
  end
17
17
 
18
+ def post_delete
19
+ customer = Models::Customer.delete(id)
20
+
21
+ { customer: customer }
22
+ end
23
+
18
24
  def post_subscriptions
19
25
  customer = Models::Customer.find(id)
20
26
  subscription = Models::Subscription.create_for_customer(customer, params)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module RequestHandlers
5
+ class Plans < Base
6
+ private
7
+
8
+ def post
9
+ plan = if id.nil?
10
+ Models::Plan.create(params)
11
+ else
12
+ Models::Plan.update(id, params)
13
+ end
14
+
15
+ { plan: plan }
16
+ end
17
+
18
+ def get
19
+ plan = Models::Plan.find(id)
20
+ binding.pry
21
+
22
+ { plan: plan }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module RequestHandlers
5
+ class PortalSessions < Base
6
+ private
7
+
8
+ def post
9
+ portal_session = Models::PortalSession.create(params)
10
+ { portal_session: portal_session }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module Validations
5
+ module PortalSessions
6
+ class CreateParams < Base
7
+ REQUIRED_KEYS = %w[customer].freeze
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MockChargebee
4
- VERSION = "0.0.3"
4
+ VERSION = '0.0.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_chargebee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cass
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-22 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,6 +110,8 @@ files:
110
110
  - lib/mock_chargebee/errors.rb
111
111
  - lib/mock_chargebee/fixtures/coupon.json
112
112
  - lib/mock_chargebee/fixtures/customer.json
113
+ - lib/mock_chargebee/fixtures/plan.json
114
+ - lib/mock_chargebee/fixtures/portal_session.json
113
115
  - lib/mock_chargebee/fixtures/subscription.json
114
116
  - lib/mock_chargebee/fixtures/subscription_cancel_response.json
115
117
  - lib/mock_chargebee/fixtures/subscription_create_response.json
@@ -208,17 +210,22 @@ files:
208
210
  - lib/mock_chargebee/models/base.rb
209
211
  - lib/mock_chargebee/models/coupon.rb
210
212
  - lib/mock_chargebee/models/customer.rb
213
+ - lib/mock_chargebee/models/plan.rb
214
+ - lib/mock_chargebee/models/portal_session.rb
211
215
  - lib/mock_chargebee/models/subscription.rb
212
216
  - lib/mock_chargebee/repositories.rb
213
217
  - lib/mock_chargebee/request.rb
214
218
  - lib/mock_chargebee/request_handlers/base.rb
215
219
  - lib/mock_chargebee/request_handlers/coupons.rb
216
220
  - lib/mock_chargebee/request_handlers/customers.rb
221
+ - lib/mock_chargebee/request_handlers/plans.rb
222
+ - lib/mock_chargebee/request_handlers/portal_sessions.rb
217
223
  - lib/mock_chargebee/request_handlers/subscriptions.rb
218
224
  - lib/mock_chargebee/services/apply_coupons.rb
219
225
  - lib/mock_chargebee/util.rb
220
226
  - lib/mock_chargebee/validations/base.rb
221
227
  - lib/mock_chargebee/validations/coupons.rb
228
+ - lib/mock_chargebee/validations/portal_sessions.rb
222
229
  - lib/mock_chargebee/validations/subscriptions.rb
223
230
  - lib/mock_chargebee/validations/webhooks.rb
224
231
  - lib/mock_chargebee/version.rb