workarea-orderbot 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,106 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Orderbot
5
+ module Product
6
+ class ParentProductTest < Workarea::TestCase
7
+ def test_process
8
+ parent_product = create_parent_product
9
+
10
+ Orderbot::ParentProduct.new(parent_product).process
11
+
12
+ product = Workarea::Catalog::Product.first
13
+ assert_equal("Blue Tooth USB", product.name)
14
+ assert_equal("Test", product.description)
15
+ assert_equal("Electronics", product.filters[:orderbot_category])
16
+ assert_equal("Accessories", product.filters[:orderbot_group])
17
+ assert_equal(["BTUSB001"], product.fetch_detail(:upc))
18
+ assert_equal("generic", product.template)
19
+
20
+ parent_product.update_attributes!(
21
+ product_data: {
22
+ product_id: 3166006,
23
+ name: "Blue Tooth USB",
24
+ sku: "BTUSB01",
25
+ upc: "BTUSB001",
26
+ active: true,
27
+ taxable: true,
28
+ base_price: 1,
29
+ orderguide_price: nil,
30
+ units_of_measure: "Each",
31
+ weight: 1,
32
+ shipping_unit_of_measure: "Lbs",
33
+ has_children: true,
34
+ parent_id: 0,
35
+ class_type: "Sales Items",
36
+ group_id: 20693,
37
+ group: "Accessories",
38
+ category: "Electronics",
39
+ first_variable_value: nil,
40
+ second_variable_value: nil,
41
+ descriptive_title: "",
42
+ description: "NEW DESCRIPTION",
43
+ other_info: "",
44
+ creation_date: nil,
45
+ last_updated: "2019-04-02T13:10:03.29",
46
+ updated_by: 282517,
47
+ workarea_info: {
48
+ template: "ob_test",
49
+ purchase_start_date: nil,
50
+ purchase_end_date: nil
51
+ }
52
+ }
53
+ )
54
+
55
+ Workarea.config.product_templates = [:ob_test]
56
+
57
+ Orderbot::ParentProduct.new(parent_product).process
58
+ product.reload
59
+ assert_equal(1, Workarea::Catalog::Product.count)
60
+ assert_equal("NEW DESCRIPTION", product.description)
61
+ assert_equal("ob_test", product.template)
62
+ end
63
+
64
+ private
65
+
66
+ def create_parent_product
67
+ product_attrs = {
68
+ product_id: 3166006,
69
+ name: "Blue Tooth USB",
70
+ sku: "BTUSB01",
71
+ upc: "BTUSB001",
72
+ active: true,
73
+ taxable: true,
74
+ base_price: 1,
75
+ orderguide_price: nil,
76
+ units_of_measure: "Each",
77
+ weight: 1,
78
+ shipping_unit_of_measure: "Lbs",
79
+ has_children: true,
80
+ parent_id: 0,
81
+ class_type: "Sales Items",
82
+ group_id: 20693,
83
+ group: "Accessories",
84
+ category_id: 5462,
85
+ category: "Electronics",
86
+ first_variable_value: nil,
87
+ second_variable_value: nil,
88
+ descriptive_title: "",
89
+ description: "Test",
90
+ other_info: "",
91
+ creation_date: nil,
92
+ last_updated: "2019-04-02T13:10:03.29",
93
+ updated_by: 282517,
94
+ workarea_info: {
95
+ template: "",
96
+ purchase_start_date: nil,
97
+ purchase_end_date: nil
98
+ }
99
+ }
100
+
101
+ Orderbot::ProductImportData.create!(product_data: product_attrs)
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,6 @@
1
+ require 'workarea/testing/teaspoon'
2
+
3
+ Teaspoon.configure do |config|
4
+ config.root = Workarea::Orderbot::Engine.root
5
+ Workarea::Teaspoon.apply(config)
6
+ end
@@ -0,0 +1,10 @@
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] = 'test'
3
+
4
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
+ require 'rails/test_help'
6
+ require 'workarea/test_help'
7
+
8
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
9
+ # to be shown.
10
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Orderbot
5
+ class Fulfillment::ImportfulFillmentTest < TestCase
6
+ def test_import_fulfillment
7
+ order = create_placed_order
8
+
9
+ fulfillment_data = {
10
+ order_id: "123456789",
11
+ reference_id: "1234",
12
+ purchase_order: "00984",
13
+ ship_date: "2020-01-17T20:26:50.889Z",
14
+ carrier_service_type: "USPS Priority",
15
+ ship_code: "FED",
16
+ packages: [
17
+ {
18
+ package_id: "3003216",
19
+ tracking_number: "1Z999AA10123456784",
20
+ items: [
21
+ {
22
+ package_item_id: "3003216",
23
+ product_id: "3003217",
24
+ sku: "SKU",
25
+ quantity: "2"
26
+ }
27
+ ]
28
+ }
29
+ ]
30
+ }
31
+
32
+ Workarea::Orderbot::Fulfillment::ImportFulfillments.new.perform(fulfillment_data)
33
+
34
+ fulfillment = Workarea::Fulfillment.find(order.id)
35
+
36
+ assert_equal(:shipped, fulfillment.status)
37
+ assert_equal(1, fulfillment.events.size)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Orderbot
5
+ class ImportfulFillmentTest < TestCase
6
+ def test_fulfillment_importer
7
+ create_placed_order(id: '1234')
8
+ create_placed_order(id: '4567')
9
+
10
+ Workarea.config.orderbot_api_email_address = "test@workarea.com"
11
+ Workarea.config.orderbot_api_password = "foobar"
12
+
13
+ assert_equal(0, Workarea::Orderbot::ImportLog.count)
14
+
15
+ Workarea::Orderbot::FulfillmentImporter.new.perform # uses Workarea::Orderbot::BogusGateway
16
+
17
+ full_ship = Workarea::Fulfillment.find('1234')
18
+ partial_ship = Workarea::Fulfillment.find('4567')
19
+
20
+ assert(:shipped, full_ship.status)
21
+ assert(:partially_shipped, partial_ship.status)
22
+
23
+ log = Workarea::Orderbot::ImportLog.where(importer: "fulfillment").first
24
+ assert(log.started_at.present?)
25
+ assert(log.finished_at.present?)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Orderbot
5
+ class Inventory::ImportInventoryTest < TestCase
6
+ def test_import_inventory
7
+ inventory_data = {
8
+ distribution_center_id: 454,
9
+ product_id: 2742840,
10
+ sku: "4444",
11
+ quantity_on_hand: 400.0,
12
+ updated_on: 5.minutes.ago
13
+ }
14
+
15
+ Workarea::Orderbot::Inventory::ImportInventory.new.perform(inventory_data)
16
+ sku = Workarea::Inventory::Sku.first
17
+
18
+ assert_equal(400, sku.available)
19
+ assert_equal("standard", sku.policy)
20
+
21
+ inventory_data[:quantity_on_hand] = 500
22
+
23
+ Workarea::Orderbot::Inventory::ImportInventory.new.perform(inventory_data)
24
+
25
+ sku.reload
26
+
27
+ # assert new sku was not created when upating
28
+ assert_equal(1, Workarea::Inventory::Sku.count)
29
+ assert_equal(500, sku.available)
30
+ end
31
+
32
+ def test_backordered_inventory
33
+ inventory_data = {
34
+ distribution_center_id: 454,
35
+ product_id: 2742840,
36
+ sku: "backordersku",
37
+ quantity_on_hand: 400.0,
38
+ updated_on: 5.minutes.ago
39
+ }
40
+
41
+ Workarea::Orderbot::Inventory::ImportInventory.new.perform(inventory_data)
42
+ sku = Workarea::Inventory::Sku.first
43
+
44
+ assert_equal(400, sku.available)
45
+ assert_equal("allow_backorder", sku.policy)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Orderbot
5
+ class ImportInventoryTest < TestCase
6
+ def test_inventory_importer
7
+ Workarea.config.orderbot_api_email_address = "test@workarea.com"
8
+ Workarea.config.orderbot_api_password = "foobar"
9
+
10
+ assert_equal(0, Workarea::Orderbot::ImportLog.count)
11
+
12
+ Workarea::Orderbot::InventoryImporter.new.perform # uses Workarea::Orderbot::BogusGateway
13
+ assert_equal(4, Workarea::Inventory::Sku.count)
14
+
15
+ log = Workarea::Orderbot::ImportLog.where(importer: "inventory").first
16
+ assert(log.started_at.present?)
17
+ assert(log.finished_at.present?)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Orderbot
5
+ class Inventory::ImportInventoryTest < TestCase
6
+ def test_import_price
7
+ pricing_data = {
8
+ force_schedule: nil,
9
+ last_updated_on: 5.minutes.ago,
10
+ original_price: 15.0,
11
+ price: 15.0,
12
+ product_id: 3592532,
13
+ sales_end_on: nil,
14
+ sales_start_on: nil,
15
+ sku: "SAMEPRICE1"
16
+ }
17
+
18
+ Orderbot::PricingImportData.create!(
19
+ order_guide_id: 1,
20
+ pricing_data: pricing_data
21
+ )
22
+
23
+ Workarea::Orderbot::Pricing::ImportPricing.new.perform
24
+ sku = Workarea::Pricing::Sku.first
25
+ price = sku.prices.first
26
+
27
+ assert_equal(15.to_m, price.regular)
28
+ refute(price.sale.present?)
29
+ refute(price.on_sale?)
30
+ refute(sku.on_sale?)
31
+ end
32
+
33
+ def test_import_sales_price
34
+ pricing_data = {
35
+ force_schedule: nil,
36
+ last_updated_on: 5.minutes.ago,
37
+ original_price: 15.0,
38
+ price: 10.0,
39
+ product_id: 3592532,
40
+ sales_end_on: nil,
41
+ sales_start_on: nil,
42
+ sku: "SALEPRICE1"
43
+ }
44
+
45
+ Orderbot::PricingImportData.create!(
46
+ order_guide_id: 1,
47
+ pricing_data: pricing_data
48
+ )
49
+
50
+ Workarea::Orderbot::Pricing::ImportPricing.new.perform
51
+ sku = Workarea::Pricing::Sku.first
52
+ price = sku.prices.first
53
+
54
+ assert_equal(15.to_m, price.regular)
55
+ assert_equal(10.to_m, price.sale)
56
+ assert(price.on_sale?)
57
+ assert(sku.on_sale?)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Orderbot::PricingImporterTest < TestCase
5
+ def test_pricing_import_data
6
+ Workarea.config.orderbot_api_email_address = "test@workarea.com"
7
+ Workarea.config.orderbot_api_password = "foobar"
8
+ Workarea.config.default_order_guide_id = 1
9
+
10
+ assert_equal(0, Workarea::Orderbot::ImportLog.count)
11
+
12
+ Workarea::Orderbot::PricingImporter.new.perform # uses data from Workarea::Orderbot::Bogusgateway
13
+
14
+ assert_equal(3, Workarea::Pricing::Sku.count)
15
+
16
+ sale_sku = Workarea::Pricing::Sku.find('SALE1')
17
+ assert(sale_sku.on_sale?)
18
+
19
+ price = sale_sku.prices.first
20
+
21
+ assert_equal(45.00.to_m, price.regular)
22
+ assert_equal(30.00.to_m, price.sale)
23
+
24
+ log = Workarea::Orderbot::ImportLog.where(importer: "pricing").first
25
+ assert(log.started_at.present?)
26
+ assert(log.finished_at.present?)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Orderbot::ProductImporterTest < TestCase
5
+ def test_product_import_data
6
+ Workarea.config.orderbot_api_email_address = "test@workarea.com"
7
+ Workarea.config.orderbot_api_password = "foobar"
8
+
9
+ assert_equal(0, Workarea::Orderbot::ImportLog.count)
10
+
11
+ Workarea::Orderbot::ProductImporter.new.perform # uses data from Workarea::Orderbot::Bogusgateway
12
+
13
+ assert_equal(0, Orderbot::ProductImportData.count)
14
+ assert_equal(2, Workarea::Catalog::Product.count)
15
+ assert_equal(3, Workarea::Pricing::Sku.count)
16
+ assert_equal(3, Workarea::Shipping::Sku.count)
17
+
18
+ log = Workarea::Orderbot::ImportLog.where(importer: "product").first
19
+ assert(log.started_at.present?)
20
+ assert(log.finished_at.present?)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Orderbot::SaveOrderTest < TestCase
5
+ def test_export_order
6
+ Workarea.config.orderbot_api_email_address = "test@workarea.com"
7
+ Workarea.config.orderbot_api_password = "foobar"
8
+
9
+ order = create_placed_order
10
+
11
+ Workarea::Orderbot::SaveOrder.new.perform(order.id)
12
+
13
+ order.reload
14
+
15
+ assert(order.orderbot_order_id.present?)
16
+ assert(order.orderbot_exported?)
17
+ end
18
+
19
+ def test_export_order_error
20
+ Workarea.config.orderbot_api_email_address = "test@workarea.com"
21
+ Workarea.config.orderbot_api_password = "foobar"
22
+
23
+ order = create_placed_order(id: "error")
24
+
25
+ assert_raise Workarea::Orderbot::SaveOrder::OrderbotSaveOrderError do
26
+ Workarea::Orderbot::SaveOrder.new.perform(order.id)
27
+ end
28
+ end
29
+
30
+ def test_export_fails_to_create
31
+ Workarea.config.orderbot_api_email_address = "test@workarea.com"
32
+ Workarea.config.orderbot_api_password = "foobar"
33
+
34
+ order = create_placed_order(id: "failure")
35
+
36
+ assert_raise Workarea::Orderbot::SaveOrder::OrderbotSaveOrderError do
37
+ Workarea::Orderbot::SaveOrder.new.perform(order.id)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ $:.push File.expand_path("lib", __dir__)
2
+
3
+ # Maintain your gem's version:
4
+ require "workarea/orderbot/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "workarea-orderbot"
9
+ spec.version = Workarea::Orderbot::VERSION
10
+ spec.authors = ["Jeff Yucis"]
11
+ spec.email = ["jyucis@workarea.com"]
12
+ spec.homepage = "https://github.com/workarea-commerce/workarea-orderbot"
13
+ spec.summary = "Workarea Integration with Orderbot OMS."
14
+ spec.description = "Ordebot OMS integration for catalog and order data."
15
+ spec.license = "Business Software License"
16
+
17
+ spec.files = `git ls-files`.split("\n")
18
+
19
+ spec.add_dependency 'workarea', '~> 3.5.x'
20
+ end