workarea-storefront 3.4.45 → 3.5.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +52 -0
- data/app/assets/javascripts/workarea/storefront/application.js.erb +2 -12
- data/app/assets/javascripts/workarea/storefront/config.js.erb +0 -5
- data/app/assets/javascripts/workarea/storefront/modules/{analytics.js → analytics.js.erb} +17 -0
- data/app/assets/javascripts/workarea/storefront/modules/dialog_buttons.js +1 -1
- data/app/assets/javascripts/workarea/storefront/modules/workarea_analytics.js +4 -0
- data/app/assets/stylesheets/workarea/storefront/application.scss.erb +0 -2
- data/app/assets/stylesheets/workarea/storefront/email/_base.scss +9 -1
- data/app/assets/stylesheets/workarea/storefront/email/_components.scss +1 -1
- data/app/assets/stylesheets/workarea/storefront/email/_helpers.scss +16 -0
- data/app/assets/stylesheets/workarea/storefront/email/{_settings.scss → _settings.scss.erb} +1 -1
- data/app/controllers/workarea/storefront/analytics_controller.rb +36 -21
- data/app/controllers/workarea/storefront/application_controller.rb +2 -4
- data/app/controllers/workarea/storefront/cart_items_controller.rb +1 -2
- data/app/controllers/workarea/storefront/checkout/addresses_controller.rb +0 -2
- data/app/controllers/workarea/storefront/checkouts_controller.rb +6 -4
- data/app/controllers/workarea/storefront/content_areas_controller.rb +1 -0
- data/app/controllers/workarea/storefront/content_blocks_controller.rb +1 -0
- data/app/controllers/workarea/storefront/current_checkout.rb +20 -14
- data/app/controllers/workarea/storefront/downloads_controller.rb +18 -0
- data/app/controllers/workarea/storefront/email_signups_controller.rb +1 -0
- data/app/controllers/workarea/storefront/errors_controller.rb +6 -0
- data/app/controllers/workarea/storefront/recent_views_controller.rb +2 -35
- data/app/controllers/workarea/storefront/recommendations_controller.rb +2 -2
- data/app/controllers/workarea/storefront/searches_controller.rb +0 -11
- data/app/controllers/workarea/storefront/users/accounts_controller.rb +2 -7
- data/app/controllers/workarea/storefront/users/credit_cards_controller.rb +5 -2
- data/app/controllers/workarea/storefront/users/passwords_controller.rb +1 -5
- data/app/helpers/workarea/storefront/application_helper.rb +19 -3
- data/app/helpers/workarea/storefront/content_helper.rb +1 -1
- data/app/helpers/workarea/storefront/favicons_helper.rb +6 -7
- data/app/helpers/workarea/storefront/navigation_helper.rb +10 -0
- data/app/helpers/workarea/storefront/schema_org_helper.rb +156 -0
- data/app/mailers/workarea/storefront/application_mailer.rb +1 -0
- data/app/view_models/workarea/storefront/category_view_model.rb +2 -2
- data/app/view_models/workarea/storefront/content_block_view_model.rb +41 -10
- data/app/view_models/workarea/storefront/content_blocks/product_insights_view_model.rb +1 -1
- data/app/view_models/workarea/storefront/display_content.rb +3 -1
- data/app/view_models/workarea/storefront/inquiry_view_model.rb +1 -7
- data/app/view_models/workarea/storefront/inventory_status_view_model.rb +10 -6
- data/app/view_models/workarea/storefront/order_item_view_model.rb +14 -0
- data/app/view_models/workarea/storefront/product_view_model.rb +22 -4
- data/app/view_models/workarea/storefront/recommendations_view_model.rb +8 -4
- data/app/view_models/workarea/storefront/search_view_model.rb +1 -1
- data/app/view_models/workarea/storefront/user_activity_view_model.rb +6 -17
- data/app/views/layouts/workarea/storefront/application.html.haml +13 -17
- data/app/views/layouts/workarea/storefront/checkout.html.haml +1 -1
- data/app/views/layouts/workarea/storefront/content_preview.html.haml +1 -0
- data/app/views/layouts/workarea/storefront/email.html.haml +33 -26
- data/app/views/layouts/workarea/storefront/empty.html.haml +1 -0
- data/app/views/layouts/workarea/storefront/navigation.html.haml +1 -1
- data/app/views/workarea/storefront/account_mailer/creation.html.haml +2 -0
- data/app/views/workarea/storefront/account_mailer/password_reset.html.haml +2 -0
- data/app/views/workarea/storefront/cart_items/create.html.haml +1 -1
- data/app/views/workarea/storefront/carts/show.html.haml +1 -1
- data/app/views/workarea/storefront/categories/show.html.haml +3 -2
- data/app/views/workarea/storefront/checkouts/confirmation.html.haml +1 -1
- data/app/views/workarea/storefront/contacts/show.html.haml +4 -2
- data/app/views/workarea/storefront/content_areas/show.html.haml +1 -0
- data/app/views/workarea/storefront/content_blocks/_category_summary.html.haml +2 -1
- data/app/views/workarea/storefront/content_blocks/_product_insights.html.haml +2 -1
- data/app/views/workarea/storefront/content_blocks/_product_list.html.haml +2 -1
- data/app/views/workarea/storefront/errors/show.html.haml +1 -0
- data/app/views/workarea/storefront/fulfillment_mailer/shipped.html.haml +3 -1
- data/app/views/workarea/storefront/order_mailer/_summary.html.haml +6 -0
- data/app/views/workarea/storefront/order_mailer/confirmation.html.haml +3 -0
- data/app/views/workarea/storefront/order_mailer/reminder.html.haml +3 -0
- data/app/views/workarea/storefront/orders/_summary.html.haml +3 -1
- data/app/views/workarea/storefront/orders/show.html.haml +3 -3
- data/app/views/workarea/storefront/pages/home_page.html.haml +4 -0
- data/app/views/workarea/storefront/pages/robots.text.erb +0 -1
- data/app/views/workarea/storefront/pages/show.html.haml +1 -0
- data/app/views/workarea/storefront/products/_price.html.haml +1 -2
- data/app/views/workarea/storefront/products/_pricing.html.haml +12 -6
- data/app/views/workarea/storefront/products/_summary.html.haml +3 -3
- data/app/views/workarea/storefront/products/show.html.haml +6 -4
- data/app/views/workarea/storefront/products/templates/_generic.html.haml +5 -5
- data/app/views/workarea/storefront/products/templates/_option_selects.html.haml +5 -7
- data/app/views/workarea/storefront/products/templates/_option_thumbnails.html.haml +5 -7
- data/app/views/workarea/storefront/recent_views/aside.html.haml +3 -10
- data/app/views/workarea/storefront/recent_views/narrow.html.haml +3 -10
- data/app/views/workarea/storefront/recent_views/show.html.haml +3 -10
- data/app/views/workarea/storefront/recommendations/show.html.haml +1 -1
- data/app/views/workarea/storefront/searches/show.html.haml +4 -5
- data/app/views/workarea/storefront/users/accounts/edit.html.haml +3 -3
- data/app/views/workarea/storefront/users/accounts/show.html.haml +3 -3
- data/app/views/workarea/storefront/users/addresses/edit.html.haml +3 -3
- data/app/views/workarea/storefront/users/addresses/new.html.haml +3 -3
- data/app/views/workarea/storefront/users/credit_cards/edit.html.haml +3 -3
- data/app/views/workarea/storefront/users/credit_cards/new.html.haml +3 -3
- data/app/views/workarea/storefront/users/orders/index.html.haml +3 -3
- data/app/views/workarea/storefront/users/orders/show.html.haml +4 -4
- data/app/views/workarea/storefront/users/passwords/new.html.haml +3 -3
- data/config/locales/en.yml +16 -3
- data/config/routes.rb +4 -2
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/helpers/workarea/storefront/content_helper_test.rb +1 -0
- data/test/helpers/workarea/storefront/navigation_helper_test.rb +4 -0
- data/test/helpers/workarea/storefront/schema_org_helper_test.rb +27 -0
- data/test/integration/workarea/storefront/analytics_integration_test.rb +44 -4
- data/test/integration/workarea/storefront/cart_items_integration_test.rb +0 -12
- data/test/integration/workarea/storefront/categories_integration_test.rb +0 -10
- data/test/integration/workarea/storefront/checkout_side_effects_integration_test.rb +15 -1
- data/test/integration/workarea/storefront/checkouts_integration_test.rb +68 -11
- data/test/integration/workarea/storefront/contact_form_integration_test.rb +18 -20
- data/test/integration/workarea/storefront/content_blocks_integration_test.rb +1 -4
- data/test/integration/workarea/storefront/current_checkout_integration_test.rb +53 -2
- data/test/integration/workarea/storefront/downloads_integration_test.rb +38 -0
- data/test/integration/workarea/storefront/email_signups_integration_test.rb +2 -0
- data/test/integration/workarea/storefront/guest_browsing_integration_test.rb +2 -2
- data/test/integration/workarea/storefront/impersonations_integration_test.rb +2 -2
- data/test/integration/workarea/storefront/login_integration_test.rb +3 -9
- data/test/integration/workarea/storefront/order_data_integration_test.rb +1 -9
- data/test/integration/workarea/storefront/place_order_integration_test.rb +5 -7
- data/test/integration/workarea/storefront/placing_order_integration_test.rb +1 -1
- data/test/integration/workarea/storefront/recent_views_integration_test.rb +29 -0
- data/test/integration/workarea/storefront/releases_integration_test.rb +132 -0
- data/test/integration/workarea/storefront/search_integration_test.rb +0 -46
- data/test/integration/workarea/storefront/segment_overrides_integration_test.rb +48 -0
- data/test/integration/workarea/storefront/segments_integration_test.rb +250 -0
- data/test/integration/workarea/storefront/store_credit_integration_test.rb +1 -1
- data/test/integration/workarea/storefront/users/credit_cards_integration_test.rb +2 -2
- data/test/integration/workarea/storefront/users/passwords_integration_test.rb +0 -19
- data/test/javascripts/traffic_referrer_spec.js +1 -1
- data/test/mailers/workarea/storefront/transactional_mailer_test.rb +9 -13
- data/test/system/workarea/storefront/analytics_system_test.rb +54 -40
- data/test/system/workarea/storefront/content_system_test.rb +10 -1
- data/test/system/workarea/storefront/digital_products_system_test.rb +2 -0
- data/test/system/workarea/storefront/download_system_test.rb +145 -0
- data/test/system/workarea/storefront/guest_checkout_system_test.rb +20 -0
- data/test/system/workarea/storefront/logged_in_checkout_system_test.rb +31 -32
- data/test/system/workarea/storefront/passwords_system_test.rb +35 -37
- data/test/system/workarea/storefront/pricing_overrides_system_test.rb +13 -2
- data/test/system/workarea/storefront/segment_overrides_system_test.rb +69 -0
- data/test/view_models/workarea/storefront/category_view_model_test.rb +20 -0
- data/test/view_models/workarea/storefront/content_block_view_model_test.rb +135 -3
- data/test/view_models/workarea/storefront/display_content_test.rb +4 -0
- data/test/view_models/workarea/storefront/product_view_model/option_set_test.rb +7 -8
- data/test/view_models/workarea/storefront/product_view_model_test.rb +17 -10
- data/test/view_models/workarea/storefront/search_view_model_test.rb +0 -6
- data/test/view_models/workarea/storefront/user_activity_view_model_test.rb +18 -20
- metadata +20 -22
- data/app/assets/javascripts/workarea/storefront/modules/recent_views.js +0 -25
- data/app/assets/javascripts/workarea/storefront/modules/search_fields.js +0 -59
- data/app/assets/javascripts/workarea/storefront/templates/ui_menu_heading.jst.ejs +0 -1
- data/app/assets/javascripts/workarea/storefront/templates/ui_menu_item.jst.ejs +0 -8
- data/app/assets/stylesheets/jquery_ui/storefront/_ui_autocomplete.scss +0 -17
- data/app/assets/stylesheets/jquery_ui/storefront/_ui_menu.scss +0 -40
- data/app/controllers/workarea/storefront/http_caching.rb +0 -33
- data/app/controllers/workarea/storefront/user_activity.rb +0 -19
- data/app/view_models/workarea/storefront/search_suggestion_view_model.rb +0 -87
- data/app/views/workarea/storefront/searches/index.json.jbuilder +0 -1
- data/app/views/workarea/storefront/style_guides/components/_ui_autocomplete.html.haml +0 -11
- data/test/dummy/tmp/screenshots/.keep +0 -0
- data/test/view_models/workarea/storefront/search_suggestion_view_model_test.rb +0 -42
@@ -12,12 +12,6 @@ module Workarea
|
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
def response_cookies
|
16
|
-
ActionDispatch::Cookies::CookieJar
|
17
|
-
.build(request, response.cookies)
|
18
|
-
.signed
|
19
|
-
end
|
20
|
-
|
21
15
|
def test_can_login_a_user
|
22
16
|
post storefront.login_path,
|
23
17
|
params: {
|
@@ -26,7 +20,7 @@ module Workarea
|
|
26
20
|
}
|
27
21
|
|
28
22
|
assert_redirected_to(storefront.users_account_path)
|
29
|
-
assert(
|
23
|
+
assert(session[:user_id].present?)
|
30
24
|
|
31
25
|
@user.reload
|
32
26
|
assert(@user.last_login_at.present?)
|
@@ -39,7 +33,7 @@ module Workarea
|
|
39
33
|
password: 'foo'
|
40
34
|
}
|
41
35
|
|
42
|
-
assert(
|
36
|
+
assert(session[:user_id].blank?)
|
43
37
|
|
44
38
|
@user.reload
|
45
39
|
assert(@user.last_login_at.blank?)
|
@@ -146,7 +140,7 @@ module Workarea
|
|
146
140
|
delete storefront.logout_path
|
147
141
|
|
148
142
|
assert_redirected_to(storefront.login_path)
|
149
|
-
assert(
|
143
|
+
assert(session[:user_id].blank?)
|
150
144
|
|
151
145
|
get storefront.current_user_path(format: 'json')
|
152
146
|
results = JSON.parse(response.body)
|
@@ -38,13 +38,6 @@ module Workarea
|
|
38
38
|
)
|
39
39
|
end
|
40
40
|
|
41
|
-
def complete_checkout(email = nil, password = nil)
|
42
|
-
put storefront.recent_views_path,
|
43
|
-
params: { product_id: product.id }
|
44
|
-
|
45
|
-
super
|
46
|
-
end
|
47
|
-
|
48
41
|
def test_order_info_saving
|
49
42
|
complete_checkout
|
50
43
|
|
@@ -54,7 +47,6 @@ module Workarea
|
|
54
47
|
assert_equal(order.email, 'bcrouse@workarea.com')
|
55
48
|
assert_equal('127.0.0.1', order.ip_address)
|
56
49
|
assert_equal('Mozilla', order.user_agent)
|
57
|
-
assert(order.user_activity_id.present?)
|
58
50
|
|
59
51
|
assert_equal(1, order.items.length)
|
60
52
|
assert_equal(@product.id, order.items.first.product_id)
|
@@ -108,7 +100,7 @@ module Workarea
|
|
108
100
|
assert_equal('Test Card', payment.credit_card.issuer)
|
109
101
|
assert_equal('XXXX-XXXX-XXXX-1', payment.credit_card.display_number)
|
110
102
|
assert_equal(1, payment.credit_card.month)
|
111
|
-
assert_equal(
|
103
|
+
assert_equal(2020, payment.credit_card.year)
|
112
104
|
refute(payment.credit_card.token.blank?)
|
113
105
|
assert(payment.credit_card.saved_card_id.blank?)
|
114
106
|
|
@@ -3,9 +3,7 @@ require 'test_helper'
|
|
3
3
|
module Workarea
|
4
4
|
module Storefront
|
5
5
|
class PlaceOrderIntegrationTest < Workarea::IntegrationTest
|
6
|
-
setup
|
7
|
-
|
8
|
-
def setup_checkout
|
6
|
+
setup do
|
9
7
|
create_tax_category(
|
10
8
|
name: 'Sales Tax',
|
11
9
|
code: '001',
|
@@ -68,7 +66,7 @@ module Workarea
|
|
68
66
|
credit_card: {
|
69
67
|
number: '1',
|
70
68
|
month: 1,
|
71
|
-
year:
|
69
|
+
year: 2020,
|
72
70
|
cvv: '999'
|
73
71
|
}
|
74
72
|
}
|
@@ -83,7 +81,7 @@ module Workarea
|
|
83
81
|
credit_card: {
|
84
82
|
number: '2',
|
85
83
|
month: 1,
|
86
|
-
year:
|
84
|
+
year: 2020,
|
87
85
|
cvv: '999'
|
88
86
|
}
|
89
87
|
}
|
@@ -99,7 +97,7 @@ module Workarea
|
|
99
97
|
credit_card: {
|
100
98
|
number: '1',
|
101
99
|
month: 1,
|
102
|
-
year:
|
100
|
+
year: 2020,
|
103
101
|
cvv: '999'
|
104
102
|
}
|
105
103
|
}
|
@@ -119,7 +117,7 @@ module Workarea
|
|
119
117
|
credit_card: {
|
120
118
|
number: '1',
|
121
119
|
month: 1,
|
122
|
-
year:
|
120
|
+
year: 2020,
|
123
121
|
cvv: '999'
|
124
122
|
}
|
125
123
|
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class RecentViewsIntegrationTest < Workarea::IntegrationTest
|
6
|
+
def test_show
|
7
|
+
password = 'W3bl1nc!'
|
8
|
+
user = create_user(password: password)
|
9
|
+
category = create_category
|
10
|
+
product = create_product
|
11
|
+
Metrics::User.save_affinity(
|
12
|
+
id: user.email,
|
13
|
+
action: 'viewed',
|
14
|
+
product_ids: [product.id]
|
15
|
+
)
|
16
|
+
|
17
|
+
post storefront.login_path,
|
18
|
+
params: { email: user.email, password: password }
|
19
|
+
|
20
|
+
assert_redirected_to(storefront.users_account_path)
|
21
|
+
refute(session[:user_id].blank?)
|
22
|
+
|
23
|
+
product_url = storefront.product_path(product, via: category.id)
|
24
|
+
get storefront.recent_views_path(via: category.id)
|
25
|
+
assert_select(%(.product-summary__name a[href="#{product_url}"]))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class ReleasesIntegrationTest < Workarea::IntegrationTest
|
6
|
+
def test_previewing_releases
|
7
|
+
first = create_release(publish_at: 1.day.from_now)
|
8
|
+
second = create_release(publish_at: 2.days.from_now)
|
9
|
+
|
10
|
+
product = create_product(name: 'Foo', template: 'generic', description: 'One')
|
11
|
+
first.as_current { product.update_attributes!(name: 'Bar', description: 'Two') }
|
12
|
+
second.as_current { product.update_attributes!(name: 'Baz') }
|
13
|
+
|
14
|
+
set_current_user(create_user(super_admin: true))
|
15
|
+
|
16
|
+
post admin.release_session_path, params: { release_id: first.id }
|
17
|
+
get storefront.product_path(product)
|
18
|
+
assert(response.body.include?('Bar'))
|
19
|
+
assert(response.body.include?('Two'))
|
20
|
+
|
21
|
+
post admin.release_session_path, params: { release_id: second.id }
|
22
|
+
get storefront.product_path(product)
|
23
|
+
assert(response.body.include?('Baz'))
|
24
|
+
assert(response.body.include?('Two'))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_browsing_featured_categories
|
28
|
+
set_current_user(create_user(super_admin: true))
|
29
|
+
product_one = create_product(id: 'PROD1', name: 'Foo')
|
30
|
+
product_two = create_product(id: 'PROD2', name: 'Bar')
|
31
|
+
pricing = Pricing::Sku.find('SKU').prices.first.tap { |p| p.update!(regular: 5) }
|
32
|
+
category = create_category(product_ids: [product_one.id, product_two.id])
|
33
|
+
|
34
|
+
get storefront.category_path(category)
|
35
|
+
assert_match(/Foo.*Bar/m, response.body)
|
36
|
+
assert_includes(response.body, '5.00')
|
37
|
+
|
38
|
+
release = create_release
|
39
|
+
release.as_current do
|
40
|
+
category.update!(product_ids: [product_two.id, product_one.id])
|
41
|
+
product_one.update!(name: 'Baz')
|
42
|
+
pricing.update!(regular: 7.99)
|
43
|
+
end
|
44
|
+
|
45
|
+
post admin.release_session_path, params: { release_id: release.id }
|
46
|
+
|
47
|
+
get storefront.category_path(category)
|
48
|
+
assert_match(/Bar.*Baz/m, response.body)
|
49
|
+
assert_includes(response.body, '7.99')
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_category_rules_in_releases
|
53
|
+
product_one = create_product(id: 'PROD1', name: 'Foo')
|
54
|
+
product_two = create_product(id: 'PROD2', name: 'Bar')
|
55
|
+
category = create_category(
|
56
|
+
product_rules: [{ name: 'search', operator: 'equals', value: 'foo' }]
|
57
|
+
)
|
58
|
+
|
59
|
+
get storefront.category_path(category)
|
60
|
+
assert_includes(response.body, 'Foo')
|
61
|
+
refute_includes(response.body, 'Bar')
|
62
|
+
|
63
|
+
release = create_release
|
64
|
+
release.as_current do
|
65
|
+
category.update!(
|
66
|
+
product_rules: [{ name: 'search', operator: 'equals', value: 'bar' }]
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
post admin.release_session_path, params: { release_id: release.id }
|
71
|
+
|
72
|
+
get storefront.category_path(category)
|
73
|
+
refute_includes(response.body, 'Foo')
|
74
|
+
assert_includes(response.body, 'Bar')
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_searches_with_release_customizations
|
78
|
+
set_current_user(create_user(super_admin: true))
|
79
|
+
product_one = create_product(id: 'PROD1', name: 'Test Foo')
|
80
|
+
product_two = create_product(id: 'PROD2', name: 'Test Bar')
|
81
|
+
search_customization = create_search_customization(
|
82
|
+
id: 'test',
|
83
|
+
query: 'test',
|
84
|
+
product_ids: [product_one.id, product_two.id]
|
85
|
+
)
|
86
|
+
|
87
|
+
get storefront.search_path(q: 'test')
|
88
|
+
assert_match(/Test Foo.*Test Bar/m, response.body)
|
89
|
+
|
90
|
+
release = create_release
|
91
|
+
release.as_current do
|
92
|
+
search_customization.update!(product_ids: [product_two.id, product_one.id])
|
93
|
+
product_one.update!(name: 'Test Baz')
|
94
|
+
end
|
95
|
+
|
96
|
+
post admin.release_session_path, params: { release_id: release.id }
|
97
|
+
|
98
|
+
get storefront.search_path(q: 'test')
|
99
|
+
assert_match(/Test Bar.*Test Baz/m, response.body)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_rescheduling_releases
|
103
|
+
set_current_user(create_user(super_admin: true))
|
104
|
+
product_one = create_product(id: 'PROD1', name: 'Foo')
|
105
|
+
product_two = create_product(id: 'PROD2', name: 'Bar')
|
106
|
+
category = create_category(product_ids: [product_one.id, product_two.id])
|
107
|
+
|
108
|
+
get storefront.category_path(category)
|
109
|
+
assert_match(/Foo.*Bar/m, response.body)
|
110
|
+
|
111
|
+
release_one = create_release(publish_at: 1.day.from_now)
|
112
|
+
release_one.as_current { category.update!(product_ids: [product_two.id, product_one.id]) }
|
113
|
+
|
114
|
+
release_two = create_release(publish_at: 2.days.from_now)
|
115
|
+
release_two.as_current { product_one.update!(name: 'Baz') }
|
116
|
+
|
117
|
+
post admin.release_session_path, params: { release_id: release_one.id }
|
118
|
+
get storefront.category_path(category)
|
119
|
+
assert_match(/Bar.*Foo/m, response.body)
|
120
|
+
|
121
|
+
post admin.release_session_path, params: { release_id: release_two.id }
|
122
|
+
get storefront.category_path(category)
|
123
|
+
assert_match(/Bar.*Baz/m, response.body)
|
124
|
+
|
125
|
+
release_one.update!(publish_at: 1.week.from_now)
|
126
|
+
post admin.release_session_path, params: { release_id: release_one.id }
|
127
|
+
get storefront.category_path(category)
|
128
|
+
assert_match(/Bar.*Baz/m, response.body)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -13,42 +13,6 @@ module Workarea
|
|
13
13
|
assert_redirected_to(storefront.cart_path)
|
14
14
|
end
|
15
15
|
|
16
|
-
def test_renders_search_suggestions_in_json
|
17
|
-
create_product(name: 'Foo')
|
18
|
-
create_category(name: 'Foo Category')
|
19
|
-
create_page(name: 'Foo Page')
|
20
|
-
|
21
|
-
Metrics::SearchByDay.save_search('foo', 3)
|
22
|
-
travel_to 1.week.from_now
|
23
|
-
GenerateInsights.generate_all!
|
24
|
-
BulkIndexSearches.perform
|
25
|
-
|
26
|
-
get storefront.searches_path(q: 'foo', format: 'json')
|
27
|
-
results = JSON.parse(response.body)['results']
|
28
|
-
assert_equal(4, results.length)
|
29
|
-
|
30
|
-
search = results.detect { |r| r['type'] == 'Searches' }
|
31
|
-
assert(search.present?)
|
32
|
-
assert_equal('foo', search['value'])
|
33
|
-
assert_equal(storefront.search_path(q: 'foo'), search['url'])
|
34
|
-
|
35
|
-
product = results.detect { |r| r['type'] == 'Products' }
|
36
|
-
assert(product.present?)
|
37
|
-
assert_equal('Foo', product['value'])
|
38
|
-
assert_match(/product_images/, product['image'])
|
39
|
-
assert_equal(storefront.product_path('foo'), product['url'])
|
40
|
-
|
41
|
-
category = results.detect { |r| r['type'] == 'Categories' }
|
42
|
-
assert(category.present?)
|
43
|
-
assert_equal('Foo Category', category['value'])
|
44
|
-
assert_equal(storefront.category_path('foo-category'), category['url'])
|
45
|
-
|
46
|
-
page = results.detect { |r| r['type'] == 'Pages' }
|
47
|
-
assert(page.present?)
|
48
|
-
assert_equal('Foo Page', page['value'])
|
49
|
-
assert_equal(storefront.page_path('foo-page'), page['url'])
|
50
|
-
end
|
51
|
-
|
52
16
|
def test_handles_invalid_queries
|
53
17
|
get storefront.search_path(q: '{()!}'),
|
54
18
|
headers: { 'HTTP_REFERER' => '/foo' }
|
@@ -123,16 +87,6 @@ module Workarea
|
|
123
87
|
assert_includes(response.body, 'Foo A')
|
124
88
|
assert_includes(response.body, 'Foo B')
|
125
89
|
end
|
126
|
-
|
127
|
-
def test_not_accepting_per_page_param
|
128
|
-
one = create_product(name: 'Foo A')
|
129
|
-
two = create_product(name: 'Foo B')
|
130
|
-
|
131
|
-
get storefront.search_path(q: 'foo', page: 1, per_page: 1)
|
132
|
-
assert(response.ok?)
|
133
|
-
assert_includes(response.body, storefront.product_path(one))
|
134
|
-
assert_includes(response.body, storefront.product_path(two))
|
135
|
-
end
|
136
90
|
end
|
137
91
|
end
|
138
92
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class SegmentOverridesIntegrationTest < Workarea::IntegrationTest
|
6
|
+
include Storefront::IntegrationTest
|
7
|
+
|
8
|
+
def test_admins_ignore_segments
|
9
|
+
create_life_cycle_segments
|
10
|
+
first_time_visitor = Segment::FirstTimeVisitor.instance
|
11
|
+
returning_visitor = Segment::ReturningVisitor.instance
|
12
|
+
product = create_product(active: true, active_segment_ids: [returning_visitor.id])
|
13
|
+
content = Content.for('home_page')
|
14
|
+
content.blocks.create!(
|
15
|
+
type: 'html',
|
16
|
+
data: { 'html' => '<p>Foo</p>' },
|
17
|
+
active_segment_ids: [returning_visitor.id]
|
18
|
+
)
|
19
|
+
|
20
|
+
set_current_user(create_user(admin: true))
|
21
|
+
|
22
|
+
get storefront.search_path(q: '*')
|
23
|
+
refute_includes(response.body, product.id)
|
24
|
+
|
25
|
+
get storefront.root_path
|
26
|
+
refute_includes(response.body, '<p>Foo</p>')
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_impersonation_segments
|
30
|
+
create_life_cycle_segments
|
31
|
+
first_time_visitor = Segment::FirstTimeVisitor.instance
|
32
|
+
customer = create_user
|
33
|
+
super_admin = create_user(password: 'W3bl1nc!', super_admin: true)
|
34
|
+
post storefront.login_path, params: { email: super_admin.email, password: 'W3bl1nc!' }
|
35
|
+
post admin.impersonations_path, params: { user_id: customer.id }
|
36
|
+
|
37
|
+
get storefront.current_user_path(format: 'json')
|
38
|
+
assert(response.headers['X-Workarea-Segments'].blank?)
|
39
|
+
|
40
|
+
post admin.segment_override_path,
|
41
|
+
params: { segment_ids: { first_time_visitor.id => 'true' } }
|
42
|
+
|
43
|
+
get storefront.current_user_path(format: 'json')
|
44
|
+
assert_equal(first_time_visitor.id, response.headers['X-Workarea-Segments'])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,250 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class SegmentsIntegrationTest < Workarea::IntegrationTest
|
6
|
+
include Storefront::IntegrationTest
|
7
|
+
|
8
|
+
def test_life_cycle_segments_functionality
|
9
|
+
Workarea.config.loyal_customers_min_orders = 3
|
10
|
+
create_life_cycle_segments
|
11
|
+
|
12
|
+
get storefront.current_user_path(format: 'json')
|
13
|
+
assert_equal(
|
14
|
+
Segment::FirstTimeVisitor.instance.id.to_s,
|
15
|
+
response.headers['X-Workarea-Segments']
|
16
|
+
)
|
17
|
+
|
18
|
+
cookies[:sessions] = 2
|
19
|
+
get storefront.current_user_path(format: 'json')
|
20
|
+
assert_equal(
|
21
|
+
Segment::ReturningVisitor.instance.id.to_s,
|
22
|
+
response.headers['X-Workarea-Segments']
|
23
|
+
)
|
24
|
+
|
25
|
+
complete_checkout
|
26
|
+
|
27
|
+
get storefront.current_user_path(format: 'json')
|
28
|
+
assert_equal(
|
29
|
+
Segment::FirstTimeCustomer.instance.id.to_s,
|
30
|
+
response.headers['X-Workarea-Segments']
|
31
|
+
)
|
32
|
+
|
33
|
+
complete_checkout
|
34
|
+
|
35
|
+
get storefront.current_user_path(format: 'json')
|
36
|
+
assert_equal(
|
37
|
+
Segment::ReturningCustomer.instance.id.to_s,
|
38
|
+
response.headers['X-Workarea-Segments']
|
39
|
+
)
|
40
|
+
|
41
|
+
complete_checkout
|
42
|
+
|
43
|
+
get storefront.current_user_path(format: 'json')
|
44
|
+
assert_equal(
|
45
|
+
Segment::LoyalCustomer.instance.id.to_s,
|
46
|
+
response.headers['X-Workarea-Segments']
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_products_active_by_segment
|
51
|
+
segment_one = create_segment(rules: [Segment::Rules::Sessions.new(minimum: 1, maximum: 1)])
|
52
|
+
segment_two = create_segment(rules: [Segment::Rules::Sessions.new(minimum: 2, maximum: 2)])
|
53
|
+
product_one = create_product(active: true, active_segment_ids: [segment_two.id])
|
54
|
+
product_two = create_product(active: true, active_segment_ids: [segment_one.id])
|
55
|
+
|
56
|
+
assert_raise InvalidDisplay do
|
57
|
+
cookies[:sessions] = 0
|
58
|
+
get storefront.product_path(product_one)
|
59
|
+
assert(response.not_found?)
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_raise InvalidDisplay do
|
63
|
+
cookies[:sessions] = 0
|
64
|
+
get storefront.product_path(product_two)
|
65
|
+
assert(response.not_found?)
|
66
|
+
end
|
67
|
+
|
68
|
+
cookies[:sessions] = 0
|
69
|
+
get storefront.search_path(q: '*')
|
70
|
+
refute_includes(response.body, product_one.id)
|
71
|
+
refute_includes(response.body, product_two.id)
|
72
|
+
|
73
|
+
assert_raise InvalidDisplay do
|
74
|
+
cookies[:sessions] = 1
|
75
|
+
get storefront.product_path(product_one)
|
76
|
+
assert(response.not_found?)
|
77
|
+
end
|
78
|
+
|
79
|
+
cookies[:sessions] = 1
|
80
|
+
get storefront.product_path(product_two)
|
81
|
+
assert(response.ok?)
|
82
|
+
|
83
|
+
cookies[:sessions] = 1
|
84
|
+
get storefront.search_path(q: '*')
|
85
|
+
refute_includes(response.body, product_one.id)
|
86
|
+
assert_includes(response.body, product_two.id)
|
87
|
+
|
88
|
+
cookies[:sessions] = 2
|
89
|
+
get storefront.product_path(product_one)
|
90
|
+
assert(response.ok?)
|
91
|
+
|
92
|
+
assert_raise InvalidDisplay do
|
93
|
+
cookies[:sessions] = 2
|
94
|
+
get storefront.product_path(product_two)
|
95
|
+
assert(response.not_found?)
|
96
|
+
end
|
97
|
+
|
98
|
+
cookies[:sessions] = 2
|
99
|
+
get storefront.search_path(q: '*')
|
100
|
+
assert_includes(response.body, product_one.id)
|
101
|
+
refute_includes(response.body, product_two.id)
|
102
|
+
|
103
|
+
segment_one.rules.first.update!(minimum: 1, maximum: nil)
|
104
|
+
segment_two.rules.first.update!(minimum: 1, maximum: nil)
|
105
|
+
|
106
|
+
cookies[:sessions] = 1
|
107
|
+
get storefront.product_path(product_one)
|
108
|
+
assert(response.ok?)
|
109
|
+
|
110
|
+
cookies[:sessions] = 1
|
111
|
+
get storefront.product_path(product_two)
|
112
|
+
assert(response.ok?)
|
113
|
+
|
114
|
+
cookies[:sessions] = 1
|
115
|
+
get storefront.search_path(q: '*')
|
116
|
+
assert_includes(response.body, product_one.id)
|
117
|
+
assert_includes(response.body, product_two.id)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_content_active_by_segment
|
121
|
+
segment_one = create_segment(rules: [Segment::Rules::Sessions.new(minimum: 1, maximum: 1)])
|
122
|
+
segment_two = create_segment(rules: [Segment::Rules::Sessions.new(minimum: 2, maximum: 2)])
|
123
|
+
|
124
|
+
content = Content.for('home_page')
|
125
|
+
content.blocks.create!(
|
126
|
+
type: 'html',
|
127
|
+
data: { 'html' => '<p>Foo</p>' },
|
128
|
+
active_segment_ids: [segment_one.id]
|
129
|
+
)
|
130
|
+
content.blocks.create!(
|
131
|
+
type: 'html',
|
132
|
+
data: { 'html' => '<p>Bar</p>' },
|
133
|
+
active_segment_ids: [segment_two.id]
|
134
|
+
)
|
135
|
+
|
136
|
+
cookies[:sessions] = 1
|
137
|
+
get storefront.root_path
|
138
|
+
assert_includes(response.body, '<p>Foo</p>')
|
139
|
+
refute_includes(response.body, '<p>Bar</p>')
|
140
|
+
|
141
|
+
cookies[:sessions] = 2
|
142
|
+
get storefront.root_path
|
143
|
+
refute_includes(response.body, '<p>Foo</p>')
|
144
|
+
assert_includes(response.body, '<p>Bar</p>')
|
145
|
+
|
146
|
+
segment_one.rules.first.update!(minimum: 1, maximum: nil)
|
147
|
+
segment_two.rules.first.update!(minimum: 1, maximum: nil)
|
148
|
+
cookies[:sessions] = 1
|
149
|
+
get storefront.root_path
|
150
|
+
assert_includes(response.body, '<p>Foo</p>')
|
151
|
+
assert_includes(response.body, '<p>Bar</p>')
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_logged_in_based_segments
|
155
|
+
logged_in = create_segment(rules: [Segment::Rules::LoggedIn.new(logged_in: true)])
|
156
|
+
logged_out = create_segment(rules: [Segment::Rules::LoggedIn.new(logged_in: false)])
|
157
|
+
|
158
|
+
get storefront.current_user_path(format: 'json')
|
159
|
+
assert_equal(logged_out.id.to_s, response.headers['X-Workarea-Segments'])
|
160
|
+
|
161
|
+
user = create_user(password: 'w0rkArea!')
|
162
|
+
post storefront.login_path,
|
163
|
+
params: { email: user.email, password: 'w0rkArea!' }
|
164
|
+
|
165
|
+
get storefront.current_user_path(format: 'json')
|
166
|
+
assert_equal(logged_in.id.to_s, response.headers['X-Workarea-Segments'])
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_endpoints_without_a_visit
|
170
|
+
assert_nothing_raised do
|
171
|
+
get storefront.internal_error_path(format: 'png')
|
172
|
+
refute(response.headers.key?('X-Workarea-Segments'))
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_segmented_discounts
|
177
|
+
new_visitors = create_segment(rules: [Segment::Rules::Sessions.new(minimum: 0)])
|
178
|
+
returning_visitors = create_segment(rules: [Segment::Rules::Sessions.new(minimum: 2)])
|
179
|
+
product = create_product(variants: [{ sku: 'SKU', regular: 5.to_m }])
|
180
|
+
discount = create_product_discount(
|
181
|
+
amount_type: 'flat',
|
182
|
+
amount: 1.to_m,
|
183
|
+
product_ids: [product.id],
|
184
|
+
active: true,
|
185
|
+
active_segment_ids: [returning_visitors.id]
|
186
|
+
)
|
187
|
+
|
188
|
+
post storefront.cart_items_path,
|
189
|
+
params: { product_id: product.id, sku: product.skus.first, quantity: 1 }
|
190
|
+
|
191
|
+
order = Order.first
|
192
|
+
assert_equal(5.to_m, order.total_price)
|
193
|
+
|
194
|
+
cookies[:sessions] = 2
|
195
|
+
get storefront.cart_path # reprice the order
|
196
|
+
assert_equal(4.to_m, order.reload.total_price)
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_http_caching_headers_for_segmented_content
|
200
|
+
Workarea.config.strip_http_caching_in_tests = false
|
201
|
+
segment = create_segment(rules: [Segment::Rules::Sessions.new(maximum: 999)])
|
202
|
+
|
203
|
+
get storefront.root_path
|
204
|
+
refute_match(/private/, response.headers['Cache-Control'])
|
205
|
+
assert_match(/public/, response.headers['Cache-Control'])
|
206
|
+
assert(response.headers['X-Workarea-Segmented-Content'].blank?)
|
207
|
+
|
208
|
+
content = Content.for('home_page')
|
209
|
+
content.blocks.create!(
|
210
|
+
type: 'html',
|
211
|
+
data: { 'html' => '<p>Foo</p>' },
|
212
|
+
active_segment_ids: [segment.id]
|
213
|
+
)
|
214
|
+
|
215
|
+
get storefront.root_path
|
216
|
+
assert_match(/private/, response.headers['Cache-Control'])
|
217
|
+
refute_match(/public/, response.headers['Cache-Control'])
|
218
|
+
assert_equal('true', response.headers['X-Workarea-Segmented-Content'])
|
219
|
+
|
220
|
+
product = create_product(active: true, active_segment_ids: [])
|
221
|
+
get storefront.product_path(product)
|
222
|
+
assert(response.ok?)
|
223
|
+
refute_match(/private/, response.headers['Cache-Control'])
|
224
|
+
assert_match(/public/, response.headers['Cache-Control'])
|
225
|
+
assert(response.headers['X-Workarea-Segmented-Content'].blank?)
|
226
|
+
|
227
|
+
product.update!(active_segment_ids: [segment.id])
|
228
|
+
get storefront.product_path(product)
|
229
|
+
assert(response.ok?)
|
230
|
+
assert_match(/private/, response.headers['Cache-Control'])
|
231
|
+
refute_match(/public/, response.headers['Cache-Control'])
|
232
|
+
assert_equal('true', response.headers['X-Workarea-Segmented-Content'])
|
233
|
+
|
234
|
+
category = create_category(active: true, active_segment_ids: [])
|
235
|
+
get storefront.category_path(category)
|
236
|
+
assert(response.ok?)
|
237
|
+
refute_match(/private/, response.headers['Cache-Control'])
|
238
|
+
assert_match(/public/, response.headers['Cache-Control'])
|
239
|
+
assert(response.headers['X-Workarea-Segmented-Content'].blank?)
|
240
|
+
|
241
|
+
category.update!(product_ids: [product.id])
|
242
|
+
get storefront.category_path(category)
|
243
|
+
assert(response.ok?)
|
244
|
+
assert_match(/private/, response.headers['Cache-Control'])
|
245
|
+
refute_match(/public/, response.headers['Cache-Control'])
|
246
|
+
assert_equal('true', response.headers['X-Workarea-Segmented-Content'])
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|