workarea-reviews 3.1.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.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.eslintignore +2 -0
- data/.eslintrc +24 -0
- data/.eslintrc.json +35 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/workflows/ci.yml +60 -0
- data/.gitignore +15 -0
- data/.rubocop.yml +3 -0
- data/.scss-lint.yml +188 -0
- data/.stylelintrc.json +8 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +745 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +8 -0
- data/LICENSE +52 -0
- data/README.md +107 -0
- data/Rakefile +53 -0
- data/app/assets/images/workarea/admin/icons/star.svg +1 -0
- data/app/assets/images/workarea/storefront/icons/empty_star.svg +1 -0
- data/app/assets/images/workarea/storefront/icons/half_star.svg +1 -0
- data/app/assets/images/workarea/storefront/icons/star.svg +1 -0
- data/app/assets/javascripts/workarea/storefront/reviews/modules/product_review_ajax_submit.js +39 -0
- data/app/assets/javascripts/workarea/storefront/reviews/modules/product_reviews_sort_menus.js +82 -0
- data/app/assets/javascripts/workarea/storefront/reviews/modules/rating_buttons.js +103 -0
- data/app/assets/javascripts/workarea/storefront/reviews/templates/sort_by_property.jst.ejs +11 -0
- data/app/assets/stylesheets/workarea/storefront/reviews/components/_rating.scss +28 -0
- data/app/assets/stylesheets/workarea/storefront/reviews/components/_reviews.scss +59 -0
- data/app/assets/stylesheets/workarea/storefront/reviews/components/_reviews_aggregate.scss +38 -0
- data/app/assets/stylesheets/workarea/storefront/reviews/components/_write_review.scss +63 -0
- data/app/controllers/workarea/admin/catalog_products_controller.decorator +9 -0
- data/app/controllers/workarea/admin/reports_controller.decorator +10 -0
- data/app/controllers/workarea/admin/reviews_controller.rb +51 -0
- data/app/controllers/workarea/storefront/review_requests_controller.rb +50 -0
- data/app/controllers/workarea/storefront/reviews_controller.rb +53 -0
- data/app/helpers/workarea/admin/reviews_helper.rb +13 -0
- data/app/helpers/workarea/storefront/reviews_helper.rb +22 -0
- data/app/helpers/workarea/storefront/reviews_schema_org_helper.rb +34 -0
- data/app/mailers/workarea/admin/status_report_mailer.decorator +8 -0
- data/app/mailers/workarea/storefront/review_mailer.rb +23 -0
- data/app/models/workarea/catalog/product.decorator +15 -0
- data/app/models/workarea/fulfillment.decorator +11 -0
- data/app/models/workarea/insights/most_active_reviewers.rb +34 -0
- data/app/models/workarea/insights/most_reviewed_products.rb +33 -0
- data/app/models/workarea/insights/top_rated_products.rb +33 -0
- data/app/models/workarea/review.rb +124 -0
- data/app/models/workarea/review/request.rb +62 -0
- data/app/models/workarea/search/admin/review.rb +72 -0
- data/app/models/workarea/search/storefront/product.decorator +9 -0
- data/app/models/workarea/sort.decorator +17 -0
- data/app/queries/workarea/reports/reviews_by_product.rb +86 -0
- data/app/queries/workarea/reports/reviews_by_user.rb +71 -0
- data/app/queries/workarea/review_request_params.rb +47 -0
- data/app/queries/workarea/review_summary.rb +11 -0
- data/app/queries/workarea/search/admin_reviews.rb +40 -0
- data/app/queries/workarea/search/category_browse.decorator +9 -0
- data/app/queries/workarea/search/product_search.decorator +9 -0
- data/app/seeds/workarea/review_seeds.rb +49 -0
- data/app/services/workarea/create_review.rb +99 -0
- data/app/view_models/workarea/admin/dashboards/reports_view_model.decorator +11 -0
- data/app/view_models/workarea/admin/product_view_model.decorator +7 -0
- data/app/view_models/workarea/admin/reports/reviews_by_product_view_model.rb +27 -0
- data/app/view_models/workarea/admin/review_view_model.rb +23 -0
- data/app/view_models/workarea/admin/reviews_search_view_model.rb +46 -0
- data/app/view_models/workarea/storefront/product_view_model.decorator +13 -0
- data/app/view_models/workarea/storefront/review_view_model.rb +14 -0
- data/app/views/workarea/admin/activities/_review_create.html.haml +12 -0
- data/app/views/workarea/admin/activities/_review_destroy.html.haml +10 -0
- data/app/views/workarea/admin/activities/_review_update.html.haml +10 -0
- data/app/views/workarea/admin/dashboards/_reviews_by_product_card.html.haml +17 -0
- data/app/views/workarea/admin/insights/_most_active_reviewers.html.haml +22 -0
- data/app/views/workarea/admin/insights/_most_reviewed_products.html.haml +22 -0
- data/app/views/workarea/admin/insights/_top_rated_products.html.haml +22 -0
- data/app/views/workarea/admin/reports/reviews_by_product.html.haml +44 -0
- data/app/views/workarea/admin/reviews/_aux_navigation.html.haml +5 -0
- data/app/views/workarea/admin/reviews/_catalog_products_aux_link.html.haml +5 -0
- data/app/views/workarea/admin/reviews/_dashboard_navigation.html.haml +1 -0
- data/app/views/workarea/admin/reviews/_menu.html.haml +3 -0
- data/app/views/workarea/admin/reviews/_summary.html.haml +12 -0
- data/app/views/workarea/admin/reviews/edit.html.haml +77 -0
- data/app/views/workarea/admin/reviews/index.html.haml +74 -0
- data/app/views/workarea/admin/status_report_mailer/_reviews.html.haml +5 -0
- data/app/views/workarea/storefront/products/_rating.html.haml +9 -0
- data/app/views/workarea/storefront/products/_reviews.html.haml +23 -0
- data/app/views/workarea/storefront/products/_reviews_aggregate.html.haml +22 -0
- data/app/views/workarea/storefront/products/_reviews_summary.html.haml +2 -0
- data/app/views/workarea/storefront/review_mailer/review_request.html.haml +24 -0
- data/app/views/workarea/storefront/review_requests/show.html.haml +45 -0
- data/app/views/workarea/storefront/reviews/new.html.haml +68 -0
- data/app/views/workarea/storefront/style_guides/_reviews_product_summary_docs.html.haml +13 -0
- data/app/views/workarea/storefront/style_guides/components/_reviews.html.haml +17 -0
- data/app/workers/workarea/create_review_requests.rb +33 -0
- data/app/workers/workarea/schedule_review_requests.rb +44 -0
- data/app/workers/workarea/send_review_requests.rb +12 -0
- data/app/workers/workarea/update_product_review_data.rb +26 -0
- data/bin/rails +18 -0
- data/config/initializers/append_points.rb +75 -0
- data/config/initializers/assets.rb +1 -0
- data/config/initializers/configuration.rb +31 -0
- data/config/initializers/rack_attack.rb +11 -0
- data/config/initializers/recaptcha.rb +19 -0
- data/config/initializers/scheduled_jobs.rb +8 -0
- data/config/locales/en.yml +150 -0
- data/config/routes.rb +25 -0
- data/lib/tasks/verify.rake +16 -0
- data/lib/workarea/mailer_previews/storefront/review_mailer_preview.rb +10 -0
- data/lib/workarea/reviews.rb +13 -0
- data/lib/workarea/reviews/engine.rb +16 -0
- data/lib/workarea/reviews/version.rb +5 -0
- data/package.json +9 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +25 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +55 -0
- data/test/dummy/config/environments/production.rb +86 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
- data/test/dummy/config/initializers/session_store.rb +5 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/factories/reviews.rb +32 -0
- data/test/fixtures/reviews.csv +5 -0
- data/test/helpers/workarea/storefront/reviews_helper_test.rb +20 -0
- data/test/integration/workarea/admin/reviews_integration_test.rb +37 -0
- data/test/integration/workarea/storefront/review_requests_integration_test.rb +63 -0
- data/test/integration/workarea/storefront/reviews_integration_test.rb +82 -0
- data/test/javascripts/fixtures/product_review_ajax_submit.html.haml +4 -0
- data/test/javascripts/product_review_ajax_submit_spec.js +28 -0
- data/test/javascripts/spec_helper.js +23 -0
- data/test/models/workarea/insights/most_active_reviewers_test.rb +32 -0
- data/test/models/workarea/insights/most_reviewed_products_test.rb +32 -0
- data/test/models/workarea/insights/top_rated_products_test.rb +49 -0
- data/test/models/workarea/review/request_test.rb +18 -0
- data/test/models/workarea/review_test.rb +105 -0
- data/test/models/workarea/search/storefront/product_test.decorator +14 -0
- data/test/queries/workarea/reports/reviews_by_product_test.rb +104 -0
- data/test/queries/workarea/reports/reviews_by_user_test.rb +102 -0
- data/test/queries/workarea/review_request_params_test.rb +64 -0
- data/test/services/workarea/create_review_test.rb +131 -0
- data/test/system/workarea/admin/review_system_test.rb +96 -0
- data/test/system/workarea/admin/reviews_by_product_system_test.rb +60 -0
- data/test/system/workarea/storefront/review_request_system_test.rb +34 -0
- data/test/system/workarea/storefront/review_system_test.rb +113 -0
- data/test/teaspoon_env.rb +10 -0
- data/test/test_helper.rb +11 -0
- data/test/workers/workarea/create_review_requests_test.rb +38 -0
- data/test/workers/workarea/schedule_review_requests_test.rb +115 -0
- data/test/workers/workarea/send_review_requests_test.rb +30 -0
- data/workarea-reviews.gemspec +22 -0
- data/yarn.lock +3265 -0
- metadata +265 -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,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: 958e498ef6e641de48be17da594796b171313957cee8c4bd9012fc4bfbd1bfeca489ee8dea5a893f60f77eb8505a0739589fb87c001259dab8e86e811fb58e3b
|
15
|
+
|
16
|
+
test:
|
17
|
+
secret_key_base: 96dce534407273cf8b9f9b7fb0a49a107350a08608622c80ee26a4f3debf9d30df5ab9276bd7460d53a60c6f25c50465ff7dd3b275a2d1983845b2dab752c60e
|
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"] %>
|
File without changes
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Factories
|
3
|
+
module Reviews
|
4
|
+
Factories.add(self)
|
5
|
+
|
6
|
+
def create_review(overrides = {})
|
7
|
+
attributes = {
|
8
|
+
title: 'Test Product',
|
9
|
+
body: 'This is great.',
|
10
|
+
product_id: "PROD#{rand(9_999_999)}",
|
11
|
+
user_id: BSON::ObjectId.new,
|
12
|
+
approved: true,
|
13
|
+
rating: 4,
|
14
|
+
user_info: 'BC from Philadelphia'
|
15
|
+
}.merge(overrides)
|
16
|
+
|
17
|
+
Workarea::Review.create!(attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_review_request(overrides = {})
|
21
|
+
attributes = {
|
22
|
+
product_id: "PROD#{rand(9_999_999)}",
|
23
|
+
order_id: SecureRandom.hex(5).upcase,
|
24
|
+
email: 'test@workarea.com',
|
25
|
+
send_after: Time.current
|
26
|
+
}.merge(overrides)
|
27
|
+
|
28
|
+
Workarea::Review::Request.create!(attributes)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
product_id,rating,user_info,body,title,approved
|
2
|
+
PROD1,3,"MD","Worked well for what I needed",,true
|
3
|
+
PROD2,4,"BC","Exactly what I was looking for.",,false
|
4
|
+
PROD2,5,"CH from Philadelphia","Greatest thing since avocados","OMG wow",false
|
5
|
+
PROD3,2,"DB","Was not impressed, could have been built better.","Disappointed",true
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class ReviewsHelperTest < ViewTest
|
6
|
+
def test_rating_stars_displays_correct_rating
|
7
|
+
assert_match(/1 out of 5 stars/, rating_stars(1))
|
8
|
+
assert_match(/1(?:\.0)? out of 5 stars/, rating_stars(1))
|
9
|
+
assert_match(/2\.5 out of 5 stars/, rating_stars(2.5))
|
10
|
+
assert_match(/4\.25 out of 5 stars/, rating_stars(4.251))
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_rating_stars_outputs_correct_number_of_stars
|
14
|
+
assert_equal(1, rating_stars(1).scan(/<title>star<\/title>/).size)
|
15
|
+
assert_equal(4, rating_stars(4.251).scan(/<title>star<\/title>/).size)
|
16
|
+
assert_equal(1, rating_stars(4.5).scan(/<title>half_star<\/title>/).size)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Admin
|
5
|
+
class ReviewsIntegrationTest < Workarea::IntegrationTest
|
6
|
+
include Admin::IntegrationTest
|
7
|
+
|
8
|
+
def test_updating_a_review
|
9
|
+
review = create_review(
|
10
|
+
product_id: product.id,
|
11
|
+
rating: 4,
|
12
|
+
approved: false
|
13
|
+
)
|
14
|
+
|
15
|
+
put admin.review_path(review), params: {
|
16
|
+
review: { body: 'foo bar', approved: true }
|
17
|
+
}
|
18
|
+
|
19
|
+
review.reload
|
20
|
+
assert_equal('foo bar', review.body)
|
21
|
+
assert(review.approved)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_deleting_a_review
|
25
|
+
review = create_review(product_id: product.id)
|
26
|
+
delete admin.review_path(review)
|
27
|
+
assert_empty(Review)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def product
|
33
|
+
@product ||= create_product
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class ReviewRequestsIntegrationTest < Workarea::IntegrationTest
|
6
|
+
def test_show
|
7
|
+
order = create_placed_order
|
8
|
+
|
9
|
+
review_request = create_review_request(
|
10
|
+
product_id: create_product.id,
|
11
|
+
order_id: order.id,
|
12
|
+
email: order.email
|
13
|
+
)
|
14
|
+
|
15
|
+
get storefront.review_request_path(review_request.token)
|
16
|
+
assert(response.ok?)
|
17
|
+
|
18
|
+
review_request.complete!
|
19
|
+
|
20
|
+
get storefront.review_request_path(review_request.token)
|
21
|
+
assert_redirected_to(storefront.root_path)
|
22
|
+
assert(flash[:error].present?)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_complete
|
26
|
+
order = create_placed_order
|
27
|
+
product = create_product
|
28
|
+
|
29
|
+
review_request = create_review_request(
|
30
|
+
product_id: product.id,
|
31
|
+
order_id: order.id,
|
32
|
+
email: order.email
|
33
|
+
)
|
34
|
+
|
35
|
+
other_requests = Array.new(2) do
|
36
|
+
create_review_request(
|
37
|
+
product_id: '123',
|
38
|
+
order_id: order.id,
|
39
|
+
email: order.email
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
post storefront.complete_review_request_path(review_request.token),
|
44
|
+
params: {
|
45
|
+
review: {
|
46
|
+
rating: 4,
|
47
|
+
body: 'Exactly what I was looking for.'
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
assert_redirected_to(storefront.product_path(product))
|
52
|
+
assert(flash[:success].present?)
|
53
|
+
|
54
|
+
review_request.reload
|
55
|
+
assert(review_request.completed?)
|
56
|
+
assert_equal(1, Review.count)
|
57
|
+
|
58
|
+
other_requests.each(&:reload)
|
59
|
+
assert(other_requests.all?(&:canceled?))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class ReviewsIntegrationTest < Workarea::IntegrationTest
|
6
|
+
def user
|
7
|
+
@user ||= create_user(
|
8
|
+
email: 'test@weblinc.com',
|
9
|
+
password: 'w3bl1nc',
|
10
|
+
first_name: 'Bob',
|
11
|
+
last_name: 'Clams',
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def product
|
16
|
+
@product ||= create_product
|
17
|
+
end
|
18
|
+
|
19
|
+
def login
|
20
|
+
post storefront.login_path,
|
21
|
+
params: {
|
22
|
+
email: user.email,
|
23
|
+
password: 'w3bl1nc'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_creating_a_review
|
28
|
+
login
|
29
|
+
|
30
|
+
post storefront.create_product_review_path(product),
|
31
|
+
params: {
|
32
|
+
review: {
|
33
|
+
product_id: product.id,
|
34
|
+
rating: 1,
|
35
|
+
title: 'Amazing product',
|
36
|
+
body: 'Totes buy this product!'
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
assert_redirected_to(storefront.product_path(product))
|
41
|
+
|
42
|
+
assert_equal(
|
43
|
+
I18n.t('workarea.storefront.reviews.flash_messages.created'),
|
44
|
+
flash[:success]
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_creating_a_review_not_signed_in
|
49
|
+
post storefront.create_product_review_path(product),
|
50
|
+
params: {
|
51
|
+
review: {
|
52
|
+
product_id: product.id,
|
53
|
+
rating: 1,
|
54
|
+
title: 'Amazing product',
|
55
|
+
body: 'Totes buy this product!',
|
56
|
+
first_name: 'Bob',
|
57
|
+
last_name: 'Clams'
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
assert_redirected_to(storefront.product_path(product))
|
62
|
+
|
63
|
+
assert_equal(
|
64
|
+
I18n.t('workarea.storefront.reviews.flash_messages.created'),
|
65
|
+
flash[:success]
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_create_failure
|
70
|
+
login
|
71
|
+
|
72
|
+
post storefront.create_product_review_path(product)
|
73
|
+
|
74
|
+
assert_equal(200, status)
|
75
|
+
assert_equal(
|
76
|
+
I18n.t('workarea.storefront.reviews.flash_messages.failure'),
|
77
|
+
flash[:error]
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
//= require workarea/core/config
|
2
|
+
//
|
3
|
+
(function () {
|
4
|
+
'use strict';
|
5
|
+
|
6
|
+
describe('WORKAREA.productReviewAjaxSubmit', function () {
|
7
|
+
describe('init', function () {
|
8
|
+
var formIsInDialog = function ($form) {
|
9
|
+
return ! _.isEmpty(WORKAREA.dialog.closest($form));
|
10
|
+
};
|
11
|
+
|
12
|
+
beforeEach(function () {
|
13
|
+
this.fixtures = fixture.load('product_review_ajax_submit.html');
|
14
|
+
|
15
|
+
WORKAREA.dialog.create($(this.fixtures));
|
16
|
+
WORKAREA.productReviewAjaxSubmit.init($(this.fixtures));
|
17
|
+
});
|
18
|
+
|
19
|
+
it('dialog remains if form invalid', function () {
|
20
|
+
expect($('form').valid()).to.equal(false);
|
21
|
+
|
22
|
+
$('form').trigger('submit');
|
23
|
+
|
24
|
+
expect(formIsInDialog($('form'))).to.equal(true);
|
25
|
+
});
|
26
|
+
});
|
27
|
+
});
|
28
|
+
}());
|
@@ -0,0 +1,23 @@
|
|
1
|
+
//= require workarea/core/spec_helper
|
2
|
+
//= require workarea/storefront/spec_helper
|
3
|
+
|
4
|
+
//= require featurejs_rails/feature
|
5
|
+
//= require webcomponentsjs-rails/MutationObserver
|
6
|
+
//= require i18n
|
7
|
+
//= require i18n/translations
|
8
|
+
//= require local_time
|
9
|
+
//= require lodash
|
10
|
+
//= require jquery3
|
11
|
+
//= require jquery-ui/core
|
12
|
+
//= require jquery-ui/widget
|
13
|
+
//= require jquery-ui/position
|
14
|
+
//= require jquery-ui/widgets/mouse
|
15
|
+
//= require jquery-ui/widgets/draggable
|
16
|
+
//= require jquery-ui/widgets/resizable
|
17
|
+
//= require jquery-ui/widgets/autocomplete
|
18
|
+
//= require jquery-ui/widgets/button
|
19
|
+
//= require jquery-ui/widgets/dialog
|
20
|
+
//= require jquery-ui/widgets/menu
|
21
|
+
//= require jquery.validate
|
22
|
+
//= require waypoints/noframework.waypoints
|
23
|
+
//= require waypoints/shortcuts/sticky
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Insights
|
5
|
+
class MostActiveReviewersTest < TestCase
|
6
|
+
setup :add_data, :time_travel
|
7
|
+
|
8
|
+
def add_data
|
9
|
+
travel_to Time.zone.local(2018, 10, 27)
|
10
|
+
|
11
|
+
5.times { create_review(email: 'foo@workarea.com', approved: true, verified: true) }
|
12
|
+
7.times { create_review(email: 'bar@workarea.com', approved: true) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def time_travel
|
16
|
+
travel_to Time.zone.local(2018, 11, 1)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_generate_monthly!
|
20
|
+
MostActiveReviewers.generate_monthly!
|
21
|
+
assert_equal(1, MostActiveReviewers.count)
|
22
|
+
|
23
|
+
reviewers = MostActiveReviewers.first
|
24
|
+
assert_equal(2, reviewers.results.size)
|
25
|
+
assert_equal('foo@workarea.com', reviewers.results.first['email'])
|
26
|
+
assert_in_delta(5, reviewers.results.first['reviews'])
|
27
|
+
assert_equal('bar@workarea.com', reviewers.results.second['email'])
|
28
|
+
assert_in_delta(7, reviewers.results.second['reviews'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Insights
|
5
|
+
class MostReviewedProductsTest < TestCase
|
6
|
+
setup :add_data, :time_travel
|
7
|
+
|
8
|
+
def add_data
|
9
|
+
travel_to Time.zone.local(2018, 10, 27)
|
10
|
+
|
11
|
+
6.times { create_review(product_id: 'foo', approved: true) }
|
12
|
+
12.times { create_review(product_id: 'bar', approved: true) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def time_travel
|
16
|
+
travel_to Time.zone.local(2018, 11, 1)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_generate_monthly!
|
20
|
+
MostReviewedProducts.generate_monthly!
|
21
|
+
assert_equal(1, MostReviewedProducts.count)
|
22
|
+
|
23
|
+
reviewed_products = MostReviewedProducts.first
|
24
|
+
assert_equal(2, reviewed_products.results.size)
|
25
|
+
assert_equal('bar', reviewed_products.results.first['product_id'])
|
26
|
+
assert_in_delta(12, reviewed_products.results.first['reviews'])
|
27
|
+
assert_equal('foo', reviewed_products.results.second['product_id'])
|
28
|
+
assert_in_delta(6, reviewed_products.results.second['reviews'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|