workarea-global_e 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintrc.json +37 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.github/workflows/ci.yml +77 -0
  7. data/.gitignore +20 -0
  8. data/.rubocop.yml +2 -0
  9. data/.ruby-version +1 -0
  10. data/CHANGELOG.md +261 -0
  11. data/Gemfile +16 -0
  12. data/README.md +39 -0
  13. data/Rakefile +59 -0
  14. data/app/assets/javascripts/workarea/storefront/global_e/modules/checkout_info_validator.js +122 -0
  15. data/app/assets/javascripts/workarea/storefront/global_e/modules/suppress_price_ranges.js +19 -0
  16. data/app/controllers/workarea/admin/country_exceptions_controller.rb +67 -0
  17. data/app/controllers/workarea/admin/fixed_prices_controller.rb +89 -0
  18. data/app/controllers/workarea/admin/orders_controller.decorator +6 -0
  19. data/app/controllers/workarea/storefront/application_controller.decorator +30 -0
  20. data/app/controllers/workarea/storefront/checkouts_controller.decorator +22 -0
  21. data/app/controllers/workarea/storefront/ge_checkouts_controller.rb +10 -0
  22. data/app/controllers/workarea/storefront/global_e_controller.rb +42 -0
  23. data/app/controllers/workarea/storefront/globale/api_controller.rb +108 -0
  24. data/app/controllers/workarea/storefront/globale/refund_controller.rb +65 -0
  25. data/app/controllers/workarea/storefront/users/logins_controller.decorator +13 -0
  26. data/app/helpers/workarea/admin/global_e_helpers.rb +28 -0
  27. data/app/models/workarea/address.decorator +11 -0
  28. data/app/models/workarea/catalog/product.decorator +14 -0
  29. data/app/models/workarea/fulfillment/status/partially_refunded.rb +13 -0
  30. data/app/models/workarea/fulfillment/status/refunded.rb +15 -0
  31. data/app/models/workarea/fulfillment.decorator +55 -0
  32. data/app/models/workarea/global_e/country_exception.rb +37 -0
  33. data/app/models/workarea/global_e/fixed_price.rb +93 -0
  34. data/app/models/workarea/global_e/order_api_events.rb +29 -0
  35. data/app/models/workarea/order/item.decorator +46 -0
  36. data/app/models/workarea/order/status/pending_global_e_fraud_check.rb +12 -0
  37. data/app/models/workarea/order.decorator +64 -0
  38. data/app/models/workarea/payment/status/global_e_appoved.rb +9 -0
  39. data/app/models/workarea/payment/status/pending_global_e_fraud_check.rb +9 -0
  40. data/app/models/workarea/payment/tender/global_e_payment.rb +16 -0
  41. data/app/models/workarea/payment.decorator +10 -0
  42. data/app/models/workarea/price_adjustment.decorator +13 -0
  43. data/app/models/workarea/price_adjustment_set.decorator +25 -0
  44. data/app/models/workarea/pricing/calculators/item_calculator.decorator +48 -0
  45. data/app/models/workarea/pricing/collection.decorator +90 -0
  46. data/app/models/workarea/pricing/discount/appliation_group.decorator +16 -0
  47. data/app/models/workarea/pricing/discount/international_item_proxy.rb +27 -0
  48. data/app/models/workarea/pricing/discount/international_order.rb +29 -0
  49. data/app/models/workarea/pricing/discount.decorator +65 -0
  50. data/app/models/workarea/pricing/price_distributor.decorator +37 -0
  51. data/app/models/workarea/pricing/request.decorator +17 -0
  52. data/app/models/workarea/pricing/sku.decorator +17 -0
  53. data/app/models/workarea/search/admin/order.decorator +11 -0
  54. data/app/models/workarea/shipping/sku.decorator +23 -0
  55. data/app/models/workarea/shipping.decorator +11 -0
  56. data/app/models/workarea/user.decorator +10 -0
  57. data/app/seeds/workarea/global_e_seeds.rb +66 -0
  58. data/app/services/workarea/create_fulfillment.decorator +12 -0
  59. data/app/services/workarea/global_e/address_details.rb +218 -0
  60. data/app/services/workarea/global_e/api/notify_order_refunded.rb +45 -0
  61. data/app/services/workarea/global_e/api/perform_order_payment.rb +46 -0
  62. data/app/services/workarea/global_e/api/remove_restricted_products.rb +28 -0
  63. data/app/services/workarea/global_e/api/send_order_to_merchant/item_pricer.rb +147 -0
  64. data/app/services/workarea/global_e/api/send_order_to_merchant/save_user.rb +59 -0
  65. data/app/services/workarea/global_e/api/send_order_to_merchant.rb +359 -0
  66. data/app/services/workarea/global_e/api/update_order_shipping_info.rb +38 -0
  67. data/app/services/workarea/global_e/api/update_order_status/canceled.rb +42 -0
  68. data/app/services/workarea/global_e/api/update_order_status.rb +28 -0
  69. data/app/services/workarea/global_e/attribute.rb +44 -0
  70. data/app/services/workarea/global_e/brand.rb +19 -0
  71. data/app/services/workarea/global_e/cart_user_details.rb +34 -0
  72. data/app/services/workarea/global_e/category.rb +19 -0
  73. data/app/services/workarea/global_e/checkout_cart_info.rb +358 -0
  74. data/app/services/workarea/global_e/custom_product_attribute.rb +19 -0
  75. data/app/services/workarea/global_e/discount.rb +215 -0
  76. data/app/services/workarea/global_e/merchant/brand.rb +21 -0
  77. data/app/services/workarea/global_e/merchant/category.rb +21 -0
  78. data/app/services/workarea/global_e/merchant/customer.rb +36 -0
  79. data/app/services/workarea/global_e/merchant/customer_details.rb +201 -0
  80. data/app/services/workarea/global_e/merchant/discount.rb +127 -0
  81. data/app/services/workarea/global_e/merchant/international_details.rb +296 -0
  82. data/app/services/workarea/global_e/merchant/order.rb +425 -0
  83. data/app/services/workarea/global_e/merchant/order_refund.rb +103 -0
  84. data/app/services/workarea/global_e/merchant/original_order.rb +28 -0
  85. data/app/services/workarea/global_e/merchant/parcel_tracking.rb +31 -0
  86. data/app/services/workarea/global_e/merchant/payment_details.rb +161 -0
  87. data/app/services/workarea/global_e/merchant/product.rb +222 -0
  88. data/app/services/workarea/global_e/merchant/refund_product.rb +69 -0
  89. data/app/services/workarea/global_e/merchant/response_info.rb +115 -0
  90. data/app/services/workarea/global_e/merchant_cart_product_attribute.rb +21 -0
  91. data/app/services/workarea/global_e/order_status.rb +20 -0
  92. data/app/services/workarea/global_e/order_status_details.rb +79 -0
  93. data/app/services/workarea/global_e/order_status_reason.rb +20 -0
  94. data/app/services/workarea/global_e/parcel.rb +53 -0
  95. data/app/services/workarea/global_e/product.rb +612 -0
  96. data/app/services/workarea/global_e/product_meta_data.rb +13 -0
  97. data/app/services/workarea/global_e/tracking_details.rb +23 -0
  98. data/app/services/workarea/global_e/update_order_dispatch_exception.rb +46 -0
  99. data/app/services/workarea/global_e/update_order_dispatch_request.rb +108 -0
  100. data/app/services/workarea/global_e/user_id_number_type.rb +21 -0
  101. data/app/services/workarea/global_e/users_details.rb +151 -0
  102. data/app/services/workarea/global_e/vat_category.rb +20 -0
  103. data/app/services/workarea/global_e/vat_rate_type.rb +27 -0
  104. data/app/services/workarea/save_order_analytics.decorator +18 -0
  105. data/app/view_models/workarea/admin/order_view_model.decorator +13 -0
  106. data/app/view_models/workarea/storefront/cart_view_model.decorator +7 -0
  107. data/app/view_models/workarea/storefront/order_item_view_model.decorator +16 -0
  108. data/app/view_models/workarea/storefront/order_view_model.decorator +45 -0
  109. data/app/view_models/workarea/storefront/product_view_model.decorator +35 -0
  110. data/app/views/workarea/admin/catalog_products/_country_exceptions_card.html.haml +31 -0
  111. data/app/views/workarea/admin/catalog_products/_global_e_attributes.html.haml +3 -0
  112. data/app/views/workarea/admin/catalog_products/_global_e_fields.html.haml +4 -0
  113. data/app/views/workarea/admin/country_exceptions/edit.html.haml +48 -0
  114. data/app/views/workarea/admin/country_exceptions/index.html.haml +47 -0
  115. data/app/views/workarea/admin/country_exceptions/new.html.haml +44 -0
  116. data/app/views/workarea/admin/fixed_prices/edit.html.haml +73 -0
  117. data/app/views/workarea/admin/fixed_prices/index.html.haml +55 -0
  118. data/app/views/workarea/admin/fixed_prices/new.html.haml +70 -0
  119. data/app/views/workarea/admin/orders/_global_e.html.haml +27 -0
  120. data/app/views/workarea/admin/orders/attributes.html.haml +131 -0
  121. data/app/views/workarea/admin/orders/global_e.html.haml +110 -0
  122. data/app/views/workarea/admin/orders/show.html.haml +27 -0
  123. data/app/views/workarea/admin/orders/tenders/_global_e_payment.html.haml +3 -0
  124. data/app/views/workarea/admin/pricing_skus/_cards.html.haml +98 -0
  125. data/app/views/workarea/storefront/cart_items/create.html.haml +71 -0
  126. data/app/views/workarea/storefront/carts/_pricing.html.haml +14 -0
  127. data/app/views/workarea/storefront/carts/show.html.haml +187 -0
  128. data/app/views/workarea/storefront/ge_checkouts/show.html.haml +1 -0
  129. data/app/views/workarea/storefront/global_e/_country_picker.html.haml +1 -0
  130. data/app/views/workarea/storefront/global_e/_head.html.haml +10 -0
  131. data/app/views/workarea/storefront/orders/_summary.html.haml +275 -0
  132. data/app/views/workarea/storefront/orders/tenders/_global_e_payment.html.haml +3 -0
  133. data/app/views/workarea/storefront/products/_pricing.html.haml +49 -0
  134. data/app/views/workarea/storefront/products/_restricted_item_text.html.haml +1 -0
  135. data/app/views/workarea/storefront/users/orders/_summary.html.haml +22 -0
  136. data/app/workers/workarea/global_e/update_order_dispatch.rb +28 -0
  137. data/app/workers/workarea/save_user_order_details.decorator +9 -0
  138. data/bin/rails +25 -0
  139. data/config/initializers/appends.rb +46 -0
  140. data/config/initializers/seeds.rb +1 -0
  141. data/config/initializers/workarea.rb +64 -0
  142. data/config/locales/en.yml +105 -0
  143. data/config/routes.rb +31 -0
  144. data/lib/workarea/global_e/engine.rb +10 -0
  145. data/lib/workarea/global_e/error.rb +8 -0
  146. data/lib/workarea/global_e/version.rb +5 -0
  147. data/lib/workarea/global_e.rb +58 -0
  148. data/script/admin_ci +5 -0
  149. data/script/ci +8 -0
  150. data/script/core_ci +5 -0
  151. data/script/plugins_ci +5 -0
  152. data/script/storefront_ci +5 -0
  153. data/test/dummy/.ruby-version +1 -0
  154. data/test/dummy/Rakefile +6 -0
  155. data/test/dummy/app/assets/config/manifest.js +3 -0
  156. data/test/dummy/app/assets/images/.keep +0 -0
  157. data/test/dummy/app/assets/javascripts/application.js +14 -0
  158. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  159. data/test/dummy/app/controllers/application_controller.rb +2 -0
  160. data/test/dummy/app/controllers/concerns/.keep +0 -0
  161. data/test/dummy/app/helpers/application_helper.rb +2 -0
  162. data/test/dummy/app/jobs/application_job.rb +2 -0
  163. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  164. data/test/dummy/app/models/concerns/.keep +0 -0
  165. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  166. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  167. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  168. data/test/dummy/bin/bundle +3 -0
  169. data/test/dummy/bin/rails +4 -0
  170. data/test/dummy/bin/rake +4 -0
  171. data/test/dummy/bin/setup +28 -0
  172. data/test/dummy/bin/update +28 -0
  173. data/test/dummy/bin/yarn +11 -0
  174. data/test/dummy/config/application.rb +23 -0
  175. data/test/dummy/config/boot.rb +5 -0
  176. data/test/dummy/config/environment.rb +5 -0
  177. data/test/dummy/config/environments/development.rb +52 -0
  178. data/test/dummy/config/environments/production.rb +83 -0
  179. data/test/dummy/config/environments/test.rb +45 -0
  180. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  181. data/test/dummy/config/initializers/assets.rb +14 -0
  182. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  183. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  184. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  185. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  186. data/test/dummy/config/initializers/inflections.rb +16 -0
  187. data/test/dummy/config/initializers/mime_types.rb +4 -0
  188. data/test/dummy/config/initializers/workarea.rb +5 -0
  189. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  190. data/test/dummy/config/locales/en.yml +33 -0
  191. data/test/dummy/config/puma.rb +34 -0
  192. data/test/dummy/config/routes.rb +5 -0
  193. data/test/dummy/config/secrets.yml +18 -0
  194. data/test/dummy/config/spring.rb +6 -0
  195. data/test/dummy/config.ru +5 -0
  196. data/test/dummy/db/seeds.rb +2 -0
  197. data/test/dummy/lib/assets/.keep +0 -0
  198. data/test/dummy/log/.keep +0 -0
  199. data/test/factories/workarea/global_e_factories.rb +836 -0
  200. data/test/integration/workarea/admin/catalog_product_country_exceptions_integration_test.rb +81 -0
  201. data/test/integration/workarea/admin/global_e_jump_to_integration_test.rb +20 -0
  202. data/test/integration/workarea/admin/pricing_sku_fixed_prices_integration_test.rb +83 -0
  203. data/test/integration/workarea/storefront/global_e_api/receive_order_integration_test.rb +278 -0
  204. data/test/integration/workarea/storefront/global_e_api/receive_order_refund_integration_test.rb +25 -0
  205. data/test/integration/workarea/storefront/global_e_api/receive_payment_integration_test.rb +34 -0
  206. data/test/integration/workarea/storefront/global_e_api/receive_shipping_info_integration_test.rb +29 -0
  207. data/test/integration/workarea/storefront/global_e_api/remove_restricted_products_integration_test.rb +27 -0
  208. data/test/integration/workarea/storefront/global_e_api/update_order_status_integration_test.rb +29 -0
  209. data/test/integration/workarea/storefront/global_e_checkout_cart_info/fixed_pricing_test.rb +438 -0
  210. data/test/integration/workarea/storefront/global_e_checkout_cart_info/gift_card_test.rb +63 -0
  211. data/test/integration/workarea/storefront/global_e_checkout_cart_info_integration_test.rb +660 -0
  212. data/test/integration/workarea/storefront/global_e_checkouts_integration_test.rb +71 -0
  213. data/test/integration/workarea/storefront/users/global_e_logins_integration_test.rb +20 -0
  214. data/test/models/workarea/catalog/product_global_e_test.rb +13 -0
  215. data/test/models/workarea/fixed_pricing_test.rb +117 -0
  216. data/test/models/workarea/global_e/country_exception_test.rb +36 -0
  217. data/test/models/workarea/payment_test.decorator +31 -0
  218. data/test/models/workarea/pricing/calculators/item_calculator_fixed_prices_test.rb +83 -0
  219. data/test/models/workarea/pricing/collection_fixed_prices_test.rb +83 -0
  220. data/test/models/workarea/pricing/price_distributor_test.decorator +21 -0
  221. data/test/models/workarea/pricing/sku_fixed_price_test.rb +133 -0
  222. data/test/support/workarea/global_e_support.rb +18 -0
  223. data/test/system/workarea/admin/global_e_system_test.rb +21 -0
  224. data/test/system/workarea/storefront/global_e_cart_system_test.rb +48 -0
  225. data/test/system/workarea/storefront/global_e_order_history_system_test.rb +43 -0
  226. data/test/teaspoon_env.rb +6 -0
  227. data/test/test_helper.rb +9 -0
  228. data/test/view_models/workarea/admin/global_e_order_view_model_test.rb +22 -0
  229. data/test/workers/workarea/global_e/update_order_dispatch_test.rb +64 -0
  230. data/test/workers/workarea/global_e_save_user_order_details_test.rb +41 -0
  231. data/workarea-global_e.gemspec +16 -0
  232. metadata +293 -0
@@ -0,0 +1,81 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Admin
5
+ class CatalogProductCountryExceptionsIntegrationTest < Workarea::IntegrationTest
6
+ include Admin::IntegrationTest
7
+
8
+ def test_create_country_exception_invalid_data
9
+ product = create_product
10
+
11
+ post admin.catalog_product_country_exceptions_path(product),
12
+ params: {
13
+ country_exception: {
14
+ vat_rate: 10
15
+ }
16
+ }
17
+
18
+ product.reload
19
+
20
+ assert_empty product.country_exceptions
21
+ end
22
+
23
+ def test_creating_country_exceptions
24
+ product = create_product
25
+
26
+ post admin.catalog_product_country_exceptions_path(product),
27
+ params: {
28
+ country_exception: {
29
+ country: 'DE',
30
+ restricted: true
31
+ }
32
+ }
33
+
34
+ product.reload
35
+
36
+ refute_empty product.country_exceptions
37
+
38
+ country_exception = product.country_exceptions.first
39
+
40
+ assert country_exception.restricted?
41
+ end
42
+
43
+ def test_updates_country_exception
44
+ product = create_product(
45
+ country_exceptions: [
46
+ country: 'DE',
47
+ restricted: true
48
+ ]
49
+ )
50
+
51
+ patch admin.catalog_product_country_exception_path(product, product.country_exceptions.first),
52
+ params: {
53
+ country_exception: {
54
+ restricted: false,
55
+ vat_rate: 5,
56
+ }
57
+ }
58
+
59
+ product.reload
60
+ country_exception = product.country_exceptions.first
61
+
62
+ refute country_exception.restricted?
63
+ assert_equal 5, country_exception.vat_rate
64
+ end
65
+
66
+ def test_destroys_country_exception
67
+ product = create_product(
68
+ country_exceptions: [
69
+ country: 'DE',
70
+ restricted: true
71
+ ]
72
+ )
73
+
74
+ delete admin.catalog_product_country_exception_path(product, product.country_exceptions.first.id)
75
+
76
+ product.reload
77
+ assert_empty product.country_exceptions
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Admin
5
+ class JumpToIntegrationTest < Workarea::IntegrationTest
6
+ include Admin::IntegrationTest
7
+
8
+ def test_finding_orders_by_global_e_id
9
+ order = create_global_e_completed_checkout
10
+ get admin.jump_to_path q: order.global_e_id
11
+
12
+ results = JSON.parse(response.body)['results']
13
+ assert_equal(1, results.length)
14
+ assert_match(/#{order.id}/, results.first['label'])
15
+ assert_equal('Orders', results.first['type'])
16
+ assert_equal(admin.order_path(order.id), results.first['url'])
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Admin
5
+ class PricingSkuFixedPricesIntegrationtest < Workarea::IntegrationTest
6
+ include Admin::IntegrationTest
7
+
8
+ def test_create_fixed_price_invalid_data
9
+ sku = create_pricing_sku
10
+
11
+ post admin.pricing_sku_fixed_prices_path(sku),
12
+ params: {
13
+ fixed_price: {
14
+ regular: '5.00'
15
+ }
16
+ }
17
+
18
+ sku.reload
19
+
20
+ assert_empty sku.fixed_prices
21
+ end
22
+
23
+ def test_creating_fixed_price
24
+ sku = create_pricing_sku
25
+
26
+ post admin.pricing_sku_fixed_prices_path(sku),
27
+ params: {
28
+ fixed_price: {
29
+ regular: '5.00',
30
+ currency_code: 'EUR'
31
+ }
32
+ }
33
+
34
+ sku.reload
35
+
36
+ refute_empty sku.fixed_prices
37
+
38
+ fixed_price = sku.fixed_prices.first
39
+
40
+ assert_equal 5.to_m("EUR"), fixed_price.regular
41
+ assert_equal "EUR", fixed_price.currency_code
42
+ assert_nil fixed_price.sale
43
+ end
44
+
45
+ def test_updates_fixed_price
46
+ sku = create_pricing_sku(
47
+ fixed_prices: [
48
+ { regular: 3.to_m("CAD"), sale: 1.to_m("CAD"), currency_code: "CAD" }
49
+ ]
50
+ )
51
+
52
+ patch admin.pricing_sku_fixed_price_path(sku, sku.fixed_prices.first.id),
53
+ params: {
54
+ fixed_price: {
55
+ currency_code: "CAD",
56
+ regular: '5.00',
57
+ sale: '3.00',
58
+ }
59
+ }
60
+
61
+ sku.reload
62
+ fixed_price = sku.fixed_prices.first
63
+
64
+ assert_equal(5.to_m("CAD"), fixed_price.regular)
65
+ assert_equal(3.to_m("CAD"), fixed_price.sale)
66
+ end
67
+
68
+ def test_destroy_fixed_price
69
+ sku = create_pricing_sku(
70
+ fixed_prices: [{
71
+ regular: 5.to_m("EUR"),
72
+ currency_code: "EUR"
73
+ }]
74
+ )
75
+
76
+ delete admin.pricing_sku_fixed_price_path(sku, sku.fixed_prices.first.id)
77
+
78
+ sku.reload
79
+ assert_empty sku.fixed_prices
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,278 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ module GlobalEAPi
6
+ class ReceiveOrderIntegrationTest < Workarea::IntegrationTest
7
+ include GlobalESupport
8
+
9
+ def test_successful_post
10
+ order = create_cart
11
+
12
+ post storefront.globale_receive_order_path,
13
+ headers: { 'CONTENT_TYPE' => 'application/json' },
14
+ params: global_e_send_order_to_mechant_body(order: order)
15
+
16
+ assert response.ok?, "Expected 200 response"
17
+
18
+ response_body = JSON.parse response.body
19
+ assert response_body["Success"]
20
+ assert_equal order.id, response_body["InternalOrderId"]
21
+
22
+ order.reload
23
+ assert_equal "GE927127", order.global_e_id
24
+ assert order.placed?
25
+
26
+ assert order.global_e?
27
+ assert order.international_total_price.present?
28
+ assert_equal "€9.68", order.international_subtotal_price.format
29
+ assert_equal "€19.97", order.international_shipping_total.format
30
+ assert_equal "€64.88", order.international_total_price.format
31
+ assert_equal "€0.00", order.total_duties_price.format
32
+ refute order.duties_guaranteed
33
+
34
+ item = order.items.first
35
+ assert_equal 5.0, item.nonadjusted_price
36
+ assert_equal Money.new(1000, "USD"), item.nonadjusted_amount
37
+ assert_equal "€9.68", item.international_price_adjustments.first.amount.format
38
+
39
+ assert_equal :pending_global_e_fraud_check, order.status
40
+
41
+ inventory_transaction = Inventory::Transaction.find_by order_id: order.id
42
+ assert inventory_transaction.captured
43
+
44
+ shipping = Workarea::Shipping.find_by(order_id: order.id)
45
+ assert shipping.shipping_service.present?
46
+
47
+ payment = Workarea::Payment.find order.id
48
+ assert_equal "Visa", payment.global_e_payment.name
49
+ assert_equal "1", payment.global_e_payment.payment_method_code
50
+ assert_equal "7854", payment.global_e_payment.last_four
51
+ assert_equal "2023-06-30", payment.global_e_payment.expiration_date
52
+
53
+ api_events = GlobalE::OrderApiEvents.find(order.id)
54
+ assert api_events.receive_order.present?
55
+ assert api_events.receive_order_response.present?
56
+ end
57
+
58
+ def test_with_discounts
59
+ product_1 = create_complete_product(
60
+ variants: [{ sku: 'SKU', regular: 189.00 }]
61
+ )
62
+ product_2 = create_complete_product(
63
+ variants: [{ sku: 'SKU1', regular: 65.00 }]
64
+ )
65
+
66
+ product_discount = create_product_discount(product_ids: [product_1.id.to_s])
67
+ order_discount_1 = create_order_total_discount(compatible_discount_ids: [product_discount.id.to_s])
68
+ _order_discount_2 = create_order_total_discount(compatible_discount_ids: [
69
+ product_discount.id.to_s,
70
+ order_discount_1.id.to_s
71
+ ])
72
+
73
+ order = create_cart(
74
+ items: [
75
+ { product: product_1, sku: product_1.skus.first, quantity: 1 },
76
+ { product: product_2, sku: product_2.skus.first, quantity: 2 }
77
+ ]
78
+ )
79
+
80
+ post storefront.globale_receive_order_path,
81
+ headers: { 'CONTENT_TYPE' => 'application/json' },
82
+ params: global_e_send_order_to_mechant_body(order: order)
83
+
84
+ order.reload
85
+ assert response.ok?, "Expected 200 response"
86
+
87
+ response_body = JSON.parse response.body
88
+ assert response_body["Success"]
89
+ assert_equal order.id, response_body["InternalOrderId"]
90
+
91
+ price_adjustments_currency = order
92
+ .items
93
+ .flat_map { |oi| oi.price_adjustments.map { |pa| pa.amount.currency.iso_code } }
94
+ .uniq
95
+
96
+ assert_equal ["USD"], price_adjustments_currency
97
+
98
+ price_adjustments_currency = order
99
+ .items
100
+ .flat_map { |oi| oi.international_price_adjustments.map { |pa| pa.amount.currency.iso_code } }
101
+ .uniq
102
+
103
+ assert_equal ["EUR"], price_adjustments_currency
104
+ end
105
+
106
+ def test_item_going_out_of_stock
107
+ product_1 = create_complete_product(
108
+ variants: [{ sku: 'SKU', details: { material: 'cotton' }, regular: 5.00, sale: 4.00, policy: :standard }]
109
+ )
110
+ product_2 = create_complete_product(
111
+ variants: [{ sku: 'SKU2', details: { material: 'cotton' }, regular: 5.00, sale: 4.00, on_sale: true, policy: :standard }]
112
+ )
113
+ order = create_cart(
114
+ items: [
115
+ { product: product_1, sku: product_1.skus.first, quantity: 1 },
116
+ { product: product_2, sku: product_2.skus.first, quantity: 1 }
117
+ ]
118
+ )
119
+
120
+ Inventory::Sku.find('SKU2').update_attributes(available: 0)
121
+
122
+ post storefront.globale_receive_order_path,
123
+ headers: { 'CONTENT_TYPE' => 'application/json' },
124
+ params: global_e_send_order_to_mechant_body(order: order)
125
+
126
+ refute response.ok?
127
+ assert_equal "500", response.code
128
+
129
+ response_body = JSON.parse response.body
130
+ expected_body = {
131
+ "InternalOrderId" => order.id,
132
+ "OrderId" => nil,
133
+ "StatusCode" => nil,
134
+ "PaymentCurrencyCode" => nil,
135
+ "PaymentAmount" => nil,
136
+ "Success" => false,
137
+ "ErrorCode" => nil,
138
+ "Message" => "insufficient inventory for SKU: SKU2",
139
+ "Description" => nil
140
+ }
141
+ assert_equal expected_body, response_body
142
+
143
+ api_events = GlobalE::OrderApiEvents.find(order.id)
144
+ assert api_events.receive_order.present?
145
+ assert api_events.receive_order_response.present?
146
+ end
147
+
148
+ def test_order_locked
149
+ order = create_cart
150
+
151
+ order.lock!
152
+
153
+ post storefront.globale_receive_order_path,
154
+ headers: { 'CONTENT_TYPE' => 'application/json' },
155
+ params: global_e_send_order_to_mechant_body(order: order)
156
+
157
+ refute response.ok?
158
+ assert_equal "500", response.code
159
+
160
+ response_body = JSON.parse response.body
161
+ expected_body = {
162
+ "InternalOrderId" => order.id,
163
+ "OrderId" => nil,
164
+ "StatusCode" => nil,
165
+ "PaymentCurrencyCode" => nil,
166
+ "PaymentAmount" => nil,
167
+ "Success" => false,
168
+ "ErrorCode" => nil,
169
+ "Message" => "workarea/order/#{order.id}/lock is already locked",
170
+ "Description" => nil
171
+ }
172
+ assert_equal expected_body, response_body
173
+
174
+ api_events = GlobalE::OrderApiEvents.find(order.id)
175
+ assert api_events.receive_order.present?
176
+ assert api_events.receive_order_response.present?
177
+ end
178
+
179
+ def test_failing_to_place_order
180
+ order = create_cart
181
+
182
+ post storefront.globale_receive_order_path,
183
+ headers: { 'CONTENT_TYPE' => 'application/json' },
184
+ params: global_e_send_order_to_mechant_body(email: "epigeon%40weblinc", order: order)
185
+
186
+ refute response.ok?
187
+ assert_equal "500", response.code
188
+
189
+ response_body = JSON.parse response.body
190
+ expected_body = {
191
+ "InternalOrderId" => order.id,
192
+ "OrderId" => nil,
193
+ "StatusCode" => nil,
194
+ "PaymentCurrencyCode" => nil,
195
+ "PaymentAmount" => nil,
196
+ "Success" => false,
197
+ "ErrorCode" => nil,
198
+ "Message" => "Email is invalid",
199
+ "Description" => nil
200
+ }
201
+ assert_equal expected_body, response_body
202
+
203
+ api_events = GlobalE::OrderApiEvents.find(order.id)
204
+ assert api_events.receive_order.present?
205
+ assert api_events.receive_order_response.present?
206
+ end
207
+
208
+ def test_with_shipping_discounts
209
+ order = create_cart
210
+
211
+ post storefront.globale_receive_order_path,
212
+ headers: { 'CONTENT_TYPE' => 'application/json' },
213
+ params: global_e_send_order_to_merchant_with_shipping_discounts_body(order: order)
214
+
215
+ assert response.ok?, "Expected 200 response"
216
+
217
+ shipping = Workarea::Shipping.find_by(order_id: order.id)
218
+
219
+ assert_equal 2, shipping.price_adjustments.size
220
+ assert_equal 2, shipping.international_price_adjustments.size
221
+
222
+ order.reload
223
+
224
+ assert_equal 1, order.discount_adjustments.size
225
+ assert_equal 1, order.international_discount_adjustments.size
226
+ end
227
+
228
+ def test_updating_user_addresses
229
+ user = create_user(
230
+ addresses: [
231
+ {
232
+ first_name: 'Ben',
233
+ last_name: 'Crouse',
234
+ street: '22 S. 3rd St.',
235
+ city: 'Philadelphia',
236
+ region: 'PA',
237
+ postal_code: '19106',
238
+ country: 'US',
239
+ phone_number: '2159251800',
240
+ last_billed_at: Time.current
241
+ },
242
+ {
243
+ first_name: 'Ben',
244
+ last_name: 'Crouse',
245
+ street: '22 S. 3rd St.',
246
+ city: 'Philadelphia',
247
+ region: 'PA',
248
+ postal_code: '19106',
249
+ country: 'US',
250
+ phone_number: '2159251800',
251
+ last_billed_at: Time.current
252
+ }
253
+ ]
254
+ )
255
+ order = create_cart(user: user)
256
+
257
+ post storefront.globale_receive_order_path,
258
+ headers: { 'CONTENT_TYPE' => 'application/json' },
259
+ params: global_e_send_order_to_mechant_body(order: order, user: user)
260
+
261
+ assert response.ok?, "Expected 200 response"
262
+
263
+ response_body = JSON.parse response.body
264
+ assert response_body["Success"]
265
+ assert_equal order.id, response_body["InternalOrderId"]
266
+
267
+ order.reload
268
+ assert_equal "GE927127", order.global_e_id
269
+ assert order.placed?
270
+ assert order.global_e?
271
+
272
+ user.reload
273
+ assert_equal 2, user.addresses.size
274
+ end
275
+ end
276
+ end
277
+ end
278
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ module GlobalEAPi
6
+ class ReceiveOrderRefundIntegrationTest < Workarea::IntegrationTest
7
+ include GlobalESupport
8
+
9
+ def test_successful_post
10
+ order = create_global_e_shipped_order
11
+
12
+ post storefront.globale_receive_order_refund_path,
13
+ headers: { 'CONTENT_TYPE' => 'application/json' },
14
+ params: global_e_notify_order_refunded_body(order: order)
15
+
16
+ assert response.ok?
17
+
18
+ fulfillment = Fulfillment.find order.id
19
+
20
+ assert_equal :refunded, fulfillment.status
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ module GlobalEAPi
6
+ class ReceivePaymentIntegrationTest < Workarea::IntegrationTest
7
+ include GlobalESupport
8
+
9
+ def test_successful_post
10
+ order = create_global_e_completed_checkout
11
+
12
+ post storefront.globale_receive_payment_path,
13
+ headers: { 'CONTENT_TYPE' => 'application/json' },
14
+ params: global_e_peform_order_payment_body(order: order)
15
+
16
+ assert response.ok?
17
+
18
+ order.reload
19
+ assert order.placed?
20
+
21
+ fulfillment = Fulfillment.find order.id
22
+ assert_equal(
23
+ "https%3a%2f%2fqa.bglobale.com%2fOrder%2fTrack%2fmZ7c%3fOrderId%3dGE2130509US%26ShippingEmail%3dalextest%40test.com",
24
+ fulfillment.global_e_tracking_url
25
+ )
26
+
27
+ api_events = GlobalE::OrderApiEvents.find(order.id)
28
+ assert api_events.receive_payment.present?
29
+ assert api_events.receive_payment_response.present?
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ module GlobalEApi
6
+ class ReceiveShippingInfoIntegrationTest < Workarea::IntegrationTest
7
+ include GlobalESupport
8
+
9
+ def test_successful_shipping_info
10
+ order = create_global_e_placed_order
11
+
12
+ post storefront.globale_receive_shipping_info_path,
13
+ headers: { 'CONTENT_TYPE' => 'application/json' },
14
+ params: global_e_update_order_shipping_info_body(order: order)
15
+
16
+ assert response.ok?
17
+
18
+ fulfillment = Fulfillment.find order.id
19
+
20
+ assert_equal :shipped, fulfillment.status
21
+
22
+ api_events = GlobalE::OrderApiEvents.find(order.id)
23
+ assert api_events.receive_shipping_info.present?
24
+ assert api_events.receive_shipping_info_response.present?
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ module GlobalEApi
6
+ class RemoveRestrictedProductsIntegrationTest < Workarea::IntegrationTest
7
+ include GlobalESupport
8
+
9
+ def test_successful_post
10
+ order = create_global_e_completed_checkout
11
+ path = storefront.globale_remove_restricted_products_path(
12
+ format: :json
13
+ )
14
+
15
+ post path, params: {
16
+ 'MerchantGUID' => "abcdabcd-abcd-abcd-abcd-abcdabcdabcd",
17
+ 'CartId' => order.global_e_token,
18
+ 'RemovedProductCodes' => order.items.map(&:sku)
19
+ }
20
+
21
+ assert_empty(order.reload.items)
22
+ assert_response(:success)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ module GlobalEAPi
6
+ class UpdateOrderStatusIntegrationTest < Workarea::IntegrationTest
7
+ include GlobalESupport
8
+
9
+ def test_successful_canceled_order_post
10
+ order = create_global_e_completed_checkout
11
+
12
+ post storefront.globale_update_order_status_path,
13
+ headers: { 'CONTENT_TYPE' => 'application/json' },
14
+ params: global_e_update_order_status_body(global_e_order_id: order.global_e_id)
15
+
16
+ assert response.ok?
17
+
18
+ order.reload
19
+ assert order.canceled?
20
+ assert_equal :canceled, order.status
21
+
22
+ api_events = GlobalE::OrderApiEvents.find(order.id)
23
+ assert api_events.update_order_status.present?
24
+ assert api_events.update_order_status_response.present?
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end