workarea-ship_station 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 (95) 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 +54 -0
  6. data/.gitignore +19 -0
  7. data/.rubocop.yml +3 -0
  8. data/CHANGELOG.md +13 -0
  9. data/Gemfile +17 -0
  10. data/LICENSE +52 -0
  11. data/README.md +89 -0
  12. data/Rakefile +57 -0
  13. data/app/assets/images/workarea/admin/ship_station/.keep +0 -0
  14. data/app/assets/images/workarea/storefront/ship_station/.keep +0 -0
  15. data/app/assets/javascripts/workarea/admin/ship_station/.keep +0 -0
  16. data/app/assets/javascripts/workarea/storefront/ship_station/.keep +0 -0
  17. data/app/assets/stylesheets/workarea/admin/ship_station/.keep +0 -0
  18. data/app/assets/stylesheets/workarea/storefront/ship_station/.keep +0 -0
  19. data/app/controllers/workarea/admin/orders_controller.decorator +50 -0
  20. data/app/controllers/workarea/storefront/ship_station_webhook_controller.rb +52 -0
  21. data/app/helpers/.keep +0 -0
  22. data/app/mailers/.keep +0 -0
  23. data/app/models/.keep +0 -0
  24. data/app/models/workarea/order.decorator +25 -0
  25. data/app/services/workarea/ship_station/order.rb +161 -0
  26. data/app/services/workarea/ship_station/webhook.rb +27 -0
  27. data/app/services/workarea/ship_station/webhook/item_ship_notify.rb +33 -0
  28. data/app/views/.keep +0 -0
  29. data/app/views/workarea/admin/orders/_ship_station.html.haml +12 -0
  30. data/app/views/workarea/admin/orders/_ship_station_bar_actions.html.haml +7 -0
  31. data/app/views/workarea/admin/orders/hold_date.html.haml +27 -0
  32. data/app/workers/workarea/ship_station/save_order.rb +24 -0
  33. data/bin/rails +25 -0
  34. data/config/initializers/appends.rb +9 -0
  35. data/config/initializers/workarea.rb +11 -0
  36. data/config/locales/en.yml +20 -0
  37. data/config/routes.rb +13 -0
  38. data/lib/workarea/ship_station.rb +39 -0
  39. data/lib/workarea/ship_station/bogus_gateway.rb +297 -0
  40. data/lib/workarea/ship_station/engine.rb +10 -0
  41. data/lib/workarea/ship_station/gateway.rb +92 -0
  42. data/lib/workarea/ship_station/response.rb +17 -0
  43. data/lib/workarea/ship_station/version.rb +5 -0
  44. data/test/dummy/Rakefile +6 -0
  45. data/test/dummy/app/assets/config/manifest.js +3 -0
  46. data/test/dummy/app/assets/images/.keep +0 -0
  47. data/test/dummy/app/assets/javascripts/application.js +14 -0
  48. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  49. data/test/dummy/app/controllers/application_controller.rb +2 -0
  50. data/test/dummy/app/controllers/concerns/.keep +0 -0
  51. data/test/dummy/app/helpers/application_helper.rb +2 -0
  52. data/test/dummy/app/jobs/application_job.rb +2 -0
  53. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  54. data/test/dummy/app/models/concerns/.keep +0 -0
  55. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  56. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  57. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  58. data/test/dummy/bin/bundle +3 -0
  59. data/test/dummy/bin/rails +4 -0
  60. data/test/dummy/bin/rake +4 -0
  61. data/test/dummy/bin/setup +25 -0
  62. data/test/dummy/bin/update +25 -0
  63. data/test/dummy/config.ru +5 -0
  64. data/test/dummy/config/application.rb +34 -0
  65. data/test/dummy/config/boot.rb +5 -0
  66. data/test/dummy/config/environment.rb +5 -0
  67. data/test/dummy/config/environments/development.rb +52 -0
  68. data/test/dummy/config/environments/production.rb +83 -0
  69. data/test/dummy/config/environments/test.rb +45 -0
  70. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  71. data/test/dummy/config/initializers/assets.rb +12 -0
  72. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  73. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  74. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  75. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  76. data/test/dummy/config/initializers/inflections.rb +16 -0
  77. data/test/dummy/config/initializers/mime_types.rb +4 -0
  78. data/test/dummy/config/initializers/workarea.rb +5 -0
  79. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  80. data/test/dummy/config/locales/en.yml +33 -0
  81. data/test/dummy/config/puma.rb +34 -0
  82. data/test/dummy/config/routes.rb +5 -0
  83. data/test/dummy/config/spring.rb +6 -0
  84. data/test/dummy/db/seeds.rb +2 -0
  85. data/test/dummy/lib/assets/.keep +0 -0
  86. data/test/dummy/log/.keep +0 -0
  87. data/test/integration/workarea/admin/ship_station_integration_test.rb +36 -0
  88. data/test/integration/workarea/storefront/ship_station_webhook_test.rb +37 -0
  89. data/test/integration/workarea/storefront/ship_station_webhooks/notify_shipment_test.rb +56 -0
  90. data/test/services/workarea/ship_station/order_test.rb +67 -0
  91. data/test/teaspoon_env.rb +6 -0
  92. data/test/test_helper.rb +10 -0
  93. data/test/workers/workarea/ship_station/save_order_test.rb +16 -0
  94. data/workarea-ship_station.gemspec +20 -0
  95. metadata +157 -0
@@ -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 Ship Station'
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,36 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Admin
5
+ class ShipStationIntegrationTest < Workarea::IntegrationTest
6
+ include Admin::IntegrationTest
7
+
8
+ def test_setting_order_on_hold
9
+ order = create_placed_order
10
+
11
+ hold_date = 10.days.from_now
12
+ patch admin.save_hold_date_order_path(order),
13
+ params: {
14
+ hold_until: hold_date
15
+ }
16
+
17
+ order.reload
18
+
19
+ assert(order.ship_station_on_hold?)
20
+ assert(order.ship_station_on_hold_until.present?)
21
+ end
22
+
23
+ def test_clearing_order_hold
24
+ order = create_placed_order(ship_station_on_hold_until: 1.day.from_now)
25
+
26
+ assert(order.ship_station_on_hold?)
27
+
28
+ patch admin.clear_hold_date_order_path(order)
29
+ order.reload
30
+
31
+ refute(order.ship_station_on_hold?)
32
+ refute(order.ship_station_on_hold_until.present?)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class ShipStationWebhookTest < Workarea::IntegrationTest
6
+ def test_resource_url
7
+ post storefront.ship_station_webhook_path, params: invalid_payload, as: :json
8
+ refute(response.ok?)
9
+ assert_equal(400, response.status)
10
+ end
11
+
12
+ def test_no_processor
13
+ post storefront.ship_station_webhook_path, params: no_processor_payload, as: :json
14
+
15
+ refute(response.ok?)
16
+ assert(response.body.include? "no class defined to handle FOO_BAR_BAZ")
17
+ assert_equal(404, response.status)
18
+ end
19
+
20
+ private
21
+
22
+ def invalid_payload
23
+ {
24
+ "resource_url": "https://ssapiX.example.com",
25
+ "resource_type": "ITEM_SHIP_NOTIFY"
26
+ }
27
+ end
28
+
29
+ def no_processor_payload
30
+ {
31
+ "resource_url": "https://ssapiX.shipstation.com",
32
+ "resource_type": "FOO_BAR_BAZ"
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ module ShipStationWebhooks
6
+ class NotifyShipmentTest < Workarea::IntegrationTest
7
+ def test_notify_shipment
8
+ order = create_placed_order
9
+ fulfillment = create_fulfillment_from_order(order)
10
+
11
+ Workarea::ShipStation::Response.any_instance.stubs(:body).returns(order_response(order))
12
+
13
+ post storefront.ship_station_webhook_path, params: notify_shipment_payload, as: :json
14
+
15
+ assert(response.ok?)
16
+
17
+ assert_equal({ "status" => 200 }, JSON.parse(response.body))
18
+ assert_equal(200, response.status)
19
+
20
+ fulfillment.reload
21
+ assert_equal(:shipped, fulfillment.status)
22
+ end
23
+
24
+ private
25
+
26
+ def notify_shipment_payload
27
+ {
28
+ "resource_url": "https://ssapiX.shipstation.com/shipments?storeID=123456&batchId=12345678&includeShipmentItems=True",
29
+ "resource_type": "ITEM_SHIP_NOTIFY"
30
+ }
31
+ end
32
+
33
+ def order_response(order)
34
+ items = order.items.map do |order_item|
35
+ {
36
+ "lineItemKey" => order_item.id.to_s,
37
+ "quantity" => order_item.quantity
38
+ }
39
+ end
40
+
41
+ {
42
+ "page" => 1,
43
+ "pages" => 0,
44
+ "shipments" => [
45
+ {
46
+ "orderKey" => order.id.to_s,
47
+ "shipmentItems" => items,
48
+ "trackingNumber" => "9400111699000508143346"
49
+ }
50
+ ]
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,67 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module ShipStation
5
+ class OrderTest < Workarea::TestCase
6
+ def test_to_h
7
+ create_order_total_discount(order_total: 1.to_m)
8
+ shipping_sku = create_shipping_sku(id: 'SKU', weight: 1, dimensions: [2, 3, 4])
9
+ order = create_placed_order
10
+ order_details = Order.new(order.id).to_h
11
+
12
+ order_vm = Workarea::Storefront::OrderViewModel.new(order)
13
+
14
+ assert_equal(order.id, order_details[:orderNumber])
15
+ assert_equal(order.id, order_details[:orderKey])
16
+ assert_equal('awaiting_shipment', order_details[:orderStatus])
17
+ assert_equal(order.email, order_details[:customerUsername])
18
+ assert_equal(order.email, order_details[:customerEmail])
19
+ refute(order_details[:shipByDate].present?)
20
+
21
+ wa_billing_address = order_vm.billing_address
22
+ ship_station_billing_address = order_details[:billTo]
23
+
24
+ assert_equal("Ben Crouse", ship_station_billing_address[:name])
25
+ assert_equal(wa_billing_address.street, ship_station_billing_address[:street1])
26
+ assert_equal(wa_billing_address.street_2, ship_station_billing_address[:street2])
27
+ assert_equal(wa_billing_address.city, ship_station_billing_address[:city])
28
+ assert_equal(wa_billing_address.postal_code, ship_station_billing_address[:postalCode])
29
+ assert_equal(wa_billing_address.region, ship_station_billing_address[:state])
30
+ assert_equal("US", ship_station_billing_address[:country])
31
+
32
+ wa_shipping_address = order_vm.shipping_address
33
+ ship_station_shipping_address = order_details[:shipTo]
34
+
35
+ assert_equal("Ben Crouse", ship_station_shipping_address[:name])
36
+ assert_equal(wa_shipping_address.street, ship_station_shipping_address[:street1])
37
+ assert_equal(wa_shipping_address.street_2, ship_station_shipping_address[:street2])
38
+ assert_equal(wa_shipping_address.city, ship_station_shipping_address[:city])
39
+ assert_equal(wa_shipping_address.postal_code, ship_station_shipping_address[:postalCode])
40
+ assert_equal(wa_shipping_address.region, ship_station_shipping_address[:state])
41
+ assert_equal("US", ship_station_shipping_address[:country])
42
+
43
+ merch_item = order_details[:items].detect { |item| !item[:adjustment] }
44
+
45
+ assert_equal(2, order_details[:items].size)
46
+ assert_equal("SKU", merch_item[:sku])
47
+ assert_equal("Test Product", merch_item[:name])
48
+ assert_equal(2, merch_item[:quantity])
49
+ assert_equal(5.0, merch_item[:unitPrice])
50
+ assert_equal(1.0, merch_item[:weight][:value])
51
+ assert_equal("ounces", merch_item[:weight][:units])
52
+
53
+ discount_item = order_details[:items].detect { |item| item[:adjustment] }
54
+ assert_equal("DISCOUNT CODE", discount_item[:sku])
55
+ assert_equal("Order Total Discount", discount_item[:name])
56
+ assert_equal(1, discount_item[:quantity])
57
+ assert_equal(-1, discount_item[:unitPrice])
58
+
59
+ Workarea.with_config do |config|
60
+ config.ship_station.ship_by_date_lead_days = 5
61
+ order_details = Order.new(order.id).to_h
62
+ assert(order_details[:shipByDate] > Time.current)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,6 @@
1
+ require 'workarea/testing/teaspoon'
2
+
3
+ Teaspoon.configure do |config|
4
+ config.root = Workarea::ShipStation::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,16 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class ShipStation::SaveOrderTest < TestCase
5
+ def test_order_ship_station_exported
6
+ order = create_placed_order
7
+
8
+ Workarea::ShipStation::SaveOrder.new.perform(order.id)
9
+
10
+ order.reload
11
+
12
+ assert(order.ship_station_exported?)
13
+ assert(order.ship_station_order_id.present?)
14
+ end
15
+ end
16
+ end