workarea-api-storefront 4.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/README.md +58 -0
- data/Rakefile +10 -0
- data/app/controllers/workarea/api/storefront/accounts_controller.rb +31 -0
- data/app/controllers/workarea/api/storefront/analytics_controller.rb +41 -0
- data/app/controllers/workarea/api/storefront/application_controller.rb +65 -0
- data/app/controllers/workarea/api/storefront/assets_controller.rb +11 -0
- data/app/controllers/workarea/api/storefront/authentication.rb +30 -0
- data/app/controllers/workarea/api/storefront/authentication_tokens_controller.rb +50 -0
- data/app/controllers/workarea/api/storefront/cart_items_controller.rb +100 -0
- data/app/controllers/workarea/api/storefront/carts_controller.rb +47 -0
- data/app/controllers/workarea/api/storefront/categories_controller.rb +25 -0
- data/app/controllers/workarea/api/storefront/checkouts_controller.rb +117 -0
- data/app/controllers/workarea/api/storefront/contacts_controller.rb +20 -0
- data/app/controllers/workarea/api/storefront/current_checkout.rb +60 -0
- data/app/controllers/workarea/api/storefront/email_signups_controller.rb +15 -0
- data/app/controllers/workarea/api/storefront/menus_controller.rb +19 -0
- data/app/controllers/workarea/api/storefront/orders_controller.rb +32 -0
- data/app/controllers/workarea/api/storefront/pages_controller.rb +14 -0
- data/app/controllers/workarea/api/storefront/password_resets_controller.rb +17 -0
- data/app/controllers/workarea/api/storefront/products_controller.rb +17 -0
- data/app/controllers/workarea/api/storefront/recent_views_controller.rb +46 -0
- data/app/controllers/workarea/api/storefront/recommendations_controller.rb +22 -0
- data/app/controllers/workarea/api/storefront/saved_addresses_controller.rb +38 -0
- data/app/controllers/workarea/api/storefront/saved_credit_cards_controller.rb +54 -0
- data/app/controllers/workarea/api/storefront/searches_controller.rb +29 -0
- data/app/controllers/workarea/api/storefront/system_content_controller.rb +16 -0
- data/app/controllers/workarea/api/storefront/taxons_controller.rb +20 -0
- data/app/controllers/workarea/api/storefront/user_activity.rb +36 -0
- data/app/controllers/workarea/storefront/application_controller.decorator +12 -0
- data/app/helpers/workarea/api/storefront/application_helper.rb +15 -0
- data/app/helpers/workarea/api/storefront/checkouts_helper.rb +11 -0
- data/app/helpers/workarea/api/storefront/content_blocks_helper.rb +38 -0
- data/app/models/workarea/catalog/category.decorator +7 -0
- data/app/models/workarea/user/authentication_token.rb +33 -0
- data/app/models/workarea/user.decorator +8 -0
- data/app/view_models/workarea/api/storefront/search_suggestion_view_model.rb +21 -0
- data/app/views/workarea/api/storefront/accounts/_account.json.jbuilder +7 -0
- data/app/views/workarea/api/storefront/accounts/create.json.jbuilder +7 -0
- data/app/views/workarea/api/storefront/accounts/show.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/assets/show.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/authentication_tokens/_authentication_token.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/authentication_tokens/create.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/authentication_tokens/update.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/cart_items/item.json.jbuilder +9 -0
- data/app/views/workarea/api/storefront/carts/index.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/carts/show.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/categories/_category.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/categories/index.json.jbuilder +3 -0
- data/app/views/workarea/api/storefront/categories/show.json.jbuilder +30 -0
- data/app/views/workarea/api/storefront/checkouts/_shipping_options.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/checkouts/show.json.jbuilder +17 -0
- data/app/views/workarea/api/storefront/checkouts/steps/_addresses.json.jbuilder +19 -0
- data/app/views/workarea/api/storefront/checkouts/steps/_payment.json.jbuilder +9 -0
- data/app/views/workarea/api/storefront/checkouts/steps/_shipping.json.jbuilder +9 -0
- data/app/views/workarea/api/storefront/content_blocks/_block.json.jbuilder +7 -0
- data/app/views/workarea/api/storefront/email_signups/create.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/email_signups/show.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/facets/_range.json.jbuilder +8 -0
- data/app/views/workarea/api/storefront/facets/_terms.json.jbuilder +8 -0
- data/app/views/workarea/api/storefront/fulfillments/_fulfillment.json.jbuilder +18 -0
- data/app/views/workarea/api/storefront/menus/_menu.json.jbuilder +11 -0
- data/app/views/workarea/api/storefront/menus/index.json.jbuilder +3 -0
- data/app/views/workarea/api/storefront/menus/show.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/orders/_item.json.jbuilder +26 -0
- data/app/views/workarea/api/storefront/orders/_order.json.jbuilder +42 -0
- data/app/views/workarea/api/storefront/orders/index.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/orders/show.json.jbuilder +7 -0
- data/app/views/workarea/api/storefront/orders/tenders/_credit_card.json.jbuilder +6 -0
- data/app/views/workarea/api/storefront/orders/tenders/_store_credit.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/pages/show.json.jbuilder +16 -0
- data/app/views/workarea/api/storefront/products/_image_urls.json.jbuilder +5 -0
- data/app/views/workarea/api/storefront/products/_product.json.jbuilder +41 -0
- data/app/views/workarea/api/storefront/products/show.json.jbuilder +9 -0
- data/app/views/workarea/api/storefront/recent_views/show.json.jbuilder +8 -0
- data/app/views/workarea/api/storefront/recommendations/show.json.jbuilder +3 -0
- data/app/views/workarea/api/storefront/saved_addresses/_saved_address.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/saved_addresses/index.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/saved_addresses/show.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/saved_credit_cards/_card.json.jbuilder +9 -0
- data/app/views/workarea/api/storefront/saved_credit_cards/index.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/saved_credit_cards/show.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/searches/index.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/searches/show.json.jbuilder +19 -0
- data/app/views/workarea/api/storefront/shared/_address.json.jbuilder +12 -0
- data/app/views/workarea/api/storefront/shared/_pagination.json.jbuilder +11 -0
- data/app/views/workarea/api/storefront/system_content/show.json.jbuilder +12 -0
- data/app/views/workarea/api/storefront/taxons/_taxon.json.jbuilder +10 -0
- data/app/views/workarea/api/storefront/taxons/show.json.jbuilder +7 -0
- data/app/workers/workarea/remove_authentication_tokens_on_password_changes.rb +19 -0
- data/bin/rails +18 -0
- data/config/initializers/config.rb +2 -0
- data/config/locales/en.yml +13 -0
- data/config/routes.rb +41 -0
- data/lib/workarea/api/storefront/engine.rb +10 -0
- data/lib/workarea/api/storefront.rb +15 -0
- data/test/documentation/workarea/api/storefront/accounts_documentation_test.rb +70 -0
- data/test/documentation/workarea/api/storefront/analytics_documentation_test.rb +51 -0
- data/test/documentation/workarea/api/storefront/assets_documentation_test.rb +32 -0
- data/test/documentation/workarea/api/storefront/authentication_documentation_test.rb +84 -0
- data/test/documentation/workarea/api/storefront/cart_items_documentation_test.rb +104 -0
- data/test/documentation/workarea/api/storefront/carts_documentation_test.rb +121 -0
- data/test/documentation/workarea/api/storefront/categories_documentation_test.rb +90 -0
- data/test/documentation/workarea/api/storefront/checkouts_documentation_test.rb +142 -0
- data/test/documentation/workarea/api/storefront/contacts_documentation_test.rb +39 -0
- data/test/documentation/workarea/api/storefront/email_signups_documentation_test.rb +53 -0
- data/test/documentation/workarea/api/storefront/menus_documentation_test.rb +67 -0
- data/test/documentation/workarea/api/storefront/orders_documentation_test.rb +127 -0
- data/test/documentation/workarea/api/storefront/pages_documentation_test.rb +66 -0
- data/test/documentation/workarea/api/storefront/password_resets_documentation_test.rb +30 -0
- data/test/documentation/workarea/api/storefront/products_documentation_test.rb +64 -0
- data/test/documentation/workarea/api/storefront/recent_views_documentation_test.rb +116 -0
- data/test/documentation/workarea/api/storefront/recommendations_documentation_test.rb +68 -0
- data/test/documentation/workarea/api/storefront/saved_addresses_documentation_test.rb +129 -0
- data/test/documentation/workarea/api/storefront/saved_credit_cards_documentation_test.rb +129 -0
- data/test/documentation/workarea/api/storefront/searches_documentation_test.rb +88 -0
- data/test/documentation/workarea/api/storefront/system_content_documentation_test.rb +66 -0
- data/test/documentation/workarea/api/storefront/taxons_documentation_test.rb +37 -0
- data/test/documentation/workarea/api/storefront/validation_documentation_test.rb +81 -0
- data/test/dummy/Rakefile +7 -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/.keep +0 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/.keep +0 -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/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 +8 -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 +6 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +1 -0
- data/test/integration/workarea/api/storefront/accounts_integration_test.rb +49 -0
- data/test/integration/workarea/api/storefront/analytics_integration_test.rb +36 -0
- data/test/integration/workarea/api/storefront/assets_integration_test.rb +24 -0
- data/test/integration/workarea/api/storefront/authentication_integration_test.rb +50 -0
- data/test/integration/workarea/api/storefront/authentication_tokens_integration_test.rb +87 -0
- data/test/integration/workarea/api/storefront/cart_items_integration_test.rb +149 -0
- data/test/integration/workarea/api/storefront/carts_integration_test.rb +114 -0
- data/test/integration/workarea/api/storefront/categories_integration_test.rb +84 -0
- data/test/integration/workarea/api/storefront/checkouts_integration_test.rb +203 -0
- data/test/integration/workarea/api/storefront/contacts_integration_test.rb +28 -0
- data/test/integration/workarea/api/storefront/email_signups_integration_test.rb +35 -0
- data/test/integration/workarea/api/storefront/menus_integration_test.rb +53 -0
- data/test/integration/workarea/api/storefront/orders_integration_test.rb +115 -0
- data/test/integration/workarea/api/storefront/pages_integration_test.rb +57 -0
- data/test/integration/workarea/api/storefront/password_resets_integration_test.rb +20 -0
- data/test/integration/workarea/api/storefront/products_integration_test.rb +50 -0
- data/test/integration/workarea/api/storefront/recent_views_integration_test.rb +118 -0
- data/test/integration/workarea/api/storefront/recommendations_integration_test.rb +51 -0
- data/test/integration/workarea/api/storefront/saved_addresses_integration_test.rb +100 -0
- data/test/integration/workarea/api/storefront/saved_credit_cards_integration_test.rb +107 -0
- data/test/integration/workarea/api/storefront/searches_integration_test.rb +128 -0
- data/test/integration/workarea/api/storefront/system_content_integration_test.rb +35 -0
- data/test/integration/workarea/api/storefront/taxons_integration_test.rb +44 -0
- data/test/integration/workarea/api/storefront/user_carts_integration_test.rb +55 -0
- data/test/models/workarea/user/authentication_token_test.rb +30 -0
- data/test/support/authentication_test.rb +25 -0
- data/test/support/orders_test.rb +18 -0
- data/test/test_helper.rb +10 -0
- data/workarea-api-storefront.gemspec +18 -0
- metadata +277 -0
@@ -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
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class AccountsIntegrationTest < IntegrationTest
|
7
|
+
include AuthenticationTest
|
8
|
+
|
9
|
+
def test_show
|
10
|
+
set_current_user(create_user(first_name: 'Ben', last_name: 'Crouse'))
|
11
|
+
get storefront_api.account_path
|
12
|
+
|
13
|
+
results = JSON.parse(response.body)
|
14
|
+
assert_equal('Ben', results['first_name'])
|
15
|
+
assert_equal('Crouse', results['last_name'])
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_create
|
19
|
+
assert_difference 'User.count', 1 do
|
20
|
+
post storefront_api.account_path,
|
21
|
+
params: { email: 'bcrouse@weblinc.com', password: 'aP@ssw0rd!' }
|
22
|
+
end
|
23
|
+
|
24
|
+
assert(response.ok?)
|
25
|
+
results = JSON.parse(response.body)
|
26
|
+
|
27
|
+
assert_equal('bcrouse@weblinc.com', results['account']['email'])
|
28
|
+
assert(results['authentication_token'].present?)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_update
|
32
|
+
user = create_user(first_name: 'Ben', last_name: 'Crouse')
|
33
|
+
set_current_user(user)
|
34
|
+
|
35
|
+
put storefront_api.account_path,
|
36
|
+
params: { first_name: 'Bob', last_name: 'Clams' }
|
37
|
+
|
38
|
+
results = JSON.parse(response.body)
|
39
|
+
assert_equal('Bob', results['first_name'])
|
40
|
+
assert_equal('Clams', results['last_name'])
|
41
|
+
|
42
|
+
user.reload
|
43
|
+
assert_equal('Bob', user.first_name)
|
44
|
+
assert_equal('Clams', user.last_name)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class AnalyticsIntegrationTest < Workarea::IntegrationTest
|
7
|
+
def test_saving_category_view
|
8
|
+
post storefront_api.analytics_category_view_path(category_id: 'foo')
|
9
|
+
assert_equal(1, Metrics::CategoryByDay.first.views)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_saving_product_view
|
13
|
+
post storefront_api.analytics_product_view_path(product_id: 'foo')
|
14
|
+
assert_equal(1, Metrics::ProductByDay.first.views)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_saving_search
|
18
|
+
post storefront_api.analytics_search_path,
|
19
|
+
params: { q: 'foo', total_results: 5 }
|
20
|
+
|
21
|
+
insights = Metrics::SearchByDay.first
|
22
|
+
assert_equal(1, insights.searches)
|
23
|
+
assert_equal(5, insights.total_results)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_saving_search_abandonment
|
27
|
+
# Saving abandonment is deprecated, and this will be removed in v3.5
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_saving_filters
|
31
|
+
# Saving filters is deprecated, and this will be removed in v3.5
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class AssetsIntegrationTest < IntegrationTest
|
7
|
+
setup :set_asset
|
8
|
+
|
9
|
+
def set_asset
|
10
|
+
@asset = create_asset
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_shows_assets
|
14
|
+
get storefront_api.asset_path(@asset)
|
15
|
+
result = JSON.parse(response.body)
|
16
|
+
|
17
|
+
assert_equal(@asset.id.to_s, result['id'])
|
18
|
+
assert_equal(@asset.name, result['name'])
|
19
|
+
assert_includes(result['url'], @asset.optim.url)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class AuthenticationIntegrationTest < IntegrationTest
|
7
|
+
include AuthenticationTest
|
8
|
+
|
9
|
+
setup :set_user
|
10
|
+
|
11
|
+
def set_user
|
12
|
+
@user = create_user(password: 'p@assword!')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_authentication
|
16
|
+
get storefront_api.account_path
|
17
|
+
refute(response.ok?)
|
18
|
+
assert_equal(401, response.status)
|
19
|
+
|
20
|
+
post storefront_api.authentication_tokens_path,
|
21
|
+
params: { email: @user.email, password: 'p@assword!' }
|
22
|
+
|
23
|
+
token = JSON.parse(response.body)['token']
|
24
|
+
|
25
|
+
get storefront_api.account_path,
|
26
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(token) }
|
27
|
+
|
28
|
+
assert(response.ok?)
|
29
|
+
assert_equal(@user.id.to_s, JSON.parse(response.body)['id'])
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_expired_token
|
33
|
+
post storefront_api.authentication_tokens_path,
|
34
|
+
params: { email: @user.email, password: 'p@assword!' }
|
35
|
+
|
36
|
+
token = JSON.parse(response.body)['token']
|
37
|
+
|
38
|
+
expired = (Workarea.config.authentication_token_expiration + 1.day).from_now
|
39
|
+
travel_to expired
|
40
|
+
|
41
|
+
get storefront_api.account_path,
|
42
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(token) }
|
43
|
+
|
44
|
+
refute(response.ok?)
|
45
|
+
assert_equal(401, response.status)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class AuthenticationTokensIntegrationTest < IntegrationTest
|
7
|
+
include AuthenticationTest
|
8
|
+
|
9
|
+
setup :set_user
|
10
|
+
|
11
|
+
def set_user
|
12
|
+
@user = create_user(password: 'p@assword!')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_creating_tokens
|
16
|
+
post storefront_api.authentication_tokens_path,
|
17
|
+
params: { email: @user.email, password: 'p@assword!' }
|
18
|
+
|
19
|
+
assert(response.ok?)
|
20
|
+
results = JSON.parse(response.body)
|
21
|
+
auth = @user.authentication_tokens.first
|
22
|
+
assert_equal(auth.token, results['token'])
|
23
|
+
assert_equal(auth.expires_at, results['expires_at'])
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_wrong_password
|
27
|
+
post storefront_api.authentication_tokens_path,
|
28
|
+
params: { email: @user.email, password: 'wrongpassword' }
|
29
|
+
|
30
|
+
refute(response.ok?)
|
31
|
+
assert(JSON.parse(response.body)['problem'].present?)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_wrong_email
|
35
|
+
post storefront_api.authentication_tokens_path,
|
36
|
+
params: { email: 'foo@bar.com', password: 'p@assword!' }
|
37
|
+
|
38
|
+
refute(response.ok?)
|
39
|
+
assert(JSON.parse(response.body)['problem'].present?)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_expiring_auth_tokens_when_a_password_changes
|
43
|
+
post storefront_api.authentication_tokens_path,
|
44
|
+
params: { email: @user.email, password: 'p@assword!' }
|
45
|
+
|
46
|
+
token = JSON.parse(response.body)['token']
|
47
|
+
|
48
|
+
get storefront_api.account_path,
|
49
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(token) }
|
50
|
+
|
51
|
+
assert(response.ok?)
|
52
|
+
|
53
|
+
@user.update_attributes!(password: 'a_different_password')
|
54
|
+
|
55
|
+
get storefront_api.account_path,
|
56
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(token) }
|
57
|
+
|
58
|
+
refute(response.ok?)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_locking_login
|
62
|
+
Workarea.config.allowed_login_attempts.times do
|
63
|
+
post storefront_api.authentication_tokens_path,
|
64
|
+
params: { email: @user.email, password: 'wrongpassword' }
|
65
|
+
end
|
66
|
+
|
67
|
+
post storefront_api.authentication_tokens_path,
|
68
|
+
params: { email: @user.email, password: 'p@assword!' }
|
69
|
+
|
70
|
+
refute(response.ok?)
|
71
|
+
assert(JSON.parse(response.body)['problem'].present?)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_refreshing_token
|
75
|
+
post storefront_api.authentication_tokens_path,
|
76
|
+
params: { email: @user.email, password: 'p@assword!' }
|
77
|
+
|
78
|
+
token1 = JSON.parse(response.body)
|
79
|
+
patch storefront_api.authentication_tokens_path,
|
80
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(token1['token']) }
|
81
|
+
token2 = JSON.parse(response.body)
|
82
|
+
assert_operator(token2['expires_at'].to_datetime, :>, token1['expires_at'].to_datetime)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class CartItemsIntegrationTest < IntegrationTest
|
7
|
+
include OrdersTest
|
8
|
+
include Workarea::Storefront::CatalogCustomizationTestClass
|
9
|
+
|
10
|
+
setup :set_product, :set_order
|
11
|
+
|
12
|
+
def set_product
|
13
|
+
@product = create_product(
|
14
|
+
name: 'Test Product',
|
15
|
+
variants: [
|
16
|
+
{ sku: 'SKU1', regular: 5.to_m },
|
17
|
+
{ sku: 'SKU2', regular: 6.to_m }
|
18
|
+
]
|
19
|
+
)
|
20
|
+
|
21
|
+
create_inventory(id: 'SKU1', policy: 'standard', available: 2)
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_order
|
25
|
+
@order = create_order
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_create
|
29
|
+
post storefront_api.cart_items_path(@order),
|
30
|
+
params: {
|
31
|
+
product_id: @product.id,
|
32
|
+
sku: @product.skus.first,
|
33
|
+
quantity: 1
|
34
|
+
}
|
35
|
+
|
36
|
+
results = JSON.parse(response.body)
|
37
|
+
item = results['item']
|
38
|
+
order = results['order']
|
39
|
+
|
40
|
+
assert_equal(1, order['items'].count)
|
41
|
+
assert_equal(1, item['quantity'])
|
42
|
+
assert_equal(@product.id, item['product_id'])
|
43
|
+
assert_equal(@product.skus.first, item['sku'])
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_create_with_limited_inventory
|
47
|
+
post storefront_api.cart_items_path(@order),
|
48
|
+
params: {
|
49
|
+
product_id: @product.id,
|
50
|
+
sku: @product.skus.first,
|
51
|
+
quantity: 3
|
52
|
+
}
|
53
|
+
|
54
|
+
results = JSON.parse(response.body)
|
55
|
+
item = results['item']
|
56
|
+
order = results['order']
|
57
|
+
|
58
|
+
assert_equal(1, order['items'].count)
|
59
|
+
assert_equal(2, item['quantity'])
|
60
|
+
|
61
|
+
messages = JSON.parse(response.headers['X-Flash-Messages'])
|
62
|
+
assert(messages['error'].present?)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_create_with_inactive_sku
|
66
|
+
@product.variants.first.update_attributes!(active: false)
|
67
|
+
|
68
|
+
post storefront_api.cart_items_path(@order),
|
69
|
+
params: {
|
70
|
+
product_id: @product.id,
|
71
|
+
sku: @product.skus.first,
|
72
|
+
quantity: 1
|
73
|
+
}
|
74
|
+
|
75
|
+
results = JSON.parse(response.body)
|
76
|
+
assert_equal(0, results['order']['items'].count)
|
77
|
+
|
78
|
+
messages = JSON.parse(response.headers['X-Flash-Messages'])
|
79
|
+
assert(messages['info'].present?)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_create_with_customizations
|
83
|
+
@product.update_attributes(customizations: 'foo_cust')
|
84
|
+
|
85
|
+
post storefront_api.cart_items_path(@order),
|
86
|
+
params: {
|
87
|
+
product_id: @product.id,
|
88
|
+
sku: @product.skus.first,
|
89
|
+
quantity: 1,
|
90
|
+
foo: 'Test',
|
91
|
+
bar: 'This'
|
92
|
+
}
|
93
|
+
result = JSON.parse(response.body)
|
94
|
+
|
95
|
+
assert_equal(1, result['order']['items'].count)
|
96
|
+
assert_equal(
|
97
|
+
{ 'foo' => 'Test', 'bar' => 'This' },
|
98
|
+
result['item']['customizations']
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_create_with_invalid_customizations
|
103
|
+
@product.update_attributes(customizations: 'foo_cust')
|
104
|
+
|
105
|
+
post storefront_api.cart_items_path(@order),
|
106
|
+
params: {
|
107
|
+
product_id: @product.id,
|
108
|
+
sku: @product.skus.first,
|
109
|
+
quantity: 1,
|
110
|
+
foo: 'Test'
|
111
|
+
}
|
112
|
+
|
113
|
+
result = JSON.parse(response.body)
|
114
|
+
|
115
|
+
assert_equal(0, result['order']['items'].count)
|
116
|
+
|
117
|
+
messages = JSON.parse(response.headers['X-Flash-Messages'])
|
118
|
+
assert(messages['error'].present?)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_update
|
122
|
+
add_item(@order, product_id: @product.id, sku: 'SKU1', quantity: 1)
|
123
|
+
|
124
|
+
patch storefront_api.cart_item_path(@order, @order.items.first),
|
125
|
+
params: { sku: 'SKU2', quantity: 3 }
|
126
|
+
|
127
|
+
results = JSON.parse(response.body)
|
128
|
+
item = results['item']
|
129
|
+
order = results['order']
|
130
|
+
|
131
|
+
assert_equal(1, order['items'].count)
|
132
|
+
assert_equal(3, item['quantity'])
|
133
|
+
assert_equal(@product.id, item['product_id'])
|
134
|
+
assert_equal(@product.skus.last, item['sku'])
|
135
|
+
assert_equal(1800, order['pricing']['total_price']['cents'])
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_destroy
|
139
|
+
add_item(@order, product_id: @product.id, sku: 'SKU1', quantity: 1)
|
140
|
+
|
141
|
+
delete storefront_api.cart_item_path(@order, @order.items.first)
|
142
|
+
result = JSON.parse(response.body)
|
143
|
+
|
144
|
+
assert_equal(0, result['order']['items'].count)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class CartsIntegrationTest < IntegrationTest
|
7
|
+
include AuthenticationTest
|
8
|
+
include OrdersTest
|
9
|
+
|
10
|
+
setup :set_product, :set_order
|
11
|
+
|
12
|
+
def set_product
|
13
|
+
@product = create_product(
|
14
|
+
name: 'Test Product',
|
15
|
+
variants: [
|
16
|
+
{ sku: 'SKU1', regular: 5.to_m },
|
17
|
+
{ sku: 'SKU2', regular: 6.to_m }
|
18
|
+
]
|
19
|
+
)
|
20
|
+
|
21
|
+
create_inventory(id: 'SKU1', policy: 'standard', available: 2)
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_order
|
25
|
+
@order = create_order
|
26
|
+
add_item(@order, product_id: @product.id, sku: 'SKU1', quantity: 2)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_new_cart
|
30
|
+
post storefront_api.carts_path
|
31
|
+
result = JSON.parse(response.body)
|
32
|
+
|
33
|
+
assert(result['id'].present?)
|
34
|
+
refute(result['user_id'].present?)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_show
|
38
|
+
get storefront_api.cart_path(@order)
|
39
|
+
result = JSON.parse(response.body)
|
40
|
+
|
41
|
+
assert_equal(@order.id, result['id'])
|
42
|
+
assert_equal(1, result['items'].count)
|
43
|
+
assert_equal(2, result['items'].first['quantity'])
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_invalid_user
|
47
|
+
user = create_user
|
48
|
+
auth = user.authentication_tokens.create!
|
49
|
+
|
50
|
+
# don't allow authenticated users to grab guest checkouts
|
51
|
+
get storefront_api.cart_path(@order),
|
52
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(auth.token) }
|
53
|
+
|
54
|
+
refute(response.ok?)
|
55
|
+
assert_equal(404, response.status)
|
56
|
+
|
57
|
+
# don't allow users to grab other users's checkouts
|
58
|
+
other_user = create_user
|
59
|
+
@order.update_attributes!(user_id: other_user.id)
|
60
|
+
|
61
|
+
get storefront_api.cart_path(@order),
|
62
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(auth.token) }
|
63
|
+
|
64
|
+
refute(response.ok?)
|
65
|
+
assert_equal(404, response.status)
|
66
|
+
|
67
|
+
# don't allow anonymous users to grab other users's checkouts
|
68
|
+
get storefront_api.cart_path(@order)
|
69
|
+
refute(response.ok?)
|
70
|
+
assert_equal(401, response.status)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_check_inventory
|
74
|
+
add_item(@order, product_id: @product.id, sku: 'SKU1', quantity: 2)
|
75
|
+
|
76
|
+
get storefront_api.cart_path(@order)
|
77
|
+
result = JSON.parse(response.body)
|
78
|
+
|
79
|
+
messages = JSON.parse(response.headers['X-Flash-Messages'])
|
80
|
+
assert(messages['error'].present?)
|
81
|
+
|
82
|
+
assert_equal(2, result['items'].first['quantity'])
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_purchasable_items
|
86
|
+
@product.variants.first.update_attributes!(active: false)
|
87
|
+
|
88
|
+
get storefront_api.cart_path(@order)
|
89
|
+
result = JSON.parse(response.body)
|
90
|
+
|
91
|
+
messages = JSON.parse(response.headers['X-Flash-Messages'])
|
92
|
+
assert(messages['info'].present?)
|
93
|
+
|
94
|
+
assert(result['items'].blank?)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_add_promo_code
|
98
|
+
create_order_total_discount(promo_codes: %w(TESTCODE))
|
99
|
+
|
100
|
+
post storefront_api.add_promo_code_to_cart_path(@order),
|
101
|
+
params: { promo_code: 'TESTCODE' }
|
102
|
+
result = JSON.parse(response.body)
|
103
|
+
|
104
|
+
assert_equal(@order.id, result['id'])
|
105
|
+
assert_equal(%w(TESTCODE), result['promo_codes'])
|
106
|
+
assert_equal(
|
107
|
+
'Order Total Discount',
|
108
|
+
result['pricing']['price_adjustments'].first['description']
|
109
|
+
)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|