workarea-orderbot 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  3. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.github/workflows/ci.yml +58 -0
  6. data/.gitignore +23 -0
  7. data/.rubocop.yml +3 -0
  8. data/CHANGELOG.md +58 -0
  9. data/Gemfile +17 -0
  10. data/LICENSE +52 -0
  11. data/README.md +100 -0
  12. data/Rakefile +59 -0
  13. data/app/assets/images/workarea/admin/orderbot/.keep +0 -0
  14. data/app/assets/images/workarea/storefront/orderbot/.keep +0 -0
  15. data/app/assets/javascripts/workarea/admin/orderbot/.keep +0 -0
  16. data/app/assets/javascripts/workarea/storefront/orderbot/.keep +0 -0
  17. data/app/assets/stylesheets/workarea/admin/orderbot/.keep +0 -0
  18. data/app/assets/stylesheets/workarea/storefront/orderbot/.keep +0 -0
  19. data/app/controllers/.keep +0 -0
  20. data/app/helpers/.keep +0 -0
  21. data/app/mailers/.keep +0 -0
  22. data/app/models/workarea/order.decorator +19 -0
  23. data/app/models/workarea/orderbot/import_log.rb +19 -0
  24. data/app/models/workarea/orderbot/pricing_import_data.rb +13 -0
  25. data/app/models/workarea/orderbot/product_import_data.rb +32 -0
  26. data/app/models/workarea/user.decorator +7 -0
  27. data/app/services/workarea/orderbot/child_product.rb +108 -0
  28. data/app/services/workarea/orderbot/filters.rb +33 -0
  29. data/app/services/workarea/orderbot/order.rb +146 -0
  30. data/app/services/workarea/orderbot/order/item.rb +69 -0
  31. data/app/services/workarea/orderbot/order/tender/credit_card.rb +43 -0
  32. data/app/services/workarea/orderbot/order/tender/general.rb +32 -0
  33. data/app/services/workarea/orderbot/order/tender/gift_card.rb +32 -0
  34. data/app/services/workarea/orderbot/order/tender/store_credit.rb +32 -0
  35. data/app/services/workarea/orderbot/parent_product.rb +87 -0
  36. data/app/views/.keep +0 -0
  37. data/app/workers/workarea/orderbot/fulfillment/import_fulfillments.rb +37 -0
  38. data/app/workers/workarea/orderbot/fulfillment_importer.rb +50 -0
  39. data/app/workers/workarea/orderbot/inventory/import_inventory.rb +50 -0
  40. data/app/workers/workarea/orderbot/inventory_importer.rb +57 -0
  41. data/app/workers/workarea/orderbot/pricing/import_pricing.rb +42 -0
  42. data/app/workers/workarea/orderbot/pricing_importer.rb +70 -0
  43. data/app/workers/workarea/orderbot/product/import_child_products.rb +24 -0
  44. data/app/workers/workarea/orderbot/product/import_parent_products.rb +32 -0
  45. data/app/workers/workarea/orderbot/product_importer.rb +72 -0
  46. data/app/workers/workarea/orderbot/save_order.rb +38 -0
  47. data/bin/rails +25 -0
  48. data/config/initializers/configurations.rb +60 -0
  49. data/config/initializers/scheduled_jobs.rb +28 -0
  50. data/config/initializers/workarea.rb +16 -0
  51. data/config/routes.rb +2 -0
  52. data/lib/workarea/orderbot.rb +43 -0
  53. data/lib/workarea/orderbot/authentication.rb +41 -0
  54. data/lib/workarea/orderbot/bogus_gateway.rb +629 -0
  55. data/lib/workarea/orderbot/engine.rb +10 -0
  56. data/lib/workarea/orderbot/gateway.rb +102 -0
  57. data/lib/workarea/orderbot/response.rb +29 -0
  58. data/lib/workarea/orderbot/version.rb +5 -0
  59. data/test/dummy/Rakefile +6 -0
  60. data/test/dummy/app/assets/config/manifest.js +3 -0
  61. data/test/dummy/app/assets/images/.keep +0 -0
  62. data/test/dummy/app/assets/javascripts/application.js +14 -0
  63. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  64. data/test/dummy/app/controllers/application_controller.rb +2 -0
  65. data/test/dummy/app/controllers/concerns/.keep +0 -0
  66. data/test/dummy/app/helpers/application_helper.rb +2 -0
  67. data/test/dummy/app/jobs/application_job.rb +2 -0
  68. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  69. data/test/dummy/app/models/concerns/.keep +0 -0
  70. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  71. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  72. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  73. data/test/dummy/bin/bundle +3 -0
  74. data/test/dummy/bin/rails +4 -0
  75. data/test/dummy/bin/rake +4 -0
  76. data/test/dummy/bin/setup +25 -0
  77. data/test/dummy/bin/update +25 -0
  78. data/test/dummy/config.ru +5 -0
  79. data/test/dummy/config/application.rb +34 -0
  80. data/test/dummy/config/boot.rb +5 -0
  81. data/test/dummy/config/environment.rb +5 -0
  82. data/test/dummy/config/environments/development.rb +52 -0
  83. data/test/dummy/config/environments/production.rb +83 -0
  84. data/test/dummy/config/environments/test.rb +45 -0
  85. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  86. data/test/dummy/config/initializers/assets.rb +12 -0
  87. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  88. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  89. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  90. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  91. data/test/dummy/config/initializers/inflections.rb +16 -0
  92. data/test/dummy/config/initializers/mime_types.rb +4 -0
  93. data/test/dummy/config/initializers/workarea.rb +5 -0
  94. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  95. data/test/dummy/config/locales/en.yml +33 -0
  96. data/test/dummy/config/puma.rb +34 -0
  97. data/test/dummy/config/routes.rb +5 -0
  98. data/test/dummy/config/spring.rb +6 -0
  99. data/test/dummy/db/seeds.rb +2 -0
  100. data/test/dummy/lib/assets/.keep +0 -0
  101. data/test/dummy/log/.keep +0 -0
  102. data/test/services/workarea/orderbot/order_test.rb +151 -0
  103. data/test/services/workarea/orderbot/product/child_product_test.rb +255 -0
  104. data/test/services/workarea/orderbot/product/parent_product_test.rb +106 -0
  105. data/test/teaspoon_env.rb +6 -0
  106. data/test/test_helper.rb +10 -0
  107. data/test/workers/workarea/orderbot/fulfillment/import_fulfillments_test.rb +41 -0
  108. data/test/workers/workarea/orderbot/fulfillment_importer_test.rb +29 -0
  109. data/test/workers/workarea/orderbot/inventory/import_inventory_test.rb +49 -0
  110. data/test/workers/workarea/orderbot/inventory_importer_test.rb +21 -0
  111. data/test/workers/workarea/orderbot/pricing/import_pricing_test.rb +61 -0
  112. data/test/workers/workarea/orderbot/pricing_importer_test.rb +29 -0
  113. data/test/workers/workarea/orderbot/product_importer_test.rb +23 -0
  114. data/test/workers/workarea/orderbot/save_order_test.rb +41 -0
  115. data/workarea-orderbot.gemspec +20 -0
  116. metadata +172 -0
@@ -0,0 +1,45 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure public file server for tests with Cache-Control for performance.
16
+ config.public_file_server.enabled = true
17
+ config.public_file_server.headers = {
18
+ 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
19
+ }
20
+
21
+ # Show full error reports and disable caching.
22
+ config.consider_all_requests_local = true
23
+ config.action_controller.perform_caching = false
24
+
25
+ # Raise exceptions instead of rendering exception templates.
26
+ config.action_dispatch.show_exceptions = false
27
+
28
+ # Disable request forgery protection in test environment.
29
+ config.action_controller.allow_forgery_protection = false
30
+
31
+ config.action_mailer.perform_caching = false
32
+
33
+ # Tell Action Mailer not to deliver emails to the real world.
34
+ # The :test delivery method accumulates sent emails in the
35
+ # ActionMailer::Base.deliveries array.
36
+ config.action_mailer.delivery_method = :test
37
+
38
+ # Print deprecation notices to the stderr.
39
+ config.active_support.deprecation = :stderr
40
+
41
+ # Raises error for missing translations
42
+ # config.action_view.raise_on_missing_translations = true
43
+
44
+ config.cache_store = :null_store
45
+ end
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # ActiveSupport::Reloader.to_prepare do
4
+ # ApplicationController.renderer.defaults.merge!(
5
+ # http_host: 'example.org',
6
+ # https: false
7
+ # )
8
+ # end
@@ -0,0 +1,12 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Version of your assets, change this if you want to expire all your assets.
4
+ Rails.application.config.assets.version = '1.0'
5
+
6
+ # Add additional assets to the asset load path.
7
+ # Rails.application.config.assets.paths << Emoji.images_path
8
+
9
+ # Precompile additional assets.
10
+ # application.js, application.css, and all non-JS/CSS in the app/assets
11
+ # folder are already added.
12
+ # Rails.application.config.assets.precompile += %w( admin.js admin.css )
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,25 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Define an application-wide content security policy
4
+ # For further information see the following documentation
5
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
6
+
7
+ # Rails.application.config.content_security_policy do |policy|
8
+ # policy.default_src :self, :https
9
+ # policy.font_src :self, :https, :data
10
+ # policy.img_src :self, :https, :data
11
+ # policy.object_src :none
12
+ # policy.script_src :self, :https
13
+ # policy.style_src :self, :https
14
+
15
+ # # Specify URI for violation reports
16
+ # # policy.report_uri "/csp-violation-report-endpoint"
17
+ # end
18
+
19
+ # If you are using UJS then enable automatic nonce generation
20
+ # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
21
+
22
+ # Report CSP violations to a specified URI
23
+ # For further information see the following documentation:
24
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
25
+ # Rails.application.config.content_security_policy_report_only = true
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Specify a serializer for the signed and encrypted cookie jars.
4
+ # Valid options are :json, :marshal, and :hybrid.
5
+ Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, '\1en'
8
+ # inflect.singular /^(ox)en/i, '\1'
9
+ # inflect.irregular 'person', 'people'
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
@@ -0,0 +1,5 @@
1
+ Workarea.configure do |config|
2
+ # Basic site info
3
+ config.site_name = 'Workarea Orderbot'
4
+ config.host = 'www.example.com'
5
+ end
@@ -0,0 +1,9 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
@@ -0,0 +1,33 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # The following keys must be escaped otherwise they will not be retrieved by
20
+ # the default I18n backend:
21
+ #
22
+ # true, false, on, off, yes, no
23
+ #
24
+ # Instead, surround them with single quotes.
25
+ #
26
+ # en:
27
+ # 'true': 'foo'
28
+ #
29
+ # To learn more, please read the Rails Internationalization guide
30
+ # available at http://guides.rubyonrails.org/i18n.html.
31
+
32
+ en:
33
+ hello: "Hello world"
@@ -0,0 +1,34 @@
1
+ # Puma can serve each request in a thread from an internal thread pool.
2
+ # The `threads` method setting takes two numbers: a minimum and maximum.
3
+ # Any libraries that use thread pools should be configured to match
4
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
+ # and maximum; this matches the default thread size of Active Record.
6
+ #
7
+ threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8
+ threads threads_count, threads_count
9
+
10
+ # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
11
+ #
12
+ port ENV.fetch("PORT") { 3000 }
13
+
14
+ # Specifies the `environment` that Puma will run in.
15
+ #
16
+ environment ENV.fetch("RAILS_ENV") { "development" }
17
+
18
+ # Specifies the number of `workers` to boot in clustered mode.
19
+ # Workers are forked webserver processes. If using threads and workers together
20
+ # the concurrency of the application would be max `threads` * `workers`.
21
+ # Workers do not work on JRuby or Windows (both of which do not support
22
+ # processes).
23
+ #
24
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
25
+
26
+ # Use the `preload_app!` method when specifying a `workers` number.
27
+ # This directive tells Puma to first boot the application and load code
28
+ # before forking the application. This takes advantage of Copy On Write
29
+ # process behavior so workers use less memory.
30
+ #
31
+ # preload_app!
32
+
33
+ # Allow puma to be restarted by `rails restart` command.
34
+ plugin :tmp_restart
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ mount Workarea::Core::Engine => '/'
3
+ mount Workarea::Admin::Engine => '/admin', as: 'admin'
4
+ mount Workarea::Storefront::Engine => '/', as: 'storefront'
5
+ end
@@ -0,0 +1,6 @@
1
+ %w[
2
+ .ruby-version
3
+ .rbenv-vars
4
+ tmp/restart.txt
5
+ tmp/caching-dev.txt
6
+ ].each { |path| Spring.watch(path) }
@@ -0,0 +1,2 @@
1
+ require 'workarea/seeds'
2
+ Workarea::Seeds.run
File without changes
File without changes
@@ -0,0 +1,151 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Orderbot
5
+ class OrderTest < Workarea::TestCase
6
+ def test_to_a
7
+ Workarea.config.inventory_distribution_center_id = 100
8
+ Workarea.config.default_order_guide_id = 200
9
+
10
+ create_order_total_discount(order_total: 1.to_m)
11
+
12
+ order = Workarea::Storefront::OrderViewModel.new(create_placed_order)
13
+ orderbot_order = Orderbot::Order.new(order.id).to_a.first
14
+
15
+ assert_equal(order.id, orderbot_order[:reference_order_id])
16
+ assert_equal("unshipped", orderbot_order[:order_status])
17
+ assert_equal(order.email, orderbot_order[:reference_account_id])
18
+ assert_equal(order.email, orderbot_order[:reference_customer_id])
19
+ assert_equal(100, orderbot_order[:distribution_center_id])
20
+ assert_equal(200, orderbot_order[:order_guide_id])
21
+ assert_equal(order.email, orderbot_order[:email_confirmation_address])
22
+ assert_equal(8.0, orderbot_order[:subtotal])
23
+ assert_equal(1.0, orderbot_order[:order_discount])
24
+ assert_equal(order.total_price.to_f, orderbot_order[:order_total])
25
+
26
+ order_taxes = orderbot_order[:taxes].first
27
+ assert_equal(order.tax_total, order_taxes[:amount])
28
+
29
+ shipping_info = orderbot_order[:shipping_info]
30
+ assert_equal(1.0, shipping_info[:shipping_total])
31
+
32
+ ship_to = orderbot_order[:ship_to]
33
+ assert_equal(order.shipping_address.first_name, ship_to[:first_name])
34
+ assert_equal(order.shipping_address.last_name, ship_to[:last_name])
35
+ assert_equal(order.shipping_address.street, ship_to[:address])
36
+ assert_equal(order.shipping_address.street_2, ship_to[:address2])
37
+ assert_equal(order.shipping_address.city, ship_to[:city])
38
+ assert_equal(order.shipping_address.region, ship_to[:state_name])
39
+ assert_equal(order.shipping_address.postal_code, ship_to[:postal_code])
40
+ assert_equal(order.shipping_address.country.alpha2, ship_to[:country])
41
+
42
+ billing_to = orderbot_order[:billing_to]
43
+ assert_equal(order.billing_address.first_name, billing_to[:first_name])
44
+ assert_equal(order.billing_address.last_name, billing_to[:last_name])
45
+ assert_equal(order.billing_address.street, billing_to[:address])
46
+ assert_equal(order.billing_address.street_2, billing_to[:address2])
47
+ assert_equal(order.billing_address.city, billing_to[:city])
48
+ assert_equal(order.billing_address.region, billing_to[:state_name])
49
+ assert_equal(order.billing_address.postal_code, billing_to[:postal_code])
50
+ assert_equal(order.billing_address.country.alpha2, billing_to[:country])
51
+ assert_equal(order.email, billing_to[:email])
52
+
53
+ ob_item = orderbot_order[:order_items].first
54
+ wa_item = order.items.first
55
+ assert_equal(wa_item.id.to_s, ob_item[:order_line_id])
56
+ assert_equal(wa_item.sku, ob_item[:sku])
57
+ assert_equal(wa_item.quantity, ob_item[:quantity])
58
+ assert_equal(5.0, ob_item[:unit_price])
59
+ assert_equal(1.0, ob_item[:discount])
60
+ assert_equal(9.0, ob_item[:total])
61
+
62
+ wa_tender = Workarea::Payment.find(order.id).tenders.first
63
+ ob_tender = orderbot_order[:payments].first
64
+
65
+ assert_equal(wa_tender.id.to_s, ob_tender[:payment_reference_id])
66
+ assert_equal("credit_card", ob_tender[:payment_type])
67
+ assert_equal("test_card", ob_tender[:payment_method_type])
68
+ assert_equal(10.0, ob_tender[:amount_paid])
69
+ end
70
+
71
+ def test_multiple_tenders
72
+ order = Workarea::Storefront::OrderViewModel.new(create_placed_dual_tender_order)
73
+ orderbot_order = Orderbot::Order.new(order.id).to_a.first
74
+ payments = orderbot_order[:payments]
75
+
76
+ assert_equal(2, payments.size)
77
+
78
+ credit_card = payments.detect { |p| p[:payment_type] == "credit_card" }
79
+ assert_equal("visa", credit_card[:payment_method_type])
80
+
81
+ store_credit = payments.detect { |p| p[:payment_type] == "cheque" }
82
+ assert_equal("paid_from_web", store_credit[:payment_method_type])
83
+ end
84
+
85
+ private
86
+
87
+ def create_placed_dual_tender_order(overrides = {}, options = {})
88
+ attributes = {
89
+ id: '1234',
90
+ email: 'tester@workarea.com',
91
+ placed_at: Time.current,
92
+ ip_address: '127.0.0.1',
93
+ user_agent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0 Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0.'
94
+ }.merge(overrides)
95
+
96
+ shipping_service = create_shipping_service
97
+ sku = 'SKU'
98
+ create_product(variants: [{ sku: sku, regular: 5.to_m }])
99
+ details = OrderItemDetails.find(sku)
100
+ order = Workarea::Order.new(attributes)
101
+ item = { sku: sku, quantity: 2 }.merge(details.to_h)
102
+
103
+ order.add_item(item)
104
+
105
+ checkout = Checkout.new(order)
106
+ checkout.update(
107
+ shipping_address: {
108
+ first_name: 'Ben',
109
+ last_name: 'Crouse',
110
+ street: '22 S. 3rd St.',
111
+ street_2: 'Second Floor',
112
+ city: 'Philadelphia',
113
+ region: 'PA',
114
+ postal_code: '19106',
115
+ country: 'US'
116
+ },
117
+ billing_address: {
118
+ first_name: 'Ben',
119
+ last_name: 'Crouse',
120
+ street: '12 N. 3rd St.',
121
+ street_2: 'thrid floor',
122
+ city: 'Philadelphia',
123
+ region: 'PA',
124
+ postal_code: '19106',
125
+ country: 'US'
126
+ },
127
+ shipping_service: shipping_service.name,
128
+ )
129
+
130
+ checkout.payment_profile.store_credit = 1.0
131
+ checkout.payment.build_store_credit
132
+
133
+ checkout.update(
134
+ payment: 'new_card',
135
+ credit_card: {
136
+ number: '4111111111111111',
137
+ month: '1',
138
+ year: Time.current.year + 1,
139
+ cvv: '999'
140
+ }
141
+ )
142
+
143
+ checkout.place_order
144
+
145
+ forced_attrs = overrides.slice(:placed_at, :update_at, :total_price)
146
+ order.update_attributes!(forced_attrs)
147
+ order
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,255 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Orderbot
5
+ module Product
6
+ class ChildProductTest < Workarea::TestCase
7
+ setup :create_import_products
8
+
9
+ def test_process
10
+ Orderbot::ParentProduct.new(@parent_product).process
11
+ Orderbot::ChildProduct.new(@child_product).process
12
+
13
+ product = Workarea::Catalog::Product.first
14
+ pricing = Workarea::Pricing::Sku.first
15
+ shipping = Workarea::Shipping::Sku.first
16
+
17
+ assert_equal(1, product.variants.size)
18
+
19
+ variant = product.variants.first
20
+ assert_equal("BTUSB01", variant.sku)
21
+ assert_equal("Blue Tooth USB BLUE", variant.name)
22
+ assert(variant.details.present?)
23
+
24
+ assert_equal(1, pricing.prices.size)
25
+ assert_equal(50.to_m, pricing.sell_price)
26
+
27
+ assert_equal(16, shipping.weight) # 1lb converted to oz.
28
+ assert_equal([1, 2, 3], shipping.dimensions)
29
+ product.reload
30
+
31
+ assert_equal(["Red", "Pink"], product.filters["color"])
32
+ assert_equal(["cotton", "metal"], product.filters["material"])
33
+ assert_equal("Electronics", product.filters[:orderbot_category])
34
+ assert_equal("Accessories", product.filters[:orderbot_group])
35
+ end
36
+
37
+ def test_process_orderguide_price
38
+ Orderbot::ParentProduct.new(@parent_product).process
39
+ Orderbot::ChildProduct.new(@order_guide_price_product).process
40
+
41
+ pricing = Workarea::Pricing::Sku.first
42
+
43
+ assert_equal(1, pricing.prices.size)
44
+ assert_equal(40.to_m, pricing.sell_price)
45
+ end
46
+
47
+ def test_process_no_sku
48
+ Orderbot::ParentProduct.new(@parent_product).process
49
+
50
+ assert_raise Workarea::Orderbot::ChildProduct::ChildProductImportError do
51
+ Orderbot::ChildProduct.new(@no_sku_child_product).process
52
+ end
53
+ end
54
+
55
+ def test_process_no_parent_product
56
+ assert_raise Workarea::Orderbot::ChildProduct::NoParentProductImportError do
57
+ Orderbot::ChildProduct.new(@child_product).process
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def create_import_products
64
+ product_attrs = {
65
+ product_id: 3166006,
66
+ name: "Blue Tooth USB",
67
+ sku: nil,
68
+ upc: "BTUSB001",
69
+ active: true,
70
+ taxable: true,
71
+ base_price: 1,
72
+ orderguide_price: nil,
73
+ units_of_measure: "Each",
74
+ shipping_weight: 1,
75
+ shipping_weight_measurement_unit: "Lbs",
76
+ has_children: true,
77
+ parent_id: 0,
78
+ class_type: "Sales Items",
79
+ group_id: 20693,
80
+ group: "Accessories",
81
+ category_id: 5462,
82
+ category: "Electronics",
83
+ first_variable: {
84
+ group: "phone color",
85
+ type: "color",
86
+ value: "Red"
87
+ },
88
+ second_variable: {
89
+ group: "material",
90
+ type: "material",
91
+ value: "cotton"
92
+ },
93
+ descriptive_title: "",
94
+ description: "Test",
95
+ other_info: "",
96
+ creation_date: nil,
97
+ last_updated: "2019-04-02T13:10:03.29",
98
+ updated_by: 282517,
99
+ shipping_height: 1,
100
+ shipping_width: 2,
101
+ shipping_length: 3,
102
+ workarea_info: {
103
+ template: "",
104
+ purchase_start_date: nil,
105
+ purchase_end_date: nil
106
+ }
107
+ }
108
+
109
+ @parent_product = Orderbot::ProductImportData.create!(product_data: product_attrs)
110
+
111
+ child_product_attrs = {
112
+ product_id: 3166007,
113
+ name: "Blue Tooth USB BLUE",
114
+ sku: "BTUSB01",
115
+ upc: "BTUSB00122",
116
+ active: true,
117
+ taxable: true,
118
+ base_price: 50,
119
+ orderguide_price: nil,
120
+ units_of_measure: "Each",
121
+ shipping_weight: 1,
122
+ shipping_weight_measurement_unit: "Lbs",
123
+ has_children: true,
124
+ parent_id: 3166006,
125
+ class_type: "Sales Items",
126
+ group_id: 20693,
127
+ group: "Accessories",
128
+ category_id: 5462,
129
+ category: "Electronics",
130
+ first_variable: {
131
+ group: "phone colors",
132
+ type: "color",
133
+ value: "Pink"
134
+ },
135
+ second_variable: {
136
+ group: "material",
137
+ type: "material",
138
+ value: "metal"
139
+ },
140
+ descriptive_title: "",
141
+ description: "Test",
142
+ other_info: "",
143
+ creation_date: nil,
144
+ last_updated: "2019-04-02T13:10:03.29",
145
+ updated_by: 282517,
146
+ shipping_height: 1,
147
+ shipping_width: 2,
148
+ shipping_length: 3,
149
+ workarea_info: {
150
+ template: "",
151
+ purchase_start_date: nil,
152
+ purchase_end_date: nil
153
+ }
154
+ }
155
+
156
+ @child_product = Orderbot::ProductImportData.create!(parent_product_id: 3166006, product_data: child_product_attrs)
157
+
158
+ order_guide_product_attrs = {
159
+ product_id: 3166007,
160
+ name: "Blue Tooth USB BLUE",
161
+ sku: "BTUSB01",
162
+ upc: "BTUSB00122",
163
+ active: true,
164
+ taxable: true,
165
+ base_price: 50,
166
+ orderguide_price: 40,
167
+ units_of_measure: "Each",
168
+ shipping_weight: 1,
169
+ shipping_weight_measurement_unit: "Lbs",
170
+ has_children: true,
171
+ parent_id: 3166006,
172
+ class_type: "Sales Items",
173
+ group_id: 20693,
174
+ group: "Accessories",
175
+ category_id: 5462,
176
+ category: "Electronics",
177
+ first_variable: {
178
+ group: "phone colors",
179
+ type: "color",
180
+ value: "Pink"
181
+ },
182
+ second_variable: {
183
+ group: "material",
184
+ type: "material",
185
+ value: "metal"
186
+ },
187
+ descriptive_title: "",
188
+ description: "Test",
189
+ other_info: "",
190
+ creation_date: nil,
191
+ last_updated: "2019-04-02T13:10:03.29",
192
+ updated_by: 282517,
193
+ shipping_height: 1,
194
+ shipping_width: 2,
195
+ shipping_length: 3,
196
+ workarea_info: {
197
+ template: "",
198
+ purchase_start_date: nil,
199
+ purchase_end_date: nil
200
+ }
201
+ }
202
+
203
+ @order_guide_price_product = Orderbot::ProductImportData.create!(parent_product_id: 3166006, product_data: order_guide_product_attrs)
204
+
205
+ no_sku_child_product_attrs = {
206
+ product_id: 3166008,
207
+ name: "Blue Tooth USB BLUE",
208
+ sku: nil,
209
+ upc: "BTUSB00122",
210
+ active: true,
211
+ taxable: true,
212
+ base_price: 50,
213
+ orderguide_price: nil,
214
+ units_of_measure: "Each",
215
+ shipping_weight: 1,
216
+ shipping_weight_measurement_unit: "Lbs",
217
+ has_children: true,
218
+ parent_id: 3166006,
219
+ class_type: "Sales Items",
220
+ group_id: 20693,
221
+ group: "Accessories",
222
+ category_id: 5462,
223
+ category: "Electronics",
224
+ first_variable: {
225
+ group: "Phone Colors",
226
+ type: "color",
227
+ value: "Pink"
228
+ },
229
+ second_variable: {
230
+ group: "material",
231
+ type: "material",
232
+ value: "metal"
233
+ },
234
+ descriptive_title: "",
235
+ description: "Test",
236
+ other_info: "",
237
+ creation_date: nil,
238
+ last_updated: "2019-04-02T13:10:03.29",
239
+ updated_by: 282517,
240
+ shipping_height: 1,
241
+ shipping_width: 2,
242
+ shipping_length: 3,
243
+ workarea_info: {
244
+ template: "",
245
+ purchase_start_date: nil,
246
+ purchase_end_date: nil
247
+ }
248
+ }
249
+
250
+ @no_sku_child_product = Orderbot::ProductImportData.create!(parent_product_id: 3166006, product_data: no_sku_child_product_attrs)
251
+ end
252
+ end
253
+ end
254
+ end
255
+ end