workarea-inventory_notifications 2.1.2

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 (92) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +15 -0
  3. data/.eslintrc +24 -0
  4. data/.gitignore +12 -0
  5. data/.jshintrc +31 -0
  6. data/.rubocop.yml +2 -0
  7. data/CHANGELOG.md +99 -0
  8. data/Gemfile +17 -0
  9. data/README.md +65 -0
  10. data/Rakefile +43 -0
  11. data/app/assets/stylesheets/workarea/storefront/inventory_notifications/components/_inventory_notifications.scss +14 -0
  12. data/app/controllers/workarea/storefront/inventory_notifications_controller.rb +30 -0
  13. data/app/mailers/workarea/storefront/inventory_update_mailer.rb +17 -0
  14. data/app/models/workarea/inventory/policies/allow_notify.rb +11 -0
  15. data/app/models/workarea/inventory_notification.rb +23 -0
  16. data/app/view_models/product_view_model.decorator +45 -0
  17. data/app/views/workarea/storefront/inventory_notifications/new.html.haml +19 -0
  18. data/app/views/workarea/storefront/inventory_update_mailer/notify.html.haml +32 -0
  19. data/app/views/workarea/storefront/inventory_update_mailer/notify.text.haml +14 -0
  20. data/app/views/workarea/storefront/products/_inventory_notifications.html.haml +8 -0
  21. data/app/workers/workarea/restock_notifier.rb +27 -0
  22. data/bin/rails +18 -0
  23. data/config/initializers/appends.rb +11 -0
  24. data/config/initializers/inventory_policies.rb +3 -0
  25. data/config/locales/en.yml +22 -0
  26. data/config/routes.rb +10 -0
  27. data/lib/workarea/inventory_notifications/engine.rb +8 -0
  28. data/lib/workarea/inventory_notifications/version.rb +5 -0
  29. data/lib/workarea/inventory_notifications.rb +11 -0
  30. data/lib/workarea/mailer_previews/inventory_update_mailer_preview.rb +12 -0
  31. data/script/admin_ci +9 -0
  32. data/script/ci +11 -0
  33. data/script/core_ci +9 -0
  34. data/script/plugins_ci +9 -0
  35. data/script/storefront_ci +9 -0
  36. data/test/dummy/Rakefile +6 -0
  37. data/test/dummy/app/assets/config/manifest.js +4 -0
  38. data/test/dummy/app/assets/images/.keep +0 -0
  39. data/test/dummy/app/assets/javascripts/application.js +13 -0
  40. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  41. data/test/dummy/app/controllers/application_controller.rb +3 -0
  42. data/test/dummy/app/controllers/concerns/.keep +0 -0
  43. data/test/dummy/app/helpers/application_helper.rb +2 -0
  44. data/test/dummy/app/jobs/application_job.rb +2 -0
  45. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  46. data/test/dummy/app/models/concerns/.keep +0 -0
  47. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  48. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  49. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  50. data/test/dummy/bin/bundle +3 -0
  51. data/test/dummy/bin/rails +4 -0
  52. data/test/dummy/bin/rake +4 -0
  53. data/test/dummy/bin/setup +34 -0
  54. data/test/dummy/bin/update +29 -0
  55. data/test/dummy/config/application.rb +24 -0
  56. data/test/dummy/config/boot.rb +5 -0
  57. data/test/dummy/config/cable.yml +9 -0
  58. data/test/dummy/config/environment.rb +5 -0
  59. data/test/dummy/config/environments/development.rb +54 -0
  60. data/test/dummy/config/environments/production.rb +83 -0
  61. data/test/dummy/config/environments/test.rb +43 -0
  62. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  63. data/test/dummy/config/initializers/assets.rb +11 -0
  64. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  65. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  66. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  67. data/test/dummy/config/initializers/inflections.rb +16 -0
  68. data/test/dummy/config/initializers/mime_types.rb +4 -0
  69. data/test/dummy/config/initializers/session_store.rb +3 -0
  70. data/test/dummy/config/initializers/workarea.rb +5 -0
  71. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  72. data/test/dummy/config/locales/en.yml +23 -0
  73. data/test/dummy/config/puma.rb +47 -0
  74. data/test/dummy/config/routes.rb +5 -0
  75. data/test/dummy/config/secrets.yml +22 -0
  76. data/test/dummy/config.ru +5 -0
  77. data/test/dummy/lib/assets/.keep +0 -0
  78. data/test/dummy/log/.keep +0 -0
  79. data/test/dummy/public/404.html +67 -0
  80. data/test/dummy/public/422.html +67 -0
  81. data/test/dummy/public/500.html +66 -0
  82. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  83. data/test/dummy/public/apple-touch-icon.png +0 -0
  84. data/test/dummy/public/favicon.ico +1 -0
  85. data/test/mailers/workarea/storefront/inventory_update_mailer_test.rb +55 -0
  86. data/test/models/workarea/inventory_notification_test.rb +16 -0
  87. data/test/system/workarea/storefront/inventory_notifications_system_test.rb +89 -0
  88. data/test/test_helper.rb +10 -0
  89. data/test/view_models/workarea/storefront/product_view_model_test.decorator +28 -0
  90. data/test/workers/workarea/restock_notifier_test.rb +32 -0
  91. data/workarea-inventory_notifications.gemspec +18 -0
  92. metadata +153 -0
@@ -0,0 +1,47 @@
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 }.to_i
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. If you use this option
30
+ # you need to make sure to reconnect any threads in the `on_worker_boot`
31
+ # block.
32
+ #
33
+ # preload_app!
34
+
35
+ # The code in the `on_worker_boot` will be called if you are using
36
+ # clustered mode by specifying a number of `workers`. After each worker
37
+ # process is booted this block will be run, if you are using `preload_app!`
38
+ # option you will want to use this block to reconnect to any threads
39
+ # or connections that may have been created at application boot, Ruby
40
+ # cannot share connections between processes.
41
+ #
42
+ # on_worker_boot do
43
+ # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
44
+ # end
45
+
46
+ # Allow puma to be restarted by `rails restart` command.
47
+ 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,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rails secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: ba01157105f878f56d7d609e6825f2889ed87b864b3b29a4e636206b8493cc21bae0403054aa1cfc8172a4ea97c08dd09b4490b3e17c1dbc7be1ee9d480b4834
15
+
16
+ test:
17
+ secret_key_base: 55c4b1f3ed4228c94d7a5217a3a548abe6e40f7d72467c5e33375fd58cec9cc47d95c26f3903a6ffc086a484536495de31edb360543ea8d640cf050378edd16e
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Storefront::InventoryUpdateMailerIntegrationTest < TestCase
5
+ setup :save_mail_config
6
+ setup :product
7
+ setup :create_notification
8
+ teardown :restore_mail_config
9
+
10
+ def create_notification
11
+ Workarea.config.send_email = true
12
+ values = attrs.values_at('product_id', 'sku', 'email')
13
+ Storefront::InventoryUpdateMailer.notify(*values).deliver_later
14
+ end
15
+
16
+ def attrs
17
+ @attrs ||= {
18
+ 'product_id' => 'AB1',
19
+ 'sku' => 'SKU1',
20
+ 'email' => 'test@workarea.com'
21
+ }
22
+ end
23
+
24
+ def product
25
+ @product ||= create_product(id: 'AB1', name: 'Integration', variants: [
26
+ { sku: 'SKU1', name: 'name', details: { 'foo' => 'bar' } }
27
+ ])
28
+ end
29
+
30
+ def email
31
+ @email ||= ActionMailer::Base.deliveries.last
32
+ end
33
+
34
+ def html_body
35
+ @html_body ||= email.parts.second.body.to_s
36
+ end
37
+
38
+ def save_mail_config
39
+ @config = Workarea.config.send_email
40
+ end
41
+
42
+ def restore_mail_config
43
+ Workarea.config.send_email = @config
44
+ end
45
+
46
+ def test_notify_sends_to_proper_location
47
+ assert_match(attrs['email'], email.to.first)
48
+ end
49
+
50
+ def test_notify_displays_product_and_sku_names
51
+ assert_match(product.name, html_body)
52
+ assert_match(product.variants.first.name, html_body)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class InventoryNotificationTest < TestCase
5
+ def test_mark_as_sent_should_set_the_sent_at_timestamp
6
+ notificaiton = InventoryNotification.create!(
7
+ product_id: 'AB1',
8
+ sku: 'A01',
9
+ email: 'test@workarea.com'
10
+ )
11
+
12
+ notificaiton.mark_as_sent!
13
+ assert(notificaiton.sent_at)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,89 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class InventoryNotificationsSystemTest < Workarea::SystemTest
6
+ include Storefront::SystemTest
7
+
8
+ setup :set_products
9
+ setup :set_inventory
10
+
11
+ def set_products
12
+ @product = create_product(
13
+ name: 'Integration Product',
14
+ variants: [
15
+ { sku: 'SKU1', regular: 10.to_m },
16
+ { sku: 'SKU2', regular: 15.to_m }
17
+ ]
18
+ )
19
+
20
+ @option_product = create_product(
21
+ name: 'Option Selects Product',
22
+ template: 'option_selects',
23
+ variants: [
24
+ { sku: 'SKU3', details: { color: 'Red', size: 'Large', material: 'Cotton' } },
25
+ { sku: 'SKU4', details: { color: 'Red', size: 'Small', material: 'Cotton' } },
26
+ { sku: 'SKU5', details: { color: 'Blue', size: 'Small', material: 'Suede' } }
27
+ ]
28
+ )
29
+ end
30
+
31
+ def set_inventory
32
+ create_inventory(id: 'SKU1', available: 0, policy: 'allow_notify')
33
+ create_inventory(id: 'SKU2', available: 5, policy: 'standard')
34
+ create_inventory(id: 'SKU3', available: 0, policy: 'allow_notify')
35
+ create_inventory(id: 'SKU4', available: 5, policy: 'standard')
36
+ create_inventory(id: 'SKU5', available: 5, policy: 'standard')
37
+ end
38
+
39
+ def test_visiting_an_option_product_with_allow_notify
40
+ visit storefront.product_path(@option_product)
41
+
42
+ select 'Red', from: 'color'
43
+ select 'Small', from: 'size'
44
+ select 'Cotton', from: 'material'
45
+
46
+ assert(page.has_no_content?(t('workarea.storefront.products.sign_up_for_email_notification')))
47
+
48
+ select 'Large', from: 'size'
49
+ assert(page.has_content?(t('workarea.storefront.products.sign_up_for_email_notification')))
50
+
51
+ click_link t('workarea.storefront.products.sign_up_for_email_notification')
52
+
53
+ within '#inventory_notification_form' do
54
+ select 'SKU3', from: 'notification_sku'
55
+ fill_in 'notification_email', with: 'test@workarea.com'
56
+
57
+ click_button t('workarea.storefront.inventory_notifications.notify_me')
58
+ end
59
+
60
+ assert(page.has_content?(t('workarea.storefront.inventory_notifications.flash_messages.saved')))
61
+ assert(current_path, storefront.product_path(@product))
62
+ end
63
+
64
+ def test_visiting_a_product_with_allow_notify
65
+ visit storefront.product_path(@product)
66
+
67
+ assert(page.has_no_content?(t('workarea.storefront.products.inventory_notification_prompt')))
68
+
69
+ select @product.skus.second, from: 'sku'
70
+ assert(page.has_no_content?(t('workarea.storefront.products.inventory_notification_prompt')))
71
+
72
+ select @product.skus.first, from: 'sku'
73
+ assert(page.has_content?(t('workarea.storefront.products.inventory_notification_prompt')))
74
+
75
+ click_link t('workarea.storefront.products.sign_up_for_email_notification')
76
+
77
+ within '#inventory_notification_form' do
78
+ select 'SKU1', from: 'notification_sku'
79
+ fill_in 'notification_email', with: 'test@workarea.com'
80
+
81
+ click_button t('workarea.storefront.inventory_notifications.notify_me')
82
+ end
83
+
84
+ assert(page.has_content?(t('workarea.storefront.inventory_notifications.flash_messages.saved')))
85
+ assert(current_path, storefront.product_path(@product))
86
+ end
87
+ end
88
+ end
89
+ 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,28 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ decorate Storefront::ProductViewModelTest, with: :inventory_notifications do
5
+ def test_unavailable_sku_options_returns_options_of_sold_out_variants
6
+ @product.variants.build(sku: 'SKU1', name: 'name', details: { 'foo' => 'bar' })
7
+ @product.variants.build(sku: 'SKU2', name: 'name', details: { 'foo' => 'bar' })
8
+ @product.save
9
+ create_inventory(id: 'SKU1', available: 0, policy: 'allow_notify')
10
+ create_inventory(id: 'SKU2', available: 100, policy: 'allow_notify')
11
+
12
+ view_model = Storefront::ProductViewModel.new(@product, sku: 'SKU1')
13
+ assert(view_model.unavailable_sku_options.size == 1)
14
+ assert(view_model.unavailable_sku_options.first, ['SKU1 - Foo: bar', 'SKU1'])
15
+ end
16
+
17
+ def test_current_sku_unavailable_returns_true_if_current_sku_is_sold_out
18
+ @product.variants.build(sku: 'SKU', name: 'name', details: { 'foo' => 'bar' })
19
+ @product.variants.build(sku: 'SKU2', name: 'name', details: { 'foo' => 'bar' })
20
+ @product.save
21
+ create_inventory(id: 'SKU', available: 0, policy: 'allow_notify')
22
+ create_inventory(id: 'SKU2', available: 100, policy: 'allow_notify')
23
+
24
+ view_model = Storefront::ProductViewModel.new(@product, sku: 'SKU')
25
+ assert(view_model.current_sku_unavailable?)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class RestockNotifierTest < TestCase
5
+ setup :save_mail_config
6
+ teardown :restore_mail_config
7
+
8
+ def test_perform_sends_notification_details_to_mailer_and_sets_sent_at
9
+ Workarea.config.send_email = true
10
+ product = create_product(variants: [{ sku: 'SKU1', regular: 5.00 }])
11
+ create_inventory(id: 'SKU1', available: 1, policy: 'allow_notify')
12
+
13
+ notification = InventoryNotification.create!(
14
+ 'product_id' => product.id,
15
+ 'sku' => product.variants.first.sku,
16
+ 'email' => 'test@workarea.com'
17
+ )
18
+
19
+ RestockNotifier.new.perform('SKU1')
20
+
21
+ assert(notification.reload.sent_at)
22
+ end
23
+
24
+ def save_mail_config
25
+ @config = Workarea.config.send_email
26
+ end
27
+
28
+ def restore_mail_config
29
+ Workarea.config.send_email = @config
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ require 'workarea/inventory_notifications/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'workarea-inventory_notifications'
7
+ s.version = Workarea::InventoryNotifications::VERSION
8
+ s.authors = ['Eric Pigeon']
9
+ s.email = ['epigeon@weblinc.com']
10
+ s.homepage = 'http://www.workarea.com'
11
+ s.summary = 'Inventory Notifications plugin for the Workarea ecommerce platform'
12
+ s.description = 'Plugin for product inventory notifications on the Workarea ecommerce platform.'
13
+ s.files = `git ls-files`.split("\n")
14
+
15
+ s.required_ruby_version = '>= 2.3.0'
16
+
17
+ s.add_dependency 'workarea', '~> 3.x', '>= 3.3.0'
18
+ end