workarea-reviews 3.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.eslintignore +2 -0
- data/.eslintrc +24 -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/.gitignore +16 -0
- data/.scss-lint.yml +188 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +763 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +6 -0
- data/LICENSE +52 -0
- data/README.md +107 -0
- data/Rakefile +54 -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/import_reviews_controller.rb +35 -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 +12 -0
- data/app/helpers/workarea/storefront/reviews_helper.rb +24 -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/review.rb +135 -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/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/review_seeds.rb +49 -0
- data/app/services/workarea/create_review.rb +99 -0
- data/app/view_models/workarea/admin/product_view_model.decorator +7 -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/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 +10 -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 +22 -0
- data/app/views/workarea/storefront/review_requests/show.html.haml +44 -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 +70 -0
- data/config/initializers/assets.rb +1 -0
- data/config/initializers/configuration.rb +29 -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 +104 -0
- data/config/routes.rb +21 -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 +12 -0
- data/lib/workarea/reviews/version.rb +5 -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 +3 -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/admin/reviews_helper_test.rb +17 -0
- data/test/helpers/workarea/storefront/reviews_helper_test.rb +19 -0
- data/test/integration/workarea/admin/reviews_integration_test.rb +33 -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/review/request_test.rb +18 -0
- data/test/models/workarea/review_test.rb +94 -0
- data/test/models/workarea/search/storefront/product_test.decorator +14 -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/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
- metadata +241 -0
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,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Admin
|
5
|
+
class ReviewsHelperTest < ViewTest
|
6
|
+
def test_reviewer_info_only_shows_link_when_user_is_present
|
7
|
+
review = create_review(
|
8
|
+
user_id: nil,
|
9
|
+
product_id: create_product.id,
|
10
|
+
user_info: 'Userless User'
|
11
|
+
)
|
12
|
+
|
13
|
+
assert_equal('Userless User', reviewer_info(review))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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(?:\.0)? out of 5 stars/, rating_stars(1))
|
8
|
+
assert_match(/2\.5 out of 5 stars/, rating_stars(2.5))
|
9
|
+
assert_match(/4\.25 out of 5 stars/, rating_stars(4.251))
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_rating_stars_outputs_correct_number_of_stars
|
13
|
+
assert_equal(1, rating_stars(1).scan(/<title>star<\/title>/).size)
|
14
|
+
assert_equal(4, rating_stars(4.251).scan(/<title>star<\/title>/).size)
|
15
|
+
assert_equal(1, rating_stars(4.5).scan(/<title>half_star<\/title>/).size)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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(product_id: product.id)
|
10
|
+
|
11
|
+
put admin.review_path(review), params: {
|
12
|
+
review: { body: 'foo bar', approved: true }
|
13
|
+
}
|
14
|
+
|
15
|
+
review.reload
|
16
|
+
assert_equal('foo bar', review.body)
|
17
|
+
assert(review.approved)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_deleting_a_review
|
21
|
+
review = create_review(product_id: product.id)
|
22
|
+
delete admin.review_path(review)
|
23
|
+
assert_empty(Review)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def product
|
29
|
+
@product ||= create_product
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
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,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class Review
|
5
|
+
class RequestTest < TestCase
|
6
|
+
def test_cancel_for_orders!
|
7
|
+
requests = Array.new(3) { create_review_request }
|
8
|
+
|
9
|
+
request = requests.first
|
10
|
+
Review::Request.cancel_for_orders!(request.order_id)
|
11
|
+
assert(request.reload.canceled?)
|
12
|
+
|
13
|
+
Review::Request.cancel_for_orders!(requests.map(&:order_id))
|
14
|
+
assert(requests.each(&:reload).all?(&:canceled?))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class ReviewTest < Workarea::TestCase
|
5
|
+
def test_find_for_product_returns_approved_reviews
|
6
|
+
assert([approved], Review.find_for_product(product_id))
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_find_for_product_returns_unapproved_when_arg_is_true
|
10
|
+
assert([unapproved, approved], Review.find_for_product(product_id, true))
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_find_aggregates_returns_a_hash_data_with_one_product_id
|
14
|
+
approved
|
15
|
+
assert_equal(
|
16
|
+
{ count: 1, average: 4 },
|
17
|
+
Review.find_aggregates(product_id)
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_find_aggregates_returns_a_hash_with_multiple_product_ids
|
22
|
+
approved
|
23
|
+
product_id_2 = 'PROD2'
|
24
|
+
create_review(product_id: product_id_2, rating: 3, approved: true)
|
25
|
+
|
26
|
+
assert_equal(
|
27
|
+
{
|
28
|
+
product_id => { count: 1, average: 4 },
|
29
|
+
product_id_2 => { count: 1, average: 3 }
|
30
|
+
},
|
31
|
+
Review.find_aggregates(product_id, product_id_2)
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_find_single_aggregates_returns_a_hash_with_zeros_if_no_data
|
36
|
+
assert_equal(
|
37
|
+
{ count: 0, average: 0 },
|
38
|
+
Review.find_single_aggregates('does-not-compute')
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_find_single_aggregates_returns_a_review_data
|
43
|
+
create_review(product_id: product_id, rating: 1)
|
44
|
+
create_review(product_id: product_id, rating: 2)
|
45
|
+
create_review(product_id: product_id, rating: 3)
|
46
|
+
create_review(product_id: product_id, rating: 4)
|
47
|
+
create_review(product_id: product_id, rating: 5, approved: false)
|
48
|
+
|
49
|
+
assert_equal(
|
50
|
+
{ count: 4, average: 2.5 },
|
51
|
+
Review.find_single_aggregates(product_id)
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_ensure_title
|
56
|
+
review = Review.new(
|
57
|
+
product_id: '123',
|
58
|
+
user_info: 'MD',
|
59
|
+
rating: 3,
|
60
|
+
body: %(
|
61
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
62
|
+
Nam in ex viverra, pretium tellus quis, bibendum nisi.
|
63
|
+
Praesent luctus viverra.
|
64
|
+
).strip
|
65
|
+
)
|
66
|
+
|
67
|
+
review.save!
|
68
|
+
assert(review.title.present?)
|
69
|
+
assert_equal(review.body.truncate(50), review.title)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def product_id
|
75
|
+
'PROD1'
|
76
|
+
end
|
77
|
+
|
78
|
+
def approved
|
79
|
+
@approved ||= create_review(
|
80
|
+
product_id: product_id,
|
81
|
+
rating: 4,
|
82
|
+
approved: true
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def unapproved
|
87
|
+
@unapproved ||= create_review(
|
88
|
+
product_id: product_id,
|
89
|
+
rating: 4,
|
90
|
+
approved: false
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|