solidus_subscriptions 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +41 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.github_changelog_generator +2 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/.rubocop_todo.yml +86 -0
- data/CHANGELOG.md +191 -0
- data/Gemfile +33 -0
- data/LICENSE +26 -0
- data/README.md +221 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/spree/backend/solidus_subscriptions.js +1 -0
- data/app/assets/javascripts/spree/backend/solidus_subscriptions/edit_subscription_payment.js +32 -0
- data/app/controllers/solidus_subscriptions/api/v1/base_controller.rb +13 -0
- data/app/controllers/solidus_subscriptions/api/v1/line_items_controller.rb +48 -0
- data/app/controllers/solidus_subscriptions/api/v1/subscriptions_controller.rb +100 -0
- data/app/controllers/spree/admin/installments_controller.rb +25 -0
- data/app/controllers/spree/admin/subscription_events_controller.rb +37 -0
- data/app/controllers/spree/admin/subscription_orders_controller.rb +35 -0
- data/app/controllers/spree/admin/subscriptions_controller.rb +100 -0
- data/app/controllers/spree/admin/users/subscriptions_controller.rb +17 -0
- data/app/decorators/controllers/solidus_subscriptions/spree/api/line_items_controller/create_subscription_line_items.rb +36 -0
- data/app/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb +35 -0
- data/app/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association.rb +26 -0
- data/app/decorators/models/solidus_subscriptions/spree/order/after_create.rb +19 -0
- data/app/decorators/models/solidus_subscriptions/spree/order/finalize_creates_subscriptions.rb +23 -0
- data/app/decorators/models/solidus_subscriptions/spree/order/installment_details_association.rb +15 -0
- data/app/decorators/models/solidus_subscriptions/spree/order/subscription_association.rb +15 -0
- data/app/decorators/models/solidus_subscriptions/spree/order/subscription_line_items_association.rb +19 -0
- data/app/decorators/models/solidus_subscriptions/spree/product/delegate_subscribable.rb +17 -0
- data/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb +30 -0
- data/app/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions.rb +20 -0
- data/app/decorators/models/solidus_subscriptions/spree/variant/variant_pretty_name.rb +17 -0
- data/app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb +28 -0
- data/app/jobs/solidus_subscriptions/process_installment_job.rb +13 -0
- data/app/jobs/solidus_subscriptions/process_subscription_job.rb +31 -0
- data/app/models/solidus_subscriptions/installment.rb +135 -0
- data/app/models/solidus_subscriptions/installment_detail.rb +28 -0
- data/app/models/solidus_subscriptions/interval.rb +26 -0
- data/app/models/solidus_subscriptions/line_item.rb +42 -0
- data/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb +44 -0
- data/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb +31 -0
- data/app/models/solidus_subscriptions/subscription.rb +392 -0
- data/app/models/solidus_subscriptions/subscription_event.rb +11 -0
- data/app/overrides/views/admin_subscribable_product_checkbox.rb +8 -0
- data/app/overrides/views/admin_subscribable_variant_checkbox.rb +8 -0
- data/app/overrides/views/admin_subscriptions_menu_link.rb +10 -0
- data/app/overrides/views/admin_users_subscriptions_tab.rb +8 -0
- data/app/overrides/views/subscription_line_item_fields.rb +8 -0
- data/app/subscribers/solidus_subscriptions/churn_buster_subscriber.rb +39 -0
- data/app/subscribers/solidus_subscriptions/event_storage_subscriber.rb +64 -0
- data/app/views/spree/admin/installments/_state_pill.html.erb +8 -0
- data/app/views/spree/admin/installments/index.html.erb +42 -0
- data/app/views/spree/admin/products/_subscribable_checkbox.html.erb +8 -0
- data/app/views/spree/admin/promotions/rules/_subscription_creation_order.html.erb +0 -0
- data/app/views/spree/admin/promotions/rules/_subscription_installment_order.html.erb +0 -0
- data/app/views/spree/admin/shared/_subscription_actions.html.erb +35 -0
- data/app/views/spree/admin/shared/_subscription_breadcrumbs.html.erb +4 -0
- data/app/views/spree/admin/shared/_subscription_sidebar.html.erb +18 -0
- data/app/views/spree/admin/shared/_subscription_tab.html.erb +3 -0
- data/app/views/spree/admin/shared/_subscription_tabs.html.erb +18 -0
- data/app/views/spree/admin/subscription_events/_state_pill.html.erb +8 -0
- data/app/views/spree/admin/subscription_events/index.html.erb +42 -0
- data/app/views/spree/admin/subscription_orders/index.html.erb +93 -0
- data/app/views/spree/admin/subscriptions/_form.html.erb +150 -0
- data/app/views/spree/admin/subscriptions/_processing_state_pill.html.erb +9 -0
- data/app/views/spree/admin/subscriptions/_state_pill.html.erb +10 -0
- data/app/views/spree/admin/subscriptions/edit.html.erb +10 -0
- data/app/views/spree/admin/subscriptions/index.html.erb +176 -0
- data/app/views/spree/admin/subscriptions/new.html.erb +5 -0
- data/app/views/spree/admin/users/_subscription_tab.html.erb +5 -0
- data/app/views/spree/admin/users/subscriptions/index.html.erb +44 -0
- data/app/views/spree/admin/variants/_subscribable_checkbox.html.erb +6 -0
- data/app/views/spree/frontend/products/_subscription_line_item_fields.html.erb +30 -0
- data/bin/console +17 -0
- data/bin/rails +7 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/sandbox +86 -0
- data/bin/setup +8 -0
- data/config/initializers/permission_sets.rb +11 -0
- data/config/initializers/subscribers.rb +9 -0
- data/config/locales/en.yml +129 -0
- data/config/routes.rb +34 -0
- data/db/migrate/20160825164850_create_solidus_subscriptions_subscriptions.rb +11 -0
- data/db/migrate/20160825173548_create_solidus_subscriptions_line_items.rb +17 -0
- data/db/migrate/20160825202248_create_solidus_subscriptions_installments.rb +23 -0
- data/db/migrate/20160825211202_create_solidus_subscriptions_installment_details.rb +22 -0
- data/db/migrate/20160825214240_add_subscribable_to_spree_variants.rb +5 -0
- data/db/migrate/20160829201653_change_subscription_line_items_installments_to_max_installments.rb +5 -0
- data/db/migrate/20160902220242_remove_state_from_solidus_susbscriptions_installment_details.rb +5 -0
- data/db/migrate/20160902220604_add_successful_to_solidus_subscriptions_installment_details.rb +5 -0
- data/db/migrate/20160902221218_add_message_to_solidus_subscriptions_installment_details.rb +5 -0
- data/db/migrate/20160922164101_add_interval_length_and_units_to_subscription_line_items.rb +8 -0
- data/db/migrate/20161006191003_add_skip_count_to_solidus_subscriptions_subscriptions.rb +5 -0
- data/db/migrate/20161006191127_add_successive_skip_count_to_solidus_subscriptions_subscriptions.rb +5 -0
- data/db/migrate/20161014212649_allow_spree_line_item_id_to_be_null.rb +5 -0
- data/db/migrate/20161017155749_add_order_id_to_solidus_subscriptions_installment_details.rb +6 -0
- data/db/migrate/20161017175509_remove_order_id_from_solidus_subscriptions_installments.rb +5 -0
- data/db/migrate/20161017201944_add_subscription_order_to_spree_orders.rb +5 -0
- data/db/migrate/20161221155142_add_store_to_solidus_subscriptions_subscriptions.rb +6 -0
- data/db/migrate/20161223152905_add_address_id_to_solidus_subscriptions_subscriptions.rb +7 -0
- data/db/migrate/20170106224713_change_line_item_max_installments_to_end_date.rb +6 -0
- data/db/migrate/20170111224458_change_subscription_actionable_date_to_datetime.rb +5 -0
- data/db/migrate/20170111232801_change_inteval_actionable_date_to_datetime.rb +5 -0
- data/db/migrate/20170112012407_add_config_options_to_subscriptions.rb +7 -0
- data/db/migrate/20200617102749_add_billing_address_to_subscriptions.rb +11 -0
- data/db/migrate/20200617155042_add_payment_source_to_subscriptions.rb +6 -0
- data/db/migrate/20200618092951_add_payment_method_to_subscriptions.rb +11 -0
- data/db/migrate/20200730101242_create_solidus_subscriptions_subscription_events.rb +22 -0
- data/db/migrate/20200917072152_add_subscription_reference_to_orders.rb +11 -0
- data/db/migrate/20201007140032_add_guest_token_to_subscriptions.rb +6 -0
- data/db/migrate/20201123171026_change_actionable_date_to_date.rb +15 -0
- data/db/migrate/20210205140422_add_currency_to_subscription.rb +5 -0
- data/db/migrate/20210323165714_update_promotion_rule_names.rb +22 -0
- data/lib/generators/solidus_subscriptions/install/install_generator.rb +32 -0
- data/lib/generators/solidus_subscriptions/install/templates/initializer.rb +99 -0
- data/lib/solidus_subscriptions.rb +49 -0
- data/lib/solidus_subscriptions/checkout.rb +74 -0
- data/lib/solidus_subscriptions/churn_buster/client.rb +48 -0
- data/lib/solidus_subscriptions/churn_buster/order_serializer.rb +19 -0
- data/lib/solidus_subscriptions/churn_buster/serializer.rb +23 -0
- data/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb +28 -0
- data/lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb +37 -0
- data/lib/solidus_subscriptions/churn_buster/subscription_serializer.rb +17 -0
- data/lib/solidus_subscriptions/configuration.rb +84 -0
- data/lib/solidus_subscriptions/dispatcher/base.rb +18 -0
- data/lib/solidus_subscriptions/dispatcher/failure_dispatcher.rb +13 -0
- data/lib/solidus_subscriptions/dispatcher/out_of_stock_dispatcher.rb +11 -0
- data/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb +19 -0
- data/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb +17 -0
- data/lib/solidus_subscriptions/engine.rb +56 -0
- data/lib/solidus_subscriptions/permission_sets/default_customer.rb +19 -0
- data/lib/solidus_subscriptions/permission_sets/subscription_management.rb +12 -0
- data/lib/solidus_subscriptions/permitted_attributes.rb +20 -0
- data/lib/solidus_subscriptions/processor.rb +17 -0
- data/lib/solidus_subscriptions/subscription_generator.rb +77 -0
- data/lib/solidus_subscriptions/subscription_line_item_builder.rb +23 -0
- data/lib/solidus_subscriptions/testing_support/factories/installment_detail_factory.rb +11 -0
- data/lib/solidus_subscriptions/testing_support/factories/installment_factory.rb +29 -0
- data/lib/solidus_subscriptions/testing_support/factories/line_item_factory.rb +20 -0
- data/lib/solidus_subscriptions/testing_support/factories/spree/line_item_factory.rb +17 -0
- data/lib/solidus_subscriptions/testing_support/factories/spree/order_factory.rb +17 -0
- data/lib/solidus_subscriptions/testing_support/factories/spree_modification_factory.rb +10 -0
- data/lib/solidus_subscriptions/testing_support/factories/subscription_event_factory.rb +8 -0
- data/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb +56 -0
- data/lib/solidus_subscriptions/version.rb +5 -0
- data/lib/tasks/process_subscriptions.rake +8 -0
- data/reference/solidus_subscriptions.v1.yaml +290 -0
- data/solidus_subscriptions.gemspec +47 -0
- data/spec/controllers/spree/admin/subscriptions_controller_spec.rb +202 -0
- data/spec/controllers/spree/api/line_items_controller_spec.rb +103 -0
- data/spec/controllers/spree/api/orders_controller_spec.rb +57 -0
- data/spec/controllers/spree/api/users_controller_spec.rb +48 -0
- data/spec/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items_spec.rb +80 -0
- data/spec/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association_spec.rb +10 -0
- data/spec/decorators/models/solidus_subscriptions/spree/order/finalize_creates_subscriptions_spec.rb +32 -0
- data/spec/decorators/models/solidus_subscriptions/spree/order/installment_details_association_spec.rb +9 -0
- data/spec/decorators/models/solidus_subscriptions/spree/order/subscription_line_items_association_spec.rb +9 -0
- data/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb +22 -0
- data/spec/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions_spec.rb +25 -0
- data/spec/features/admin/subscription_orders_spec.rb +35 -0
- data/spec/features/admin/subscriptions_spec.rb +63 -0
- data/spec/features/admin_users_subscription_tabs_spec.rb +61 -0
- data/spec/fixtures/cassettes/churn_buster.yml +229 -0
- data/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb +38 -0
- data/spec/jobs/solidus_subscriptions/process_subscription_job_spec.rb +83 -0
- data/spec/lib/solidus_subscriptions/checkout_spec.rb +125 -0
- data/spec/lib/solidus_subscriptions/churn_buster/client_spec.rb +59 -0
- data/spec/lib/solidus_subscriptions/dispatcher/failure_dispatcher_spec.rb +29 -0
- data/spec/lib/solidus_subscriptions/dispatcher/out_of_stock_dispatcher_spec.rb +15 -0
- data/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb +44 -0
- data/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb +30 -0
- data/spec/lib/solidus_subscriptions/permission_sets/default_customer_spec.rb +95 -0
- data/spec/lib/solidus_subscriptions/permission_sets/subscription_management_spec.rb +26 -0
- data/spec/lib/solidus_subscriptions/processor_spec.rb +34 -0
- data/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb +57 -0
- data/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb +39 -0
- data/spec/lib/solidus_subscriptions/subscription_generator_spec.rb +83 -0
- data/spec/lib/solidus_subscriptions_spec.rb +30 -0
- data/spec/models/solidus_subscriptions/installment_detail_spec.rb +23 -0
- data/spec/models/solidus_subscriptions/installment_spec.rb +201 -0
- data/spec/models/solidus_subscriptions/line_item_spec.rb +29 -0
- data/spec/models/solidus_subscriptions/subscription_spec.rb +814 -0
- data/spec/models/spree/variant_spec.rb +16 -0
- data/spec/models/spree/wallet_payment_source_spec.rb +20 -0
- data/spec/requests/api/v1/line_items_spec.rb +116 -0
- data/spec/requests/api/v1/subscriptions_spec.rb +255 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb +76 -0
- data/spec/support/active_model_mocks.rb +1 -0
- data/spec/support/cancancan.rb +1 -0
- data/spec/support/factories.rb +1 -0
- data/spec/support/helpers/checkout_infrastructure.rb +18 -0
- data/spec/support/helpers/config.rb +13 -0
- data/spec/support/shoulda.rb +7 -0
- data/spec/support/timecop.rb +1 -0
- data/spec/support/vcr.rb +10 -0
- data/spec/support/version_cake.rb +8 -0
- metadata +498 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/solidus_subscriptions/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'solidus_subscriptions'
|
7
|
+
spec.version = SolidusSubscriptions::VERSION
|
8
|
+
spec.authors = ['Solidus Team']
|
9
|
+
spec.email = 'contact@solidus.io'
|
10
|
+
|
11
|
+
spec.summary = 'Add subscription support to Solidus'
|
12
|
+
spec.description = 'Add subscription support to Solidus'
|
13
|
+
spec.homepage = 'https://github.com/solidusio-contrib/solidus_subscriptions'
|
14
|
+
spec.license = 'BSD-3-Clause'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_subscriptions'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_subscriptions/blob/master/CHANGELOG.md'
|
19
|
+
|
20
|
+
spec.required_ruby_version = Gem::Requirement.new('~> 2.5')
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
|
25
|
+
|
26
|
+
spec.files = files.grep_v(%r{^(test|spec|features)/})
|
27
|
+
spec.test_files = files.grep(%r{^(test|spec|features)/})
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_dependency 'deface'
|
33
|
+
spec.add_dependency 'httparty', '~> 0.18'
|
34
|
+
spec.add_dependency 'i18n'
|
35
|
+
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 3']
|
36
|
+
spec.add_dependency 'solidus_support', '~> 0.7'
|
37
|
+
spec.add_dependency 'state_machines'
|
38
|
+
|
39
|
+
spec.add_development_dependency 'rspec-activemodel-mocks'
|
40
|
+
spec.add_development_dependency 'shoulda-matchers', '~> 4.4'
|
41
|
+
spec.add_development_dependency 'solidus_dev_support', '~> 2.0'
|
42
|
+
spec.add_development_dependency 'timecop'
|
43
|
+
spec.add_development_dependency 'vcr'
|
44
|
+
spec.add_development_dependency 'versioncake'
|
45
|
+
spec.add_development_dependency 'webmock'
|
46
|
+
spec.add_development_dependency 'yard'
|
47
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Spree::Admin::SubscriptionsController, type: :request do
|
6
|
+
extend Spree::TestingSupport::AuthorizationHelpers::Request
|
7
|
+
stub_authorization!
|
8
|
+
|
9
|
+
before do
|
10
|
+
ActionController::Base.allow_forgery_protection = false
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
ActionController::Base.allow_forgery_protection = true
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'get /admin/subscriptions' do
|
18
|
+
subject do
|
19
|
+
get spree.admin_subscriptions_path
|
20
|
+
response
|
21
|
+
end
|
22
|
+
|
23
|
+
it { is_expected.to be_successful }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'GET :new' do
|
27
|
+
subject do
|
28
|
+
get spree.new_admin_subscription_path
|
29
|
+
response
|
30
|
+
end
|
31
|
+
|
32
|
+
it { is_expected.to be_successful }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'GET :edit' do
|
36
|
+
subject do
|
37
|
+
get spree.edit_admin_subscription_path(subscription)
|
38
|
+
response
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:subscription) { create :subscription, :actionable }
|
42
|
+
|
43
|
+
it { is_expected.to be_successful }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'PUT :update' do
|
47
|
+
it 'redirects to edit subscription page' do
|
48
|
+
subscription = create :subscription
|
49
|
+
subscription_params = { subscription: { interval_length: 1 } }
|
50
|
+
|
51
|
+
expect(put(spree.admin_subscription_path(subscription), params: subscription_params)).
|
52
|
+
to redirect_to spree.edit_admin_subscription_path(subscription)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'updates the subscription attributes', :aggregate_failures do
|
56
|
+
expected_date = DateTime.parse('2001/11/12')
|
57
|
+
subscription = create :subscription, :actionable
|
58
|
+
subscription_params = { subscription: { actionable_date: expected_date } }
|
59
|
+
|
60
|
+
expect { put spree.admin_subscription_path(subscription), params: subscription_params }.
|
61
|
+
to change { subscription.reload.actionable_date }.
|
62
|
+
to expected_date
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'does not duplicate line items' do
|
66
|
+
variant = create :variant, subscribable: true
|
67
|
+
subscription = create :subscription
|
68
|
+
subscription_params = {
|
69
|
+
subscription: {
|
70
|
+
line_items_attributes: [
|
71
|
+
{ subscribable_id: variant.id, quantity: 1 }
|
72
|
+
]
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
expect { put spree.admin_subscription_path(subscription), params: subscription_params }.
|
77
|
+
to change { subscription.reload.line_items.count }.
|
78
|
+
by 1
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when updating the payment method' do
|
82
|
+
it 'updates the subscription payment method' do
|
83
|
+
check_payment_method = create :check_payment_method
|
84
|
+
subscription = create :subscription
|
85
|
+
subscription_params = { subscription: { payment_method_id: check_payment_method.id } }
|
86
|
+
|
87
|
+
put spree.admin_subscription_path(subscription), params: subscription_params
|
88
|
+
|
89
|
+
expect(subscription.reload).to have_attributes(
|
90
|
+
payment_method: check_payment_method,
|
91
|
+
payment_source: nil,
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'updates the subscription payment source if payment method requires source' do
|
96
|
+
payment = create :credit_card_payment
|
97
|
+
payment_source = payment.source
|
98
|
+
payment_method = payment.payment_method
|
99
|
+
|
100
|
+
subscription = create :subscription, user: payment.order.user
|
101
|
+
subscription_params = {
|
102
|
+
subscription: {
|
103
|
+
payment_method_id: payment_method.id,
|
104
|
+
payment_source_id: payment_source.id,
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
put spree.admin_subscription_path(subscription), params: subscription_params
|
109
|
+
|
110
|
+
expect(subscription.reload.payment_source).to eq(payment_source)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe 'POST cancel' do
|
116
|
+
subject(:delete_subscription) { delete spree.cancel_admin_subscription_path(subscription) }
|
117
|
+
|
118
|
+
context 'when the subscription can be canceled' do
|
119
|
+
let(:subscription) { create :subscription, :actionable }
|
120
|
+
|
121
|
+
it { is_expected.to redirect_to spree.admin_subscriptions_path }
|
122
|
+
|
123
|
+
it 'has a message' do
|
124
|
+
delete_subscription
|
125
|
+
expect(flash[:notice]).to be_present
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'cancels the subscription' do
|
129
|
+
expect { delete_subscription }.to change { subscription.reload.state }.from('active').to('canceled')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'when the subscription cannot be canceled' do
|
134
|
+
let(:subscription) { create :subscription, :canceled }
|
135
|
+
|
136
|
+
it { is_expected.to redirect_to spree.admin_subscriptions_path }
|
137
|
+
|
138
|
+
it 'has a message' do
|
139
|
+
delete_subscription
|
140
|
+
expect(flash[:notice]).to be_present
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'cancels the subscription' do
|
144
|
+
expect { delete_subscription }.not_to(change { subscription.reload.state })
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe 'POST activate' do
|
150
|
+
subject(:activate) { post spree.activate_admin_subscription_path(subscription) }
|
151
|
+
|
152
|
+
context 'when the subscription can be activated' do
|
153
|
+
let(:subscription) { create :subscription, :canceled, :with_line_item }
|
154
|
+
|
155
|
+
it { is_expected.to redirect_to spree.admin_subscriptions_path }
|
156
|
+
|
157
|
+
it 'has a message' do
|
158
|
+
activate
|
159
|
+
expect(flash[:notice]).to be_present
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'cancels the subscription' do
|
163
|
+
expect { activate }.to change { subscription.reload.state }.from('canceled').to('active')
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'when the subscription cannot be activated' do
|
168
|
+
let(:subscription) { create :subscription, :actionable, :with_line_item }
|
169
|
+
|
170
|
+
it { is_expected.to redirect_to spree.admin_subscriptions_path }
|
171
|
+
|
172
|
+
it 'has a message' do
|
173
|
+
activate
|
174
|
+
expect(flash[:notice]).to be_present
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'cancels the subscription' do
|
178
|
+
expect { activate }.not_to(change{ subscription.reload.state })
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe 'POST skip' do
|
184
|
+
subject(:skip) { post spree.skip_admin_subscription_path(subscription) }
|
185
|
+
|
186
|
+
let(:subscription) { create :subscription, :actionable, :with_line_item }
|
187
|
+
let!(:expected_date) { subscription.next_actionable_date }
|
188
|
+
|
189
|
+
it { is_expected.to redirect_to spree.admin_subscriptions_path }
|
190
|
+
|
191
|
+
it 'has a message' do
|
192
|
+
skip
|
193
|
+
expect(flash[:notice]).to be_present
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'advances the actionable_date' do
|
197
|
+
expect { skip }.
|
198
|
+
to change { subscription.reload.actionable_date }.
|
199
|
+
from(subscription.actionable_date).to(expected_date)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'spree/api/testing_support/helpers'
|
5
|
+
|
6
|
+
RSpec.describe Spree::Api::LineItemsController, type: :controller do
|
7
|
+
include Spree::Api::TestingSupport::Helpers
|
8
|
+
routes { Spree::Core::Engine.routes }
|
9
|
+
|
10
|
+
describe 'POST :create' do
|
11
|
+
subject(:post_create) { post :create, params: params }
|
12
|
+
|
13
|
+
let(:params) { line_item_params }
|
14
|
+
let!(:variant) { create :variant }
|
15
|
+
let!(:order) { create :order }
|
16
|
+
|
17
|
+
let(:line_item_params) do
|
18
|
+
{
|
19
|
+
order_id: order.number,
|
20
|
+
order_token: order.guest_token,
|
21
|
+
format: 'json',
|
22
|
+
line_item: {
|
23
|
+
quantity: 1,
|
24
|
+
variant_id: variant.id
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
shared_examples 'a new line item' do
|
30
|
+
it { is_expected.to be_created }
|
31
|
+
|
32
|
+
it 'creates a line item' do
|
33
|
+
expect { post_create }.
|
34
|
+
to change { Spree::LineItem.count }.
|
35
|
+
from(0).to(1)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with subscription_line_item params' do
|
40
|
+
let(:params) { line_item_params.merge(subscription_line_item_params) }
|
41
|
+
let(:subscription_line_item_params) do
|
42
|
+
{
|
43
|
+
subscription_line_item: {
|
44
|
+
quantity: 2,
|
45
|
+
end_date: '1990/10/12',
|
46
|
+
subscribable_id: variant.id,
|
47
|
+
interval_length: 30,
|
48
|
+
interval_units: "day"
|
49
|
+
}
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
it_behaves_like 'a new line item'
|
54
|
+
|
55
|
+
it 'creates a new subscription line item' do
|
56
|
+
expect { post_create }.
|
57
|
+
to change { SolidusSubscriptions::LineItem.count }.
|
58
|
+
from(0).to(1)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'without subscription_line_item params' do
|
63
|
+
it_behaves_like 'a new line item'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'patch :update' do
|
68
|
+
subject(:patch_create) { patch :create, params: params }
|
69
|
+
|
70
|
+
let(:params) { line_item_params }
|
71
|
+
let!(:variant) { create :variant }
|
72
|
+
let!(:order) { create :order }
|
73
|
+
let!(:line_item) { create :line_item, order: order, variant: variant }
|
74
|
+
|
75
|
+
let(:line_item_params) do
|
76
|
+
{
|
77
|
+
id: line_item.id,
|
78
|
+
order_id: order.number,
|
79
|
+
order_token: order.guest_token,
|
80
|
+
format: 'json',
|
81
|
+
line_item: {
|
82
|
+
quantity: 1,
|
83
|
+
variant_id: variant.id
|
84
|
+
},
|
85
|
+
subscription_line_item: {
|
86
|
+
quantity: 2,
|
87
|
+
end_date: '1990/10/12',
|
88
|
+
subscribable_id: variant.id,
|
89
|
+
interval_length: 30,
|
90
|
+
interval_units: "day"
|
91
|
+
}
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
it { is_expected.to be_successful }
|
96
|
+
|
97
|
+
it 'creates a new subscription line item' do
|
98
|
+
expect { patch_create }.
|
99
|
+
to change { SolidusSubscriptions::LineItem.count }.
|
100
|
+
from(0).to(1)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'spree/api/testing_support/helpers'
|
5
|
+
|
6
|
+
RSpec.describe Spree::Api::OrdersController, type: :controller do
|
7
|
+
include Spree::Api::TestingSupport::Helpers
|
8
|
+
routes { Spree::Core::Engine.routes }
|
9
|
+
|
10
|
+
let(:order) { create :order }
|
11
|
+
let(:variant) { create :variant }
|
12
|
+
|
13
|
+
describe 'patch /update' do
|
14
|
+
subject(:subscription_line_items) do
|
15
|
+
patch :update, params: params
|
16
|
+
order.subscription_line_items.reload
|
17
|
+
end
|
18
|
+
|
19
|
+
before { stub_authentication! }
|
20
|
+
|
21
|
+
let(:params) do
|
22
|
+
{
|
23
|
+
order: { line_items_attributes: [line_items_params] },
|
24
|
+
id: order.to_param,
|
25
|
+
format: 'json',
|
26
|
+
order_token: order.guest_token
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:line_items_params) do
|
31
|
+
{
|
32
|
+
variant_id: variant.id,
|
33
|
+
quantity: 1,
|
34
|
+
subscription_line_items_attributes: [subscription_line_items_params]
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:subscription_line_items_params) do
|
39
|
+
{
|
40
|
+
quantity: 1,
|
41
|
+
subscribable_id: variant.id,
|
42
|
+
interval_length: 30,
|
43
|
+
interval_units: "day"
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'is a successful response' do
|
48
|
+
subscription_line_items
|
49
|
+
expect(response).to be_successful
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'create the correct number of subscription line items' do
|
53
|
+
expect(subscription_line_items.length).
|
54
|
+
to eq line_items_params[:subscription_line_items_attributes].length
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'spree/api/testing_support/helpers'
|
5
|
+
|
6
|
+
RSpec.describe Spree::Api::UsersController, type: :controller do
|
7
|
+
include Spree::Api::TestingSupport::Helpers
|
8
|
+
routes { Spree::Core::Engine.routes }
|
9
|
+
|
10
|
+
let!(:user) do
|
11
|
+
create(:user, &:generate_spree_api_key).tap(&:save)
|
12
|
+
end
|
13
|
+
let!(:subscription) { create :subscription, :with_line_item, user: user }
|
14
|
+
|
15
|
+
describe 'patch /update' do
|
16
|
+
subject(:update_user) { patch :update, params: params }
|
17
|
+
|
18
|
+
let(:params) do
|
19
|
+
{
|
20
|
+
id: user.id,
|
21
|
+
token: user.spree_api_key,
|
22
|
+
format: 'json',
|
23
|
+
user: {
|
24
|
+
subscriptions_attributes: [{
|
25
|
+
id: subscription.id,
|
26
|
+
line_items_attributes: [line_item_attributes]
|
27
|
+
}]
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:line_item_attributes) do
|
33
|
+
{
|
34
|
+
id: subscription.line_item_ids.first,
|
35
|
+
quantity: 6,
|
36
|
+
interval_length: 1,
|
37
|
+
interval_units: 'month'
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'updates the subscription line items' do
|
42
|
+
update_user
|
43
|
+
line_item = subscription.line_items.reload.first
|
44
|
+
|
45
|
+
expect(line_item).to have_attributes(line_item_attributes)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|