solidus_subscriptions 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +41 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.github_changelog_generator +2 -0
  6. data/.gitignore +20 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +12 -0
  9. data/.rubocop_todo.yml +86 -0
  10. data/CHANGELOG.md +191 -0
  11. data/Gemfile +33 -0
  12. data/LICENSE +26 -0
  13. data/README.md +221 -0
  14. data/Rakefile +6 -0
  15. data/app/assets/javascripts/spree/backend/solidus_subscriptions.js +1 -0
  16. data/app/assets/javascripts/spree/backend/solidus_subscriptions/edit_subscription_payment.js +32 -0
  17. data/app/controllers/solidus_subscriptions/api/v1/base_controller.rb +13 -0
  18. data/app/controllers/solidus_subscriptions/api/v1/line_items_controller.rb +48 -0
  19. data/app/controllers/solidus_subscriptions/api/v1/subscriptions_controller.rb +100 -0
  20. data/app/controllers/spree/admin/installments_controller.rb +25 -0
  21. data/app/controllers/spree/admin/subscription_events_controller.rb +37 -0
  22. data/app/controllers/spree/admin/subscription_orders_controller.rb +35 -0
  23. data/app/controllers/spree/admin/subscriptions_controller.rb +100 -0
  24. data/app/controllers/spree/admin/users/subscriptions_controller.rb +17 -0
  25. data/app/decorators/controllers/solidus_subscriptions/spree/api/line_items_controller/create_subscription_line_items.rb +36 -0
  26. data/app/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb +35 -0
  27. data/app/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association.rb +26 -0
  28. data/app/decorators/models/solidus_subscriptions/spree/order/after_create.rb +19 -0
  29. data/app/decorators/models/solidus_subscriptions/spree/order/finalize_creates_subscriptions.rb +23 -0
  30. data/app/decorators/models/solidus_subscriptions/spree/order/installment_details_association.rb +15 -0
  31. data/app/decorators/models/solidus_subscriptions/spree/order/subscription_association.rb +15 -0
  32. data/app/decorators/models/solidus_subscriptions/spree/order/subscription_line_items_association.rb +19 -0
  33. data/app/decorators/models/solidus_subscriptions/spree/product/delegate_subscribable.rb +17 -0
  34. data/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb +30 -0
  35. data/app/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions.rb +20 -0
  36. data/app/decorators/models/solidus_subscriptions/spree/variant/variant_pretty_name.rb +17 -0
  37. data/app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb +28 -0
  38. data/app/jobs/solidus_subscriptions/process_installment_job.rb +13 -0
  39. data/app/jobs/solidus_subscriptions/process_subscription_job.rb +31 -0
  40. data/app/models/solidus_subscriptions/installment.rb +135 -0
  41. data/app/models/solidus_subscriptions/installment_detail.rb +28 -0
  42. data/app/models/solidus_subscriptions/interval.rb +26 -0
  43. data/app/models/solidus_subscriptions/line_item.rb +42 -0
  44. data/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb +44 -0
  45. data/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb +31 -0
  46. data/app/models/solidus_subscriptions/subscription.rb +392 -0
  47. data/app/models/solidus_subscriptions/subscription_event.rb +11 -0
  48. data/app/overrides/views/admin_subscribable_product_checkbox.rb +8 -0
  49. data/app/overrides/views/admin_subscribable_variant_checkbox.rb +8 -0
  50. data/app/overrides/views/admin_subscriptions_menu_link.rb +10 -0
  51. data/app/overrides/views/admin_users_subscriptions_tab.rb +8 -0
  52. data/app/overrides/views/subscription_line_item_fields.rb +8 -0
  53. data/app/subscribers/solidus_subscriptions/churn_buster_subscriber.rb +39 -0
  54. data/app/subscribers/solidus_subscriptions/event_storage_subscriber.rb +64 -0
  55. data/app/views/spree/admin/installments/_state_pill.html.erb +8 -0
  56. data/app/views/spree/admin/installments/index.html.erb +42 -0
  57. data/app/views/spree/admin/products/_subscribable_checkbox.html.erb +8 -0
  58. data/app/views/spree/admin/promotions/rules/_subscription_creation_order.html.erb +0 -0
  59. data/app/views/spree/admin/promotions/rules/_subscription_installment_order.html.erb +0 -0
  60. data/app/views/spree/admin/shared/_subscription_actions.html.erb +35 -0
  61. data/app/views/spree/admin/shared/_subscription_breadcrumbs.html.erb +4 -0
  62. data/app/views/spree/admin/shared/_subscription_sidebar.html.erb +18 -0
  63. data/app/views/spree/admin/shared/_subscription_tab.html.erb +3 -0
  64. data/app/views/spree/admin/shared/_subscription_tabs.html.erb +18 -0
  65. data/app/views/spree/admin/subscription_events/_state_pill.html.erb +8 -0
  66. data/app/views/spree/admin/subscription_events/index.html.erb +42 -0
  67. data/app/views/spree/admin/subscription_orders/index.html.erb +93 -0
  68. data/app/views/spree/admin/subscriptions/_form.html.erb +150 -0
  69. data/app/views/spree/admin/subscriptions/_processing_state_pill.html.erb +9 -0
  70. data/app/views/spree/admin/subscriptions/_state_pill.html.erb +10 -0
  71. data/app/views/spree/admin/subscriptions/edit.html.erb +10 -0
  72. data/app/views/spree/admin/subscriptions/index.html.erb +176 -0
  73. data/app/views/spree/admin/subscriptions/new.html.erb +5 -0
  74. data/app/views/spree/admin/users/_subscription_tab.html.erb +5 -0
  75. data/app/views/spree/admin/users/subscriptions/index.html.erb +44 -0
  76. data/app/views/spree/admin/variants/_subscribable_checkbox.html.erb +6 -0
  77. data/app/views/spree/frontend/products/_subscription_line_item_fields.html.erb +30 -0
  78. data/bin/console +17 -0
  79. data/bin/rails +7 -0
  80. data/bin/rails-engine +13 -0
  81. data/bin/rails-sandbox +16 -0
  82. data/bin/rake +7 -0
  83. data/bin/sandbox +86 -0
  84. data/bin/setup +8 -0
  85. data/config/initializers/permission_sets.rb +11 -0
  86. data/config/initializers/subscribers.rb +9 -0
  87. data/config/locales/en.yml +129 -0
  88. data/config/routes.rb +34 -0
  89. data/db/migrate/20160825164850_create_solidus_subscriptions_subscriptions.rb +11 -0
  90. data/db/migrate/20160825173548_create_solidus_subscriptions_line_items.rb +17 -0
  91. data/db/migrate/20160825202248_create_solidus_subscriptions_installments.rb +23 -0
  92. data/db/migrate/20160825211202_create_solidus_subscriptions_installment_details.rb +22 -0
  93. data/db/migrate/20160825214240_add_subscribable_to_spree_variants.rb +5 -0
  94. data/db/migrate/20160829201653_change_subscription_line_items_installments_to_max_installments.rb +5 -0
  95. data/db/migrate/20160902220242_remove_state_from_solidus_susbscriptions_installment_details.rb +5 -0
  96. data/db/migrate/20160902220604_add_successful_to_solidus_subscriptions_installment_details.rb +5 -0
  97. data/db/migrate/20160902221218_add_message_to_solidus_subscriptions_installment_details.rb +5 -0
  98. data/db/migrate/20160922164101_add_interval_length_and_units_to_subscription_line_items.rb +8 -0
  99. data/db/migrate/20161006191003_add_skip_count_to_solidus_subscriptions_subscriptions.rb +5 -0
  100. data/db/migrate/20161006191127_add_successive_skip_count_to_solidus_subscriptions_subscriptions.rb +5 -0
  101. data/db/migrate/20161014212649_allow_spree_line_item_id_to_be_null.rb +5 -0
  102. data/db/migrate/20161017155749_add_order_id_to_solidus_subscriptions_installment_details.rb +6 -0
  103. data/db/migrate/20161017175509_remove_order_id_from_solidus_subscriptions_installments.rb +5 -0
  104. data/db/migrate/20161017201944_add_subscription_order_to_spree_orders.rb +5 -0
  105. data/db/migrate/20161221155142_add_store_to_solidus_subscriptions_subscriptions.rb +6 -0
  106. data/db/migrate/20161223152905_add_address_id_to_solidus_subscriptions_subscriptions.rb +7 -0
  107. data/db/migrate/20170106224713_change_line_item_max_installments_to_end_date.rb +6 -0
  108. data/db/migrate/20170111224458_change_subscription_actionable_date_to_datetime.rb +5 -0
  109. data/db/migrate/20170111232801_change_inteval_actionable_date_to_datetime.rb +5 -0
  110. data/db/migrate/20170112012407_add_config_options_to_subscriptions.rb +7 -0
  111. data/db/migrate/20200617102749_add_billing_address_to_subscriptions.rb +11 -0
  112. data/db/migrate/20200617155042_add_payment_source_to_subscriptions.rb +6 -0
  113. data/db/migrate/20200618092951_add_payment_method_to_subscriptions.rb +11 -0
  114. data/db/migrate/20200730101242_create_solidus_subscriptions_subscription_events.rb +22 -0
  115. data/db/migrate/20200917072152_add_subscription_reference_to_orders.rb +11 -0
  116. data/db/migrate/20201007140032_add_guest_token_to_subscriptions.rb +6 -0
  117. data/db/migrate/20201123171026_change_actionable_date_to_date.rb +15 -0
  118. data/db/migrate/20210205140422_add_currency_to_subscription.rb +5 -0
  119. data/db/migrate/20210323165714_update_promotion_rule_names.rb +22 -0
  120. data/lib/generators/solidus_subscriptions/install/install_generator.rb +32 -0
  121. data/lib/generators/solidus_subscriptions/install/templates/initializer.rb +99 -0
  122. data/lib/solidus_subscriptions.rb +49 -0
  123. data/lib/solidus_subscriptions/checkout.rb +74 -0
  124. data/lib/solidus_subscriptions/churn_buster/client.rb +48 -0
  125. data/lib/solidus_subscriptions/churn_buster/order_serializer.rb +19 -0
  126. data/lib/solidus_subscriptions/churn_buster/serializer.rb +23 -0
  127. data/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb +28 -0
  128. data/lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb +37 -0
  129. data/lib/solidus_subscriptions/churn_buster/subscription_serializer.rb +17 -0
  130. data/lib/solidus_subscriptions/configuration.rb +84 -0
  131. data/lib/solidus_subscriptions/dispatcher/base.rb +18 -0
  132. data/lib/solidus_subscriptions/dispatcher/failure_dispatcher.rb +13 -0
  133. data/lib/solidus_subscriptions/dispatcher/out_of_stock_dispatcher.rb +11 -0
  134. data/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb +19 -0
  135. data/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb +17 -0
  136. data/lib/solidus_subscriptions/engine.rb +56 -0
  137. data/lib/solidus_subscriptions/permission_sets/default_customer.rb +19 -0
  138. data/lib/solidus_subscriptions/permission_sets/subscription_management.rb +12 -0
  139. data/lib/solidus_subscriptions/permitted_attributes.rb +20 -0
  140. data/lib/solidus_subscriptions/processor.rb +17 -0
  141. data/lib/solidus_subscriptions/subscription_generator.rb +77 -0
  142. data/lib/solidus_subscriptions/subscription_line_item_builder.rb +23 -0
  143. data/lib/solidus_subscriptions/testing_support/factories/installment_detail_factory.rb +11 -0
  144. data/lib/solidus_subscriptions/testing_support/factories/installment_factory.rb +29 -0
  145. data/lib/solidus_subscriptions/testing_support/factories/line_item_factory.rb +20 -0
  146. data/lib/solidus_subscriptions/testing_support/factories/spree/line_item_factory.rb +17 -0
  147. data/lib/solidus_subscriptions/testing_support/factories/spree/order_factory.rb +17 -0
  148. data/lib/solidus_subscriptions/testing_support/factories/spree_modification_factory.rb +10 -0
  149. data/lib/solidus_subscriptions/testing_support/factories/subscription_event_factory.rb +8 -0
  150. data/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb +56 -0
  151. data/lib/solidus_subscriptions/version.rb +5 -0
  152. data/lib/tasks/process_subscriptions.rake +8 -0
  153. data/reference/solidus_subscriptions.v1.yaml +290 -0
  154. data/solidus_subscriptions.gemspec +47 -0
  155. data/spec/controllers/spree/admin/subscriptions_controller_spec.rb +202 -0
  156. data/spec/controllers/spree/api/line_items_controller_spec.rb +103 -0
  157. data/spec/controllers/spree/api/orders_controller_spec.rb +57 -0
  158. data/spec/controllers/spree/api/users_controller_spec.rb +48 -0
  159. data/spec/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items_spec.rb +80 -0
  160. data/spec/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association_spec.rb +10 -0
  161. data/spec/decorators/models/solidus_subscriptions/spree/order/finalize_creates_subscriptions_spec.rb +32 -0
  162. data/spec/decorators/models/solidus_subscriptions/spree/order/installment_details_association_spec.rb +9 -0
  163. data/spec/decorators/models/solidus_subscriptions/spree/order/subscription_line_items_association_spec.rb +9 -0
  164. data/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb +22 -0
  165. data/spec/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions_spec.rb +25 -0
  166. data/spec/features/admin/subscription_orders_spec.rb +35 -0
  167. data/spec/features/admin/subscriptions_spec.rb +63 -0
  168. data/spec/features/admin_users_subscription_tabs_spec.rb +61 -0
  169. data/spec/fixtures/cassettes/churn_buster.yml +229 -0
  170. data/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb +38 -0
  171. data/spec/jobs/solidus_subscriptions/process_subscription_job_spec.rb +83 -0
  172. data/spec/lib/solidus_subscriptions/checkout_spec.rb +125 -0
  173. data/spec/lib/solidus_subscriptions/churn_buster/client_spec.rb +59 -0
  174. data/spec/lib/solidus_subscriptions/dispatcher/failure_dispatcher_spec.rb +29 -0
  175. data/spec/lib/solidus_subscriptions/dispatcher/out_of_stock_dispatcher_spec.rb +15 -0
  176. data/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb +44 -0
  177. data/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb +30 -0
  178. data/spec/lib/solidus_subscriptions/permission_sets/default_customer_spec.rb +95 -0
  179. data/spec/lib/solidus_subscriptions/permission_sets/subscription_management_spec.rb +26 -0
  180. data/spec/lib/solidus_subscriptions/processor_spec.rb +34 -0
  181. data/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb +57 -0
  182. data/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb +39 -0
  183. data/spec/lib/solidus_subscriptions/subscription_generator_spec.rb +83 -0
  184. data/spec/lib/solidus_subscriptions_spec.rb +30 -0
  185. data/spec/models/solidus_subscriptions/installment_detail_spec.rb +23 -0
  186. data/spec/models/solidus_subscriptions/installment_spec.rb +201 -0
  187. data/spec/models/solidus_subscriptions/line_item_spec.rb +29 -0
  188. data/spec/models/solidus_subscriptions/subscription_spec.rb +814 -0
  189. data/spec/models/spree/variant_spec.rb +16 -0
  190. data/spec/models/spree/wallet_payment_source_spec.rb +20 -0
  191. data/spec/requests/api/v1/line_items_spec.rb +116 -0
  192. data/spec/requests/api/v1/subscriptions_spec.rb +255 -0
  193. data/spec/spec_helper.rb +30 -0
  194. data/spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb +76 -0
  195. data/spec/support/active_model_mocks.rb +1 -0
  196. data/spec/support/cancancan.rb +1 -0
  197. data/spec/support/factories.rb +1 -0
  198. data/spec/support/helpers/checkout_infrastructure.rb +18 -0
  199. data/spec/support/helpers/config.rb +13 -0
  200. data/spec/support/shoulda.rb +7 -0
  201. data/spec/support/timecop.rb +1 -0
  202. data/spec/support/vcr.rb +10 -0
  203. data/spec/support/version_cake.rb +8 -0
  204. metadata +498 -0
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe SolidusSubscriptions::Spree::OrdersController::CreateSubscriptionLineItems, type: :controller do
6
+ controller(Spree::OrdersController) {}
7
+ routes { Spree::Core::Engine.routes }
8
+
9
+ let!(:user) { create :user }
10
+
11
+ before do
12
+ allow(controller).to receive_messages(try_spree_current_user: user)
13
+ create :store
14
+ end
15
+
16
+ describe 'POST /orders/populate' do
17
+ subject(:populate) { post :populate, params: params }
18
+
19
+ let!(:variant) { create :variant }
20
+ let(:params) { line_item_params }
21
+ let(:line_item_params) do
22
+ {
23
+ quantity: 1,
24
+ variant_id: variant.id
25
+ }
26
+ end
27
+
28
+ shared_examples 'a new order line item' do
29
+ it { is_expected.to redirect_to cart_path }
30
+
31
+ it 'creates an order' do
32
+ expect { populate }.
33
+ to change { Spree::Order.count }.
34
+ from(0).to(1)
35
+ end
36
+
37
+ it 'creates a line item' do
38
+ expect { populate }.
39
+ to change { Spree::LineItem.count }.
40
+ from(0).to(1)
41
+ end
42
+ end
43
+
44
+ context 'with subscription_line_item params' do
45
+ let(:params) { line_item_params.merge(subscription_line_item_params) }
46
+ let(:subscription_line_item_params) do
47
+ {
48
+ subscription_line_item: {
49
+ quantity: 2,
50
+ end_date: Date.parse('2000/10/11'),
51
+ subscribable_id: variant.id,
52
+ interval_length: 30,
53
+ interval_units: "day"
54
+ }
55
+ }
56
+ end
57
+
58
+ it_behaves_like 'a new order line item'
59
+
60
+ it 'creates a new subscription line item' do
61
+ expect { populate }.
62
+ to change { SolidusSubscriptions::LineItem.count }.
63
+ from(0).to(1)
64
+ end
65
+
66
+ it 'creates a subscription line item with the correct values' do
67
+ populate
68
+ subscription_line_item = SolidusSubscriptions::LineItem.last
69
+
70
+ expect(subscription_line_item).to have_attributes(
71
+ subscription_line_item_params[:subscription_line_item]
72
+ )
73
+ end
74
+ end
75
+
76
+ context 'without subscription_line_item params' do
77
+ it_behaves_like 'a new order line item'
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe SolidusSubscriptions::Spree::LineItem::SubscriptionLineItemsAssociation, type: :model do
6
+ subject { Spree::LineItem.new }
7
+
8
+ it { is_expected.to have_many :subscription_line_items }
9
+ it { is_expected.to accept_nested_attributes_for :subscription_line_items }
10
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe SolidusSubscriptions::Spree::Order::FinalizeCreatesSubscriptions do
6
+ describe '#finalize!' do
7
+ subject(:finalize) { order.finalize! }
8
+
9
+ let(:order) { create :order, :with_subscription_line_items }
10
+ let(:subscription_line_item) { order.subscription_line_items.last }
11
+ let(:expected_actionable_date) { Time.zone.today + subscription_line_item.interval }
12
+
13
+ around { |e| Timecop.freeze { e.run } }
14
+
15
+ it 'creates new subscriptions' do
16
+ expect { finalize }.
17
+ to change { SolidusSubscriptions::Subscription.count }.
18
+ by(order.subscription_line_items.count)
19
+ end
20
+
21
+ it 'creates a subscription with the correct values' do
22
+ finalize
23
+ subscription = SolidusSubscriptions::Subscription.last
24
+
25
+ expect(subscription).to have_attributes(
26
+ user_id: order.user_id,
27
+ actionable_date: expected_actionable_date,
28
+ line_items: [subscription_line_item]
29
+ )
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe SolidusSubscriptions::Spree::Order::InstallmentDetailsAssociation, type: :model do
6
+ subject { Spree::Order.new }
7
+
8
+ it { is_expected.to have_many :installment_details }
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe SolidusSubscriptions::Spree::Order::SubscriptionLineItemsAssociation, type: :model do
6
+ subject { Spree::Order.new }
7
+
8
+ it { is_expected.to have_many :subscription_line_items }
9
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe SolidusSubscriptions::Spree::User::HaveManySubscriptions, type: :model do
6
+ subject(:user) { Spree::User.new }
7
+
8
+ it { is_expected.to have_many :subscriptions }
9
+ it { is_expected.to accept_nested_attributes_for :subscriptions }
10
+
11
+ describe '#subscriptions_attributes=' do
12
+ it 'throws a deprecation warning' do
13
+ allow(::Spree::Deprecation).to receive(:warn)
14
+
15
+ user.subscriptions_attributes = [{ interval_length: 2 }]
16
+
17
+ expect(::Spree::Deprecation)
18
+ .to have_received(:warn)
19
+ .with(/Creating or updating subscriptions through Spree::User nested attributes is deprecated/)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe SolidusSubscriptions::Spree::Variant::AutoDeleteFromSubscriptions, type: :model do
6
+ subject { create(:variant, subscribable: true) }
7
+
8
+ describe '.discard' do
9
+ it 'deletes itself from subscriptions' do
10
+ subscription = create(:subscription)
11
+ create(:subscription_line_item, subscription: subscription, subscribable: subject)
12
+
13
+ expect { subject.discard }.to change { SolidusSubscriptions::LineItem.count }.by(-1)
14
+ end
15
+ end
16
+
17
+ describe '.destroy' do
18
+ it 'deletes itself from subscriptions' do
19
+ subscription = create(:subscription)
20
+ create(:subscription_line_item, subscription: subscription, subscribable: subject)
21
+
22
+ expect { subject.destroy }.to change { SolidusSubscriptions::LineItem.count }.by(-1)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'Subscription orders admin' do
4
+ stub_authorization!
5
+
6
+ let(:subscription) { create(:subscription, :with_shipping_address, :with_billing_address) }
7
+
8
+ before do
9
+ visit spree.edit_admin_subscription_path(subscription)
10
+ within('.tabs') { click_link 'Orders' }
11
+ end
12
+
13
+ it 'shows a No orders messages' do
14
+ expect(page).to have_css('legend', text: 'Orders')
15
+ expect(page).to have_content(/No orders found/i)
16
+ end
17
+
18
+ context 'with some orders' do
19
+ let(:orders) { build_list(:order, 3, subscription_order: true) }
20
+ let(:subscription) do
21
+ create(:subscription, :with_shipping_address, :with_billing_address).tap do |subscription|
22
+ subscription.orders << orders
23
+ end
24
+ end
25
+
26
+ it 'lists the orders of a subscription' do
27
+ expect(page).to have_css('.admin_subscription_order', count: orders.size)
28
+ within('#listing_subscription_orders') do
29
+ orders.each do |order|
30
+ expect(page).to have_content(order.number)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'Subscriptions admin' do
4
+ stub_authorization!
5
+
6
+ let(:shipping_address_fieldset) { 'Shipping Address' }
7
+ let(:billing_address_fieldset) { 'Billing Address' }
8
+
9
+ it 'Updating a subscription' do
10
+ subscription = create(:subscription, :with_shipping_address, :with_billing_address)
11
+
12
+ visit spree.admin_path
13
+ click_link 'Subscriptions'
14
+ find('.fa-edit').click
15
+ within_fieldset(shipping_address_fieldset) do
16
+ fill_in 'Zip Code', with: '33166'
17
+ end
18
+ within_fieldset(billing_address_fieldset) do
19
+ fill_in 'Zip Code', with: '33167'
20
+ end
21
+ click_button 'Update'
22
+ subscription.reload
23
+
24
+ expect(subscription.shipping_address.zipcode).to eq('33166')
25
+ expect(subscription.billing_address.zipcode).to eq('33167')
26
+ end
27
+
28
+ it 'Creates a subscription' do
29
+ variant = create(:variant, subscribable: true)
30
+ create(:user)
31
+ create(:store)
32
+
33
+ visit spree.admin_path
34
+ click_link 'Subscriptions'
35
+ click_link 'New Subscription'
36
+ fill_in 'Actionable date', with: '01/01/2020'
37
+ fill_in 'Interval length', with: 2
38
+ fill_in 'End date', with: '01/03/2020'
39
+
40
+ [shipping_address_fieldset, billing_address_fieldset].each do |fieldset|
41
+ within_fieldset(fieldset) do
42
+ name_input_label = if Spree.solidus_gem_version >= Gem::Version.new('2.11.0')
43
+ 'Name'
44
+ else
45
+ 'First Name'
46
+ end
47
+
48
+ fill_in name_input_label, with: 'John Doe'
49
+ fill_in 'Street Address', with: 'Street Address'
50
+ fill_in 'City', with: 'City'
51
+ fill_in 'Zip Code', with: '33166'
52
+ fill_in 'Phone', with: '1234567890'
53
+ end
54
+ end
55
+
56
+ select variant.name, from: 'Subscribable'
57
+ fill_in 'Quantity', with: 1
58
+
59
+ expect { click_on 'Create' }.to change { SolidusSubscriptions::Subscription.count }.by(1)
60
+
61
+ expect(page).to have_text('Subscription has been successfully created!')
62
+ end
63
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'User subscriptions tab', type: :feature do
6
+ stub_authorization!
7
+
8
+ let(:user) { create(:user) }
9
+
10
+ before do
11
+ allow(Spree.user_class).to receive(:find_by).
12
+ with(hash_including(:id)).
13
+ and_return(user)
14
+ end
15
+
16
+ context 'when user has subscriptions' do
17
+ let!(:subscription) {
18
+ create(:subscription,
19
+ actionable_date: '2020-10-21',
20
+ interval_length: 10,
21
+ interval_units: :day,
22
+ user: user)
23
+ }
24
+
25
+ before do
26
+ visit '/admin/'
27
+ click_link 'Users'
28
+ click_link subscription.user.email
29
+ within('.tabs') { click_link 'Subscriptions' }
30
+ end
31
+
32
+ it 'lists user subscriptions date' do
33
+ subscriptions_table = page.find('#subscriptions-table')
34
+
35
+ expect(subscriptions_table).to have_content('2020-10-21')
36
+ end
37
+
38
+ it 'lists user subscriptions days' do
39
+ subscriptions_table = page.find('#subscriptions-table')
40
+
41
+ expect(subscriptions_table).to have_content('10 days')
42
+ end
43
+
44
+ it 'shows edit link to subscriptions' do
45
+ page.find("#subscriptions-table td.actions a.fa-edit").click
46
+
47
+ expect(page).to have_current_path spree.edit_admin_subscription_path(subscription), ignore_query: true
48
+ end
49
+ end
50
+
51
+ context 'when user does not have subscriptions' do
52
+ it 'displays no found message when user has no subscriptions' do
53
+ visit spree.admin_path
54
+ click_link 'Users'
55
+ click_link user.email
56
+ within('.tabs') { click_link 'Subscriptions' }
57
+
58
+ expect(page).to have_content('No Subscriptions found.')
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,229 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.churnbuster.io/v1/successful_payments
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"payment":{"source":"in_house","source_id":"R863897282","amount_in_cents":0,"currency":"USD"},"customer":{"source":"in_house","source_id":1,"email":"email2@example.com","properties":{"first_name":"John","last_name":"John"}}}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Date:
26
+ - Thu, 01 Oct 2020 13:46:09 GMT
27
+ Connection:
28
+ - keep-alive
29
+ X-Frame-Options:
30
+ - SAMEORIGIN
31
+ X-Xss-Protection:
32
+ - 1; mode=block
33
+ X-Content-Type-Options:
34
+ - nosniff
35
+ X-Download-Options:
36
+ - noopen
37
+ X-Permitted-Cross-Domain-Policies:
38
+ - none
39
+ Referrer-Policy:
40
+ - strict-origin-when-cross-origin
41
+ Content-Type:
42
+ - application/json
43
+ Cache-Control:
44
+ - no-cache
45
+ X-Request-Id:
46
+ - a664eaa0-2735-4a88-990d-fb9c29766e00
47
+ X-Runtime:
48
+ - '0.070480'
49
+ Strict-Transport-Security:
50
+ - max-age=31536000; includeSubDomains
51
+ Transfer-Encoding:
52
+ - chunked
53
+ Via:
54
+ - 1.1 vegur
55
+ body:
56
+ encoding: UTF-8
57
+ string: ''
58
+ recorded_at: Thu, 01 Oct 2020 13:46:09 GMT
59
+ - request:
60
+ method: post
61
+ uri: https://api.churnbuster.io/v1/failed_payments
62
+ body:
63
+ encoding: UTF-8
64
+ string: '{"payment":{"source":"in_house","source_id":"R276044153","amount_in_cents":0,"currency":"USD"},"customer":{"source":"in_house","source_id":1,"email":"email2@example.com","properties":{"first_name":"John","last_name":"John"}}}'
65
+ headers:
66
+ Content-Type:
67
+ - application/json
68
+ Accept-Encoding:
69
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
70
+ Accept:
71
+ - "*/*"
72
+ User-Agent:
73
+ - Ruby
74
+ response:
75
+ status:
76
+ code: 200
77
+ message: OK
78
+ headers:
79
+ Server:
80
+ - Cowboy
81
+ Date:
82
+ - Thu, 01 Oct 2020 14:24:32 GMT
83
+ Connection:
84
+ - keep-alive
85
+ X-Frame-Options:
86
+ - SAMEORIGIN
87
+ X-Xss-Protection:
88
+ - 1; mode=block
89
+ X-Content-Type-Options:
90
+ - nosniff
91
+ X-Download-Options:
92
+ - noopen
93
+ X-Permitted-Cross-Domain-Policies:
94
+ - none
95
+ Referrer-Policy:
96
+ - strict-origin-when-cross-origin
97
+ Content-Type:
98
+ - application/json
99
+ Cache-Control:
100
+ - no-cache
101
+ X-Request-Id:
102
+ - bfd0c00b-dafa-4122-95e3-6fae6676bf05
103
+ X-Runtime:
104
+ - '0.052157'
105
+ Strict-Transport-Security:
106
+ - max-age=31536000; includeSubDomains
107
+ Transfer-Encoding:
108
+ - chunked
109
+ Via:
110
+ - 1.1 vegur
111
+ body:
112
+ encoding: UTF-8
113
+ string: ''
114
+ recorded_at: Thu, 01 Oct 2020 14:24:32 GMT
115
+ - request:
116
+ method: post
117
+ uri: https://api.churnbuster.io/v1/cancellations
118
+ body:
119
+ encoding: UTF-8
120
+ string: '{"subscription":{"source":"in_house","source_id":1},"customer":{"source":"in_house","source_id":1,"email":"email5@example.com","properties":{"first_name":"John","last_name":"Von
121
+ Doe"}}}'
122
+ headers:
123
+ Content-Type:
124
+ - application/json
125
+ Accept-Encoding:
126
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
127
+ Accept:
128
+ - "*/*"
129
+ User-Agent:
130
+ - Ruby
131
+ response:
132
+ status:
133
+ code: 200
134
+ message: OK
135
+ headers:
136
+ Server:
137
+ - Cowboy
138
+ Date:
139
+ - Thu, 01 Oct 2020 14:24:33 GMT
140
+ Connection:
141
+ - keep-alive
142
+ X-Frame-Options:
143
+ - SAMEORIGIN
144
+ X-Xss-Protection:
145
+ - 1; mode=block
146
+ X-Content-Type-Options:
147
+ - nosniff
148
+ X-Download-Options:
149
+ - noopen
150
+ X-Permitted-Cross-Domain-Policies:
151
+ - none
152
+ Referrer-Policy:
153
+ - strict-origin-when-cross-origin
154
+ Content-Type:
155
+ - application/json
156
+ Cache-Control:
157
+ - no-cache
158
+ X-Request-Id:
159
+ - aa57bbfb-aa49-4f4c-bad9-a3e9a87335bd
160
+ X-Runtime:
161
+ - '0.070606'
162
+ Strict-Transport-Security:
163
+ - max-age=31536000; includeSubDomains
164
+ Transfer-Encoding:
165
+ - chunked
166
+ Via:
167
+ - 1.1 vegur
168
+ body:
169
+ encoding: UTF-8
170
+ string: ''
171
+ recorded_at: Thu, 01 Oct 2020 14:24:33 GMT
172
+ - request:
173
+ method: post
174
+ uri: https://api.churnbuster.io/v1/payment_methods
175
+ body:
176
+ encoding: UTF-8
177
+ string: '{"payment_method":{"source":"in_house","source_id":"1-1","type":"card","properties":{}},"customer":{"source":"in_house","source_id":1,"email":"email6@example.com","properties":{"first_name":"John","last_name":"Von
178
+ Doe"}}}'
179
+ headers:
180
+ Content-Type:
181
+ - application/json
182
+ Accept-Encoding:
183
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
184
+ Accept:
185
+ - "*/*"
186
+ User-Agent:
187
+ - Ruby
188
+ response:
189
+ status:
190
+ code: 200
191
+ message: OK
192
+ headers:
193
+ Server:
194
+ - Cowboy
195
+ Date:
196
+ - Mon, 05 Oct 2020 10:55:30 GMT
197
+ Connection:
198
+ - keep-alive
199
+ X-Frame-Options:
200
+ - SAMEORIGIN
201
+ X-Xss-Protection:
202
+ - 1; mode=block
203
+ X-Content-Type-Options:
204
+ - nosniff
205
+ X-Download-Options:
206
+ - noopen
207
+ X-Permitted-Cross-Domain-Policies:
208
+ - none
209
+ Referrer-Policy:
210
+ - strict-origin-when-cross-origin
211
+ Content-Type:
212
+ - application/json
213
+ Cache-Control:
214
+ - no-cache
215
+ X-Request-Id:
216
+ - 585f1c6a-fb36-4cb4-9127-2f80636d33d9
217
+ X-Runtime:
218
+ - '1.184629'
219
+ Strict-Transport-Security:
220
+ - max-age=31536000; includeSubDomains
221
+ Transfer-Encoding:
222
+ - chunked
223
+ Via:
224
+ - 1.1 vegur
225
+ body:
226
+ encoding: UTF-8
227
+ string: ''
228
+ recorded_at: Mon, 05 Oct 2020 10:55:31 GMT
229
+ recorded_with: VCR 6.0.0