spree_api 4.3.0.rc3 → 4.4.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spree/api/v2/caching.rb +7 -3
  3. data/app/controllers/concerns/spree/api/v2/coupon_codes_helper.rb +29 -0
  4. data/app/controllers/concerns/spree/api/v2/number_resource.rb +11 -0
  5. data/app/controllers/concerns/spree/api/v2/platform/nested_set_reposition_concern.rb +37 -0
  6. data/app/controllers/concerns/spree/api/v2/platform/promotion_calculator_params.rb +17 -0
  7. data/app/controllers/concerns/spree/api/v2/platform/promotion_rule_params.rb +16 -0
  8. data/app/controllers/concerns/spree/api/v2/storefront/metadata_controller_concern.rb +18 -0
  9. data/app/controllers/spree/api/v1/checkouts_controller.rb +1 -1
  10. data/app/controllers/spree/api/v2/base_controller.rb +7 -5
  11. data/app/controllers/spree/api/v2/platform/adjustments_controller.rb +19 -0
  12. data/app/controllers/spree/api/v2/platform/classifications_controller.rb +1 -22
  13. data/app/controllers/spree/api/v2/platform/cms_pages_controller.rb +4 -0
  14. data/app/controllers/spree/api/v2/platform/cms_sections_controller.rb +13 -18
  15. data/app/controllers/spree/api/v2/platform/digital_links_controller.rb +25 -0
  16. data/app/controllers/spree/api/v2/platform/digitals_controller.rb +19 -0
  17. data/app/controllers/spree/api/v2/platform/line_items_controller.rb +59 -0
  18. data/app/controllers/spree/api/v2/platform/menu_items_controller.rb +5 -19
  19. data/app/controllers/spree/api/v2/platform/menus_controller.rb +0 -4
  20. data/app/controllers/spree/api/v2/platform/orders_controller.rb +163 -0
  21. data/app/controllers/spree/api/v2/platform/payment_methods_controller.rb +27 -0
  22. data/app/controllers/spree/api/v2/platform/payments_controller.rb +17 -0
  23. data/app/controllers/spree/api/v2/platform/promotion_actions_controller.rb +30 -0
  24. data/app/controllers/spree/api/v2/platform/promotion_categories_controller.rb +19 -0
  25. data/app/controllers/spree/api/v2/platform/promotion_rules_controller.rb +25 -0
  26. data/app/controllers/spree/api/v2/platform/promotions_controller.rb +31 -0
  27. data/app/controllers/spree/api/v2/platform/resource_controller.rb +47 -16
  28. data/app/controllers/spree/api/v2/platform/roles_controller.rb +15 -0
  29. data/app/controllers/spree/api/v2/platform/shipments_controller.rb +143 -0
  30. data/app/controllers/spree/api/v2/platform/shipping_categories_controller.rb +15 -0
  31. data/app/controllers/spree/api/v2/platform/shipping_methods_controller.rb +24 -0
  32. data/app/controllers/spree/api/v2/platform/states_controller.rb +19 -0
  33. data/app/controllers/spree/api/v2/platform/stock_items_controller.rb +19 -0
  34. data/app/controllers/spree/api/v2/platform/stock_locations_controller.rb +19 -0
  35. data/app/controllers/spree/api/v2/platform/store_credit_categories_controller.rb +15 -0
  36. data/app/controllers/spree/api/v2/platform/store_credit_types_controller.rb +15 -0
  37. data/app/controllers/spree/api/v2/platform/store_credits_controller.rb +19 -0
  38. data/app/controllers/spree/api/v2/platform/tax_categories_controller.rb +19 -0
  39. data/app/controllers/spree/api/v2/platform/tax_rates_controller.rb +23 -0
  40. data/app/controllers/spree/api/v2/platform/taxonomies_controller.rb +19 -0
  41. data/app/controllers/spree/api/v2/platform/taxons_controller.rb +25 -0
  42. data/app/controllers/spree/api/v2/platform/users_controller.rb +4 -0
  43. data/app/controllers/spree/api/v2/platform/variants_controller.rb +19 -0
  44. data/app/controllers/spree/api/v2/platform/webhooks/events_controller.rb +21 -0
  45. data/app/controllers/spree/api/v2/platform/webhooks/subscribers_controller.rb +21 -0
  46. data/app/controllers/spree/api/v2/platform/wished_items_controller.rb +19 -0
  47. data/app/controllers/spree/api/v2/platform/wishlists_controller.rb +19 -0
  48. data/app/controllers/spree/api/v2/platform/zones_controller.rb +19 -0
  49. data/app/controllers/spree/api/v2/resource_controller.rb +3 -3
  50. data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +5 -3
  51. data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +4 -1
  52. data/app/controllers/spree/api/v2/storefront/cart_controller.rb +57 -29
  53. data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +24 -0
  54. data/app/controllers/spree/api/v2/storefront/digitals_controller.rb +54 -0
  55. data/app/controllers/spree/api/v2/storefront/products_controller.rb +8 -0
  56. data/app/controllers/spree/api/v2/storefront/wishlists_controller.rb +171 -0
  57. data/app/helpers/spree/api/v2/collection_options_helpers.rb +1 -1
  58. data/app/jobs/spree/webhooks/subscribers/make_request_job.rb +17 -0
  59. data/app/models/concerns/spree/webhooks/has_webhooks.rb +58 -0
  60. data/app/models/spree/api/webhooks/order_decorator.rb +43 -0
  61. data/app/models/spree/api/webhooks/payment_decorator.rb +26 -0
  62. data/app/models/spree/api/webhooks/product_decorator.rb +27 -0
  63. data/app/models/spree/api/webhooks/shipment_decorator.rb +21 -0
  64. data/app/models/spree/api/webhooks/stock_item_decorator.rb +43 -0
  65. data/app/models/spree/api/webhooks/stock_movement_decorator.rb +52 -0
  66. data/app/models/spree/api/webhooks/variant_decorator.rb +26 -0
  67. data/app/models/spree/oauth_access_grant.rb +7 -0
  68. data/app/models/spree/oauth_access_token.rb +7 -0
  69. data/app/models/spree/oauth_application.rb +15 -0
  70. data/app/models/spree/webhooks/base.rb +11 -0
  71. data/app/models/spree/webhooks/event.rb +12 -0
  72. data/app/models/spree/webhooks/subscriber.rb +57 -0
  73. data/app/presenters/spree/api/products/filters_presenter.rb +39 -0
  74. data/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb +19 -1
  75. data/app/serializers/spree/api/v2/base_serializer.rb +11 -4
  76. data/app/serializers/spree/api/v2/platform/address_serializer.rb +1 -1
  77. data/app/serializers/spree/api/v2/platform/adjustment_serializer.rb +20 -0
  78. data/app/serializers/spree/api/v2/platform/asset_serializer.rb +13 -0
  79. data/app/serializers/spree/api/v2/platform/calculator_serializer.rb +17 -0
  80. data/app/serializers/spree/api/v2/platform/classification_serializer.rb +1 -1
  81. data/app/serializers/spree/api/v2/platform/cms_page_serializer.rb +1 -1
  82. data/app/serializers/spree/api/v2/platform/cms_section_serializer.rb +8 -1
  83. data/app/serializers/spree/api/v2/platform/country_serializer.rb +1 -1
  84. data/app/serializers/spree/api/v2/platform/credit_card_serializer.rb +14 -0
  85. data/app/serializers/spree/api/v2/platform/customer_return_serializer.rb +17 -0
  86. data/app/serializers/spree/api/v2/platform/digital_link_serializer.rb +16 -0
  87. data/app/serializers/spree/api/v2/platform/digital_serializer.rb +30 -0
  88. data/app/serializers/spree/api/v2/platform/feature_page_serializer.rb +11 -0
  89. data/app/serializers/spree/api/v2/platform/homepage_serializer.rb +11 -0
  90. data/app/serializers/spree/api/v2/platform/inventory_unit_serializer.rb +19 -0
  91. data/app/serializers/spree/api/v2/platform/line_item_serializer.rb +19 -0
  92. data/app/serializers/spree/api/v2/platform/log_entry_serializer.rb +13 -0
  93. data/app/serializers/spree/api/v2/platform/menu_item_serializer.rb +1 -1
  94. data/app/serializers/spree/api/v2/platform/menu_serializer.rb +1 -1
  95. data/app/serializers/spree/api/v2/platform/option_type_serializer.rb +1 -1
  96. data/app/serializers/spree/api/v2/platform/option_value_serializer.rb +1 -1
  97. data/app/serializers/spree/api/v2/platform/order_promotion_serializer.rb +14 -0
  98. data/app/serializers/spree/api/v2/platform/order_serializer.rb +31 -0
  99. data/app/serializers/spree/api/v2/platform/payment_capture_event_serializer.rb +13 -0
  100. data/app/serializers/spree/api/v2/platform/payment_method_serializer.rb +18 -0
  101. data/app/serializers/spree/api/v2/platform/payment_serializer.rb +21 -0
  102. data/app/serializers/spree/api/v2/platform/price_serializer.rb +19 -0
  103. data/app/serializers/spree/api/v2/platform/product_property_serializer.rb +1 -1
  104. data/app/serializers/spree/api/v2/platform/product_serializer.rb +7 -3
  105. data/app/serializers/spree/api/v2/platform/promotion_action_line_item_serializer.rb +14 -0
  106. data/app/serializers/spree/api/v2/platform/promotion_action_serializer.rb +19 -0
  107. data/app/serializers/spree/api/v2/platform/promotion_category_serializer.rb +13 -0
  108. data/app/serializers/spree/api/v2/platform/promotion_rule_serializer.rb +21 -0
  109. data/app/serializers/spree/api/v2/platform/promotion_serializer.rb +17 -0
  110. data/app/serializers/spree/api/v2/platform/property_serializer.rb +11 -0
  111. data/app/serializers/spree/api/v2/platform/prototype_serializer.rb +15 -0
  112. data/app/serializers/spree/api/v2/platform/refund_reason_serializer.rb +11 -0
  113. data/app/serializers/spree/api/v2/platform/refund_serializer.rb +16 -0
  114. data/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb +10 -0
  115. data/app/serializers/spree/api/v2/platform/reimbursement_serializer.rb +18 -0
  116. data/app/serializers/spree/api/v2/platform/reimbursement_type_serializer.rb +11 -0
  117. data/app/serializers/spree/api/v2/platform/return_authorization_reason_serializer.rb +11 -0
  118. data/app/serializers/spree/api/v2/platform/return_authorization_serializer.rb +17 -0
  119. data/app/serializers/spree/api/v2/platform/return_item_serializer.rb +16 -0
  120. data/app/serializers/spree/api/v2/platform/role_serializer.rb +11 -0
  121. data/app/serializers/spree/api/v2/platform/shipment_serializer.rb +22 -0
  122. data/app/serializers/spree/api/v2/platform/shipping_category_serializer.rb +11 -0
  123. data/app/serializers/spree/api/v2/platform/shipping_method_serializer.rb +16 -0
  124. data/app/serializers/spree/api/v2/platform/shipping_rate_serializer.rb +15 -0
  125. data/app/serializers/spree/api/v2/platform/standard_page_serializer.rb +11 -0
  126. data/app/serializers/spree/api/v2/platform/state_change_serializer.rb +13 -0
  127. data/app/serializers/spree/api/v2/platform/state_serializer.rb +1 -1
  128. data/app/serializers/spree/api/v2/platform/stock_item_serializer.rb +1 -3
  129. data/app/serializers/spree/api/v2/platform/stock_location_serializer.rb +2 -4
  130. data/app/serializers/spree/api/v2/platform/stock_movement_serializer.rb +11 -0
  131. data/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb +15 -0
  132. data/app/serializers/spree/api/v2/platform/store_credit_category_serializer.rb +12 -0
  133. data/app/serializers/spree/api/v2/platform/store_credit_event_serializer.rb +14 -0
  134. data/app/serializers/spree/api/v2/platform/store_credit_serializer.rb +18 -0
  135. data/app/serializers/spree/api/v2/platform/store_credit_type_serializer.rb +12 -0
  136. data/app/serializers/spree/api/v2/platform/store_serializer.rb +1 -1
  137. data/app/serializers/spree/api/v2/platform/tax_category_serializer.rb +2 -2
  138. data/app/serializers/spree/api/v2/platform/tax_rate_serializer.rb +14 -0
  139. data/app/serializers/spree/api/v2/platform/taxon_serializer.rb +1 -1
  140. data/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb +1 -1
  141. data/app/serializers/spree/api/v2/platform/user_serializer.rb +1 -1
  142. data/app/serializers/spree/api/v2/platform/variant_serializer.rb +3 -2
  143. data/app/serializers/spree/api/v2/platform/webhooks/event_serializer.rb +15 -0
  144. data/app/serializers/spree/api/v2/platform/webhooks/subscriber_serializer.rb +13 -0
  145. data/app/serializers/spree/api/v2/platform/wished_item_serializer.rb +29 -0
  146. data/app/serializers/spree/api/v2/platform/wishlist_serializer.rb +19 -0
  147. data/app/serializers/spree/api/v2/platform/zone_member_serializer.rb +13 -0
  148. data/app/serializers/spree/api/v2/platform/zone_serializer.rb +13 -0
  149. data/app/serializers/spree/v2/storefront/address_serializer.rb +1 -1
  150. data/app/serializers/spree/v2/storefront/cart_serializer.rb +1 -1
  151. data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +5 -1
  152. data/app/serializers/spree/v2/storefront/credit_card_serializer.rb +1 -1
  153. data/app/serializers/spree/v2/storefront/digital_link_serializer.rb +11 -0
  154. data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +2 -2
  155. data/app/serializers/spree/v2/storefront/line_item_serializer.rb +2 -1
  156. data/app/serializers/spree/v2/storefront/option_type_serializer.rb +1 -1
  157. data/app/serializers/spree/v2/storefront/option_value_serializer.rb +1 -1
  158. data/app/serializers/spree/v2/storefront/payment_method_serializer.rb +1 -1
  159. data/app/serializers/spree/v2/storefront/payment_serializer.rb +1 -1
  160. data/app/serializers/spree/v2/storefront/product_serializer.rb +2 -2
  161. data/app/serializers/spree/v2/storefront/promotion_serializer.rb +1 -1
  162. data/app/serializers/spree/v2/storefront/shipment_serializer.rb +2 -1
  163. data/app/serializers/spree/v2/storefront/store_credit_serializer.rb +1 -1
  164. data/app/serializers/spree/v2/storefront/store_serializer.rb +1 -1
  165. data/app/serializers/spree/v2/storefront/taxon_serializer.rb +1 -1
  166. data/app/serializers/spree/v2/storefront/taxonomy_serializer.rb +1 -1
  167. data/app/serializers/spree/v2/storefront/user_serializer.rb +1 -1
  168. data/app/serializers/spree/v2/storefront/variant_serializer.rb +1 -1
  169. data/app/serializers/spree/v2/storefront/wished_item_serializer.rb +29 -0
  170. data/app/serializers/spree/v2/storefront/wishlist_serializer.rb +17 -0
  171. data/app/services/spree/webhooks/subscribers/handle_request.rb +73 -0
  172. data/app/services/spree/webhooks/subscribers/make_request.rb +82 -0
  173. data/app/services/spree/webhooks/subscribers/queue_requests.rb +17 -0
  174. data/app/services/spree/webhooks.rb +13 -0
  175. data/config/i18n-tasks.yml +40 -0
  176. data/config/initializers/doorkeeper.rb +12 -12
  177. data/config/initializers/rabl.rb +2 -2
  178. data/config/locales/en.yml +29 -27
  179. data/config/routes.rb +85 -59
  180. data/db/migrate/20210902162826_create_spree_webhooks_tables.rb +16 -0
  181. data/db/migrate/20210919183228_enable_polymorphic_resource_owner.rb +21 -0
  182. data/db/migrate/20211025162826_create_spree_webhooks_events.rb +14 -0
  183. data/docs/oauth/index.yml +126 -33
  184. data/docs/v2/platform/index.yaml +19182 -1717
  185. data/docs/v2/storefront/index.yaml +14823 -14588
  186. data/{app/models/spree → lib/spree/api}/api_dependencies.rb +60 -5
  187. data/lib/spree/api/engine.rb +24 -1
  188. data/lib/spree/api/testing_support/factories/oauth_application_factory.rb +6 -0
  189. data/lib/spree/api/testing_support/factories/webhook_event_factory.rb +27 -0
  190. data/lib/spree/api/testing_support/factories/webhook_subscriber_factory.rb +13 -0
  191. data/lib/spree/api/testing_support/factories.rb +3 -0
  192. data/lib/spree/api/testing_support/helpers.rb +1 -1
  193. data/lib/spree/api/testing_support/jobs.rb +18 -0
  194. data/lib/spree/api/testing_support/matchers/webhooks.rb +67 -0
  195. data/lib/spree/api/testing_support/serializers.rb +25 -0
  196. data/lib/spree/api/testing_support/spree_webhooks.rb +9 -0
  197. data/lib/spree/api/testing_support/v2/base.rb +1 -1
  198. data/lib/spree/api/testing_support/v2/current_order.rb +34 -1
  199. data/lib/spree/api/testing_support/v2/platform_contexts.rb +109 -50
  200. data/lib/spree/api/testing_support/v2/serializers_params.rb +3 -1
  201. data/lib/spree/api.rb +1 -0
  202. data/spec/fixtures/files/icon_256x256.jpg +0 -0
  203. data/spree_api.gemspec +16 -15
  204. metadata +176 -28
  205. data/app/controllers/spree/api/errors_controller.rb +0 -9
@@ -14,18 +14,31 @@ module Spree
14
14
  :storefront_country_serializer, :storefront_menu_serializer, :storefront_menu_finder, :storefront_current_order_finder,
15
15
  :storefront_completed_order_finder, :storefront_order_sorter, :storefront_collection_paginator, :storefront_user_serializer,
16
16
  :storefront_products_sorter, :storefront_products_finder, :storefront_product_serializer, :storefront_taxon_serializer,
17
- :storefront_taxon_finder, :storefront_find_by_variant_finder, :storefront_cart_update_service,
17
+ :storefront_taxon_finder, :storefront_find_by_variant_finder, :storefront_cart_update_service, :storefront_cart_associate_service,
18
18
  :storefront_cart_estimate_shipping_rates_service, :storefront_estimated_shipment_serializer,
19
19
  :storefront_store_serializer, :storefront_address_serializer, :storefront_order_serializer,
20
20
  :storefront_account_create_address_service, :storefront_account_update_address_service, :storefront_address_finder,
21
21
  :storefront_account_create_service, :storefront_account_update_service, :storefront_collection_sorter, :error_handler,
22
- :storefront_cart_empty_service, :storefront_cart_destroy_service, :storefront_credit_cards_destroy_service, :platform_products_sorter
22
+ :storefront_cart_empty_service, :storefront_cart_destroy_service, :storefront_credit_cards_destroy_service, :platform_products_sorter,
23
+ :storefront_cart_change_currency_service, :storefront_payment_serializer,
24
+ :storefront_payment_create_service, :storefront_address_create_service, :storefront_address_update_service,
25
+ :storefront_checkout_select_shipping_method_service,
26
+
27
+ :platform_admin_user_serializer, :platform_coupon_handler, :platform_order_update_service,
28
+ :platform_order_use_store_credit_service, :platform_order_remove_store_credit_service,
29
+ :platform_order_complete_service, :platform_order_empty_service, :platform_order_destroy_service,
30
+ :platform_order_next_service, :platform_order_advance_service,
31
+ :platform_line_item_create_service, :platform_line_item_update_service, :platform_line_item_destroy_service,
32
+ :platform_order_approve_service, :platform_order_cancel_service,
33
+ :platform_shipment_change_state_service, :platform_shipment_create_service, :platform_shipment_update_service,
34
+ :platform_shipment_add_item_service, :platform_shipment_remove_item_service
23
35
  ].freeze
24
36
 
25
37
  attr_accessor *INJECTION_POINTS
26
38
 
27
39
  def initialize
28
40
  set_storefront_defaults
41
+ set_platform_defaults
29
42
  end
30
43
 
31
44
  private
@@ -43,6 +56,8 @@ module Spree
43
56
  @storefront_cart_estimate_shipping_rates_service = Spree::Dependencies.cart_estimate_shipping_rates_service
44
57
  @storefront_cart_empty_service = Spree::Dependencies.cart_empty_service
45
58
  @storefront_cart_destroy_service = Spree::Dependencies.cart_destroy_service
59
+ @storefront_cart_associate_service = Spree::Dependencies.cart_associate_service
60
+ @storefront_cart_change_currency_service = Spree::Dependencies.cart_change_currency_service
46
61
 
47
62
  # coupon code handler
48
63
  @storefront_coupon_handler = Spree::Dependencies.coupon_handler
@@ -55,16 +70,22 @@ module Spree
55
70
  @storefront_checkout_add_store_credit_service = Spree::Dependencies.checkout_add_store_credit_service
56
71
  @storefront_checkout_remove_store_credit_service = Spree::Dependencies.checkout_remove_store_credit_service
57
72
  @storefront_checkout_get_shipping_rates_service = Spree::Dependencies.checkout_get_shipping_rates_service
73
+ @storefront_checkout_select_shipping_method_service = Spree::Dependencies.checkout_select_shipping_method_service
58
74
 
59
75
  # account services
60
76
  @storefront_account_create_service = Spree::Dependencies.account_create_service
61
77
  @storefront_account_update_service = Spree::Dependencies.account_update_service
62
- @storefront_account_create_address_service = Spree::Dependencies.account_create_address_service
63
- @storefront_account_update_address_service = Spree::Dependencies.account_update_address_service
64
78
 
65
- # credit cards
79
+ # address services
80
+ @storefront_address_create_service = Spree::Dependencies.address_create_service
81
+ @storefront_address_update_service = Spree::Dependencies.address_update_service
82
+
83
+ # credit card services
66
84
  @storefront_credit_cards_destroy_service = Spree::Dependencies.credit_cards_destroy_service
67
85
 
86
+ # payment services
87
+ @storefront_payment_create_service = Spree::Dependencies.payment_create_service
88
+
68
89
  # serializers
69
90
  @storefront_address_serializer = 'Spree::V2::Storefront::AddressSerializer'
70
91
  @storefront_cart_serializer = 'Spree::V2::Storefront::CartSerializer'
@@ -76,6 +97,7 @@ module Spree
76
97
  @storefront_shipment_serializer = 'Spree::V2::Storefront::ShipmentSerializer'
77
98
  @storefront_taxon_serializer = 'Spree::V2::Storefront::TaxonSerializer'
78
99
  @storefront_payment_method_serializer = 'Spree::V2::Storefront::PaymentMethodSerializer'
100
+ @storefront_payment_serializer = 'Spree::V2::Storefront::PaymentSerializer'
79
101
  @storefront_product_serializer = 'Spree::V2::Storefront::ProductSerializer'
80
102
  @storefront_estimated_shipment_serializer = 'Spree::V2::Storefront::EstimatedShippingRateSerializer'
81
103
  @storefront_store_serializer = 'Spree::V2::Storefront::StoreSerializer'
@@ -104,5 +126,38 @@ module Spree
104
126
 
105
127
  @error_handler = 'Spree::Api::ErrorHandler'
106
128
  end
129
+
130
+ def set_platform_defaults
131
+ # serializers
132
+ @platform_admin_user_serializer = 'Spree::Api::V2::Platform::UserSerializer'
133
+
134
+ # coupon code handler
135
+ @platform_coupon_handler = Spree::Dependencies.coupon_handler
136
+
137
+ # order services
138
+ @platform_order_recalculate_service = Spree::Dependencies.cart_recalculate_service
139
+ @platform_order_update_service = Spree::Dependencies.checkout_update_service
140
+ @platform_order_empty_service = Spree::Dependencies.cart_empty_service
141
+ @platform_order_destroy_service = Spree::Dependencies.cart_destroy_service
142
+ @platform_order_next_service = Spree::Dependencies.checkout_next_service
143
+ @platform_order_advance_service = Spree::Dependencies.checkout_advance_service
144
+ @platform_order_complete_service = Spree::Dependencies.checkout_complete_service
145
+ @platform_order_use_store_credit_service = Spree::Dependencies.checkout_add_store_credit_service
146
+ @platform_order_remove_store_credit_service = Spree::Dependencies.checkout_remove_store_credit_service
147
+ @platform_order_approve_service = Spree::Dependencies.order_approve_service
148
+ @platform_order_cancel_service = Spree::Dependencies.order_cancel_service
149
+
150
+ # line item services
151
+ @platform_line_item_create_service = Spree::Dependencies.line_item_create_service
152
+ @platform_line_item_update_service = Spree::Dependencies.line_item_update_service
153
+ @platform_line_item_destroy_service = Spree::Dependencies.line_item_destroy_service
154
+
155
+ # shipment services
156
+ @platform_shipment_create_service = Spree::Dependencies.shipment_create_service
157
+ @platform_shipment_update_service = Spree::Dependencies.shipment_update_service
158
+ @platform_shipment_change_state_service = Spree::Dependencies.shipment_change_state_service
159
+ @platform_shipment_add_item_service = Spree::Dependencies.shipment_add_item_service
160
+ @platform_shipment_remove_item_service = Spree::Dependencies.shipment_remove_item_service
161
+ end
107
162
  end
108
163
  end
@@ -17,13 +17,36 @@ module Spree
17
17
 
18
18
  initializer 'spree.api.checking_deprecated_preferences' do
19
19
  Spree::Api::Config.deprecated_preferences.each do |pref|
20
- warn "[DEPRECATION] Spree::Api::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"
20
+ # FIXME: we should only notify about deprecated preferences that are in use, not all of them
21
+ # warn "[DEPRECATION] Spree::Api::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"
22
+ end
23
+ end
24
+
25
+ def self.activate
26
+ [
27
+ Spree::Address, Spree::Asset, Spree::CmsPage, Spree::CreditCard, Spree::CustomerReturn,
28
+ Spree::DigitalLink, Spree::Digital, Spree::InventoryUnit, Spree::LineItem, Spree::MenuItem,
29
+ Spree::Menu, Spree::OptionType, Spree::OptionValue, Spree::Order, Spree::PaymentCaptureEvent,
30
+ Spree::Payment, Spree::Price, Spree::Product, Spree::Promotion, Spree::Property, Spree::Prototype,
31
+ Spree::Refund, Spree::Reimbursement, Spree::ReturnAuthorization, Spree::ReturnItem, Spree::Role,
32
+ Spree::Shipment, Spree::ShippingCategory, Spree::ShippingMethod, Spree::ShippingRate,
33
+ Spree::StockItem, Spree::StockLocation, Spree::StockMovement, Spree::StockTransfer,
34
+ Spree::StoreCredit, Spree::Store, Spree::TaxCategory, Spree::TaxRate, Spree::Taxonomy,
35
+ Spree::Taxon, Spree::Variant, Spree::WishedItem, Spree::Wishlist, Spree::Zone
36
+ ].each do |webhookable_class|
37
+ webhookable_class.include(Spree::Webhooks::HasWebhooks)
38
+ end
39
+
40
+ Dir.glob(File.join(File.dirname(__FILE__), '../../../app/models/spree/api/webhooks/*_decorator*.rb')) do |c|
41
+ Rails.application.config.cache_classes ? require(c) : load(c)
21
42
  end
22
43
  end
23
44
 
24
45
  def self.root
25
46
  @root ||= Pathname.new(File.expand_path('../../..', __dir__))
26
47
  end
48
+
49
+ config.to_prepare &method(:activate).to_proc
27
50
  end
28
51
  end
29
52
  end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :oauth_application, class: Spree::OauthApplication do
3
+ name { "Admin Panel" }
4
+ scopes { "admin" }
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ FactoryBot.define do
2
+ factory :webhook_event, aliases: [:event], class: Spree::Webhooks::Event do
3
+ subscriber
4
+
5
+ execution_time { rand(1..99_999) }
6
+ name { 'order.canceled' }
7
+ request_errors { '' }
8
+ sequence(:url) { |n| "https://www.url#{n}.com/" }
9
+
10
+ trait :failed do
11
+ response_code { '500' }
12
+ success { false }
13
+ end
14
+
15
+ trait :successful do
16
+ response_code { '200' }
17
+ success { true }
18
+ end
19
+
20
+ trait :blank do
21
+ execution_time { nil }
22
+ request_errors { nil }
23
+ subscriber_id { nil }
24
+ url { nil }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ FactoryBot.define do
2
+ factory :webhook_subscriber, aliases: [:subscriber], class: Spree::Webhooks::Subscriber do
3
+ sequence(:url) { |n| "https://www.url#{n}.com/" }
4
+
5
+ trait :active do
6
+ active { true }
7
+ end
8
+
9
+ trait :inactive do
10
+ active { false }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ Dir["#{File.dirname(__FILE__)}/factories/**"].each do |f|
2
+ load File.expand_path(f)
3
+ end
@@ -25,7 +25,7 @@ module Spree
25
25
  allow(Spree.user_class).to receive(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
26
26
  end
27
27
 
28
- # This method can be overriden (with a let block) inside a context
28
+ # This method can be overridden (with a let block) inside a context
29
29
  # For instance, if you wanted to have an admin user instead.
30
30
  def current_api_user
31
31
  @current_api_user ||= stub_model(Spree.user_class, email: 'spree@example.com')
@@ -0,0 +1,18 @@
1
+ RSpec.configure do |config|
2
+ # Force jobs to be executed in a synchronous way (see http://archive.today/xcb1E)
3
+ config.around do |example|
4
+ (ActiveJob::Base.descendants << ActiveJob::Base).each(&:disable_test_adapter)
5
+ ActiveJob::Base.queue_adapter = :inline
6
+ example.run
7
+ (ActiveJob::Base.descendants << ActiveJob::Base).each { |a| a.enable_test_adapter(ActiveJob::QueueAdapters::TestAdapter.new) }
8
+ ActiveJob::Base.queue_adapter = :test
9
+ end
10
+
11
+ config.before(:each, :job) do
12
+ ActiveJob::Base.queue_adapter = :test
13
+ end
14
+
15
+ config.after(:each, :job) do
16
+ ActiveJob::Base.queue_adapter = :inline
17
+ end
18
+ end
@@ -0,0 +1,67 @@
1
+ # Passes if executing the code in the block there is a
2
+ # `Spree::Webhooks::Subscribers::QueueRequests.call` method
3
+ # call with the given `event` and `webhook_payload_body` arguments just once.
4
+ #
5
+ # @example
6
+ # expect { order.complete }.to emit_webhook_event('order.paid')
7
+ # expect do
8
+ # order.start_processing
9
+ # order.complete
10
+ # end.to emit_webhook_event('order.paid')
11
+ #
12
+ # It can also be negated, resulting in the expectation
13
+ # waiting to not receive a `call` method call with the
14
+ # given `event` and `webhook_payload_body` (`once` isn't taken into consideration).
15
+ #
16
+ # @example
17
+ # expect { order.complete }.not_to emit_webhook_event('order.paid')
18
+ # expect do
19
+ # order.start_processing
20
+ # order.complete
21
+ # end.not_to emit_webhook_event('order.paid')
22
+ #
23
+ # == Notes
24
+ #
25
+ # The matcher relies on a `webhook_payload_body` method previously defined which
26
+ # isn't added to the matcher definition, because it acts in a different
27
+ # way depending on what's the resource being tested.
28
+ #
29
+ RSpec::Matchers.define :emit_webhook_event do |event_to_emit|
30
+ match do |block|
31
+ queue_requests = instance_double(Spree::Webhooks::Subscribers::QueueRequests)
32
+
33
+ allow(Spree::Webhooks::Subscribers::QueueRequests).to receive(:new).and_return(queue_requests)
34
+ allow(queue_requests).to receive(:call).with(any_args)
35
+
36
+ with_webhooks_enabled { Timecop.freeze { block.call } }
37
+
38
+ expect(queue_requests).to(
39
+ have_received(:call).with(event_name: event_to_emit, webhook_payload_body: webhook_payload_body.to_json).once
40
+ )
41
+ end
42
+
43
+ def block_definition(obj_method)
44
+ # positive look-behinds must have a fixed length, using a straightforward match instead
45
+ obj_method.source.squish[/(expect *({|do) *)(.*?)( *(}|end).(not_)*to)/, 3]
46
+ end
47
+
48
+ failure_message do |obj_method|
49
+ block_def = block_definition(obj_method)
50
+ "Expected that executing `#{block_def}` emits the `#{event_to_emit}` Webhook event.\n" \
51
+ "Check that `#{block_def}` does implement `queue_webhooks_requests!` for " \
52
+ "`#{event_to_emit}` with the following webhook_payload_body: \n\n#{webhook_payload_body}."
53
+ end
54
+
55
+ failure_message_when_negated do |obj_method|
56
+ "Expected that executing `#{block_definition(obj_method)}` does not " \
57
+ "emit the `#{event_to_emit}` Webhook event with the following webhook_payload_body: #{webhook_payload_body}."
58
+ end
59
+
60
+ supports_block_expectations
61
+ end
62
+
63
+ def with_webhooks_enabled
64
+ ENV['DISABLE_SPREE_WEBHOOKS'] = nil
65
+ yield
66
+ ENV['DISABLE_SPREE_WEBHOOKS'] = 'true'
67
+ end
@@ -0,0 +1,25 @@
1
+ module Spree
2
+ class TestArgumentsJob < Spree::BaseJob
3
+ def perform(serializer); end
4
+ end
5
+ end
6
+
7
+ shared_examples 'an ActiveJob serializable hash' do
8
+ context 'Rails < 6', if: Rails::VERSION::MAJOR < 6 do
9
+ it 'can not be serialized by ActiveJob' do
10
+ expect { Spree::TestArgumentsJob.perform_later(subject) }.to(
11
+ raise_error(ActiveJob::SerializationError, 'Unsupported argument type: Symbol')
12
+ )
13
+ end
14
+ end
15
+
16
+ context 'Rails >= 6', if: Rails::VERSION::MAJOR >= 6 do
17
+ it 'can be serialized by ActiveJob' do
18
+ # It should fail if subject contains any custom instance (e.g Spree::Money)
19
+ expect { Spree::TestArgumentsJob.perform_later(subject) }.not_to raise_error
20
+ expect { Spree::TestArgumentsJob.perform_later(subject.merge(price: Spree::Money.new(0))) }.to(
21
+ raise_error(ActiveJob::SerializationError)
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.configure do |config|
2
+ config.before(:each, :spree_webhooks) do
3
+ ENV['DISABLE_SPREE_WEBHOOKS'] = nil
4
+ end
5
+
6
+ config.after(:each, :spree_webhooks) do
7
+ ENV['DISABLE_SPREE_WEBHOOKS'] = 'true'
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  shared_context 'API v2 tokens' do
2
- let(:token) { Doorkeeper::AccessToken.create!(resource_owner_id: user.id, expires_in: nil) }
2
+ let(:token) { Spree::OauthAccessToken.create!(resource_owner: user, expires_in: nil) }
3
3
  let(:headers_bearer) { { 'Authorization' => "Bearer #{token.token}" } }
4
4
  let(:headers_order_token) { { 'X-Spree-Order-Token' => order.token } }
5
5
  end
@@ -7,7 +7,40 @@ shared_context 'creates order with line item' do
7
7
  let!(:line_item) { create(:line_item, order: order, currency: currency) }
8
8
  let!(:headers) { headers_bearer }
9
9
 
10
- before { ensure_order_totals }
10
+ before do
11
+ order.reload
12
+ ensure_order_totals
13
+ end
14
+ end
15
+
16
+ shared_context 'order with a physical line item' do
17
+ include_context 'creates order with line item'
18
+ end
19
+
20
+ shared_context 'order with a digital line item' do
21
+ let!(:digital) { create(:digital) }
22
+ let!(:variant_digital) { digital.variant }
23
+ let!(:line_item) { create(:line_item, variant: variant_digital, order: order, currency: currency) }
24
+ let!(:headers) { headers_bearer }
25
+
26
+ before do
27
+ order.reload
28
+ ensure_order_totals
29
+ end
30
+ end
31
+
32
+ shared_context 'order with a physical and digital line item' do
33
+ let!(:digital) { create(:digital) }
34
+ let!(:variant_digital) { digital.variant }
35
+ let!(:digital_line_item) { create(:line_item, variant: variant_digital, order: order, currency: currency) }
36
+ let!(:physical_line_item) { create(:line_item, order: order, currency: currency) }
37
+
38
+ let!(:headers) { headers_bearer }
39
+
40
+ before do
41
+ order.reload
42
+ ensure_order_totals
43
+ end
11
44
  end
12
45
 
13
46
  shared_context 'creates guest order with guest token' do