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,118 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class RecentViewsIntegrationTest < IntegrationTest
|
7
|
+
include AuthenticationTest
|
8
|
+
|
9
|
+
setup :set_product
|
10
|
+
setup :set_category
|
11
|
+
|
12
|
+
def set_product
|
13
|
+
@product = create_product
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_category
|
17
|
+
@category = create_category
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_showing_recent_views_with_authentication
|
21
|
+
user = create_user(first_name: 'Ben', last_name: 'Crouse')
|
22
|
+
set_current_user(user)
|
23
|
+
|
24
|
+
activity = create_user_activity(
|
25
|
+
id: user.id,
|
26
|
+
product_ids: [@product.id],
|
27
|
+
category_ids: [@category.id],
|
28
|
+
searches: ['foo']
|
29
|
+
)
|
30
|
+
|
31
|
+
get storefront_api.recent_views_path
|
32
|
+
|
33
|
+
assert(response.ok?)
|
34
|
+
result = JSON.parse(response.body)
|
35
|
+
|
36
|
+
assert_equal(activity.id, result['id'])
|
37
|
+
assert_equal(@product.id, result['products'].first['id'])
|
38
|
+
assert_equal(@category.id.to_s, result['categories'].first['id'])
|
39
|
+
assert_includes(result['searches'], 'foo')
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_adding_recent_views_for_authentication
|
43
|
+
user = create_user(first_name: 'Ben', last_name: 'Crouse')
|
44
|
+
set_current_user(user)
|
45
|
+
patch storefront_api.recent_views_path,
|
46
|
+
params: {
|
47
|
+
product_id: @product.id,
|
48
|
+
category_id: @category.id,
|
49
|
+
search: 'foo'
|
50
|
+
}
|
51
|
+
|
52
|
+
assert(response.ok?)
|
53
|
+
|
54
|
+
user_activity = Recommendation::UserActivity.first
|
55
|
+
assert_equal(user.id.to_s, user_activity.id.to_s)
|
56
|
+
assert_includes(user_activity.product_ids, @product.id)
|
57
|
+
assert_includes(user_activity.category_ids, @category.id.to_s)
|
58
|
+
assert_includes(user_activity.searches, 'foo')
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_showing_recent_views_with_session_id
|
62
|
+
activity = create_user_activity(
|
63
|
+
product_ids: [@product.id],
|
64
|
+
category_ids: [@category.id],
|
65
|
+
searches: ['bar']
|
66
|
+
)
|
67
|
+
|
68
|
+
get storefront_api.recent_views_path,
|
69
|
+
params: { session_id: activity.id }
|
70
|
+
|
71
|
+
assert(response.ok?)
|
72
|
+
result = JSON.parse(response.body)
|
73
|
+
|
74
|
+
assert_equal(activity.id, result['id'])
|
75
|
+
assert_equal(@product.id, result['products'].first['id'])
|
76
|
+
assert_equal(@category.id.to_s, result['categories'].first['id'])
|
77
|
+
assert_includes(result['searches'], 'bar')
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_adding_recent_views_for_session_id
|
81
|
+
activity = create_user_activity(
|
82
|
+
product_ids: [@product.id],
|
83
|
+
category_ids: [@category.id],
|
84
|
+
searches: ['bar']
|
85
|
+
)
|
86
|
+
|
87
|
+
patch storefront_api.recent_views_path,
|
88
|
+
params: {
|
89
|
+
session_id: activity.id,
|
90
|
+
product_id: @product.id,
|
91
|
+
category_id: @category.id,
|
92
|
+
search: 'bar'
|
93
|
+
}
|
94
|
+
|
95
|
+
assert(response.ok?)
|
96
|
+
|
97
|
+
user_activity = Recommendation::UserActivity.first
|
98
|
+
assert_equal(activity.id, user_activity.id)
|
99
|
+
assert_includes(user_activity.product_ids, @product.id)
|
100
|
+
assert_includes(user_activity.category_ids, @category.id.to_s)
|
101
|
+
assert_includes(user_activity.searches, 'bar')
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_adding_without_id
|
105
|
+
patch storefront_api.recent_views_path,
|
106
|
+
params: {
|
107
|
+
product_id: @product.id,
|
108
|
+
category_id: @category.id,
|
109
|
+
search: 'search'
|
110
|
+
}
|
111
|
+
|
112
|
+
refute(response.ok?)
|
113
|
+
assert_equal(0, Recommendation::UserActivity.count)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class RecommendationsIntegrationTest < IntegrationTest
|
7
|
+
include AuthenticationTest
|
8
|
+
|
9
|
+
setup :set_auth
|
10
|
+
setup :set_products
|
11
|
+
setup :set_user_activity
|
12
|
+
|
13
|
+
def set_auth
|
14
|
+
user = create_user
|
15
|
+
@auth = user.authentication_tokens.create!
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_products
|
19
|
+
10.times { create_product }
|
20
|
+
|
21
|
+
top_products = Catalog::Product.sample(10).map { |p| { 'product_id' => p.id } }
|
22
|
+
create_top_products(results: top_products)
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_user_activity
|
26
|
+
@activity = create_user_activity
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_showing_recommendations_with_authentication
|
30
|
+
get storefront_api.recommendations_path,
|
31
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
32
|
+
result = JSON.parse(response.body)
|
33
|
+
|
34
|
+
assert(response.ok?)
|
35
|
+
assert_equal(6, result['products'].count)
|
36
|
+
refute_empty(result['products'].first['name'])
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_showing_recommendations_with_session_id
|
40
|
+
get storefront_api.recommendations_path,
|
41
|
+
params: { session_id: @activity.id }
|
42
|
+
result = JSON.parse(response.body)
|
43
|
+
|
44
|
+
assert(response.ok?)
|
45
|
+
assert_equal(6, result['products'].count)
|
46
|
+
refute_empty(result['products'].first['name'])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class SavedAddressesIntegrationTest < IntegrationTest
|
7
|
+
include AuthenticationTest
|
8
|
+
|
9
|
+
setup :set_user
|
10
|
+
setup :set_address
|
11
|
+
|
12
|
+
def set_user
|
13
|
+
@user = create_user(first_name: 'Ben', last_name: 'Crouse')
|
14
|
+
set_current_user(@user)
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_address
|
18
|
+
@address = @user.addresses.create!(
|
19
|
+
first_name: 'Ben',
|
20
|
+
last_name: 'Crouse',
|
21
|
+
street: '12 N. 3rd St.',
|
22
|
+
city: 'Philadelphia',
|
23
|
+
region: 'PA',
|
24
|
+
country: 'US',
|
25
|
+
postal_code: '19106',
|
26
|
+
phone_number: '2159251800'
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_index
|
31
|
+
get storefront_api.saved_addresses_path
|
32
|
+
result = JSON.parse(response.body)
|
33
|
+
|
34
|
+
assert_equal(@user.id.to_s, result['user_id'])
|
35
|
+
assert_equal(1, result['addresses'].count)
|
36
|
+
assert_equal(@address.id.to_s, result['addresses'].last['id'])
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_show
|
40
|
+
get storefront_api.saved_address_path(@address)
|
41
|
+
result = JSON.parse(response.body)
|
42
|
+
|
43
|
+
assert_equal(@user.id.to_s, result['user_id'])
|
44
|
+
|
45
|
+
assert_equal(@address.id.to_s, result['id'])
|
46
|
+
assert_equal(@address.first_name, result['first_name'])
|
47
|
+
assert_equal(@address.last_name, result['last_name'])
|
48
|
+
assert_equal(@address.street, result['street'])
|
49
|
+
assert_equal(@address.city, result['city'])
|
50
|
+
assert_equal(@address.country.alpha2, result['country'])
|
51
|
+
assert_equal(@address.region, result['region'])
|
52
|
+
assert_equal(@address.postal_code, result['postal_code'])
|
53
|
+
assert_equal(@address.phone_number, result['phone_number'])
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_create
|
57
|
+
post storefront_api.saved_addresses_path,
|
58
|
+
params: {
|
59
|
+
first_name: 'Ben',
|
60
|
+
last_name: 'Crouse',
|
61
|
+
street: '22 S. 3rd St.',
|
62
|
+
street_2: 'Second Floor',
|
63
|
+
city: 'Philadelphia',
|
64
|
+
region: 'PA',
|
65
|
+
country: 'US',
|
66
|
+
postal_code: '19106',
|
67
|
+
phone_number: '2159251800'
|
68
|
+
}
|
69
|
+
|
70
|
+
assert(response.ok?)
|
71
|
+
assert(2, @user.reload.addresses.count)
|
72
|
+
|
73
|
+
address = @user.reload.addresses.last
|
74
|
+
assert_equal('22 S. 3rd St.', address.street)
|
75
|
+
assert_equal('Second Floor', address.street_2)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_update
|
79
|
+
patch storefront_api.saved_address_path(@address),
|
80
|
+
params: {
|
81
|
+
street: '22 S. 3rd St.',
|
82
|
+
street_2: 'Second Floor'
|
83
|
+
}
|
84
|
+
|
85
|
+
assert(response.ok?)
|
86
|
+
assert(1, @user.reload.addresses.count)
|
87
|
+
|
88
|
+
address = @user.reload.addresses.first
|
89
|
+
assert_equal('22 S. 3rd St.', address.street)
|
90
|
+
assert_equal('Second Floor', address.street_2)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_destroy
|
94
|
+
delete storefront_api.saved_address_path(@address)
|
95
|
+
assert_equal(0, @user.reload.addresses.count)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class SavedCreditCardsIntegrationTest < IntegrationTest
|
7
|
+
include AuthenticationTest
|
8
|
+
|
9
|
+
setup :set_user
|
10
|
+
setup :set_payment_profile
|
11
|
+
setup :set_credit_card
|
12
|
+
|
13
|
+
def set_user
|
14
|
+
@user = create_user(first_name: 'Ben', last_name: 'Crouse')
|
15
|
+
set_current_user(@user)
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_payment_profile
|
19
|
+
@payment_profile = Payment::Profile.lookup(
|
20
|
+
PaymentReference.new(@user)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_credit_card
|
25
|
+
@credit_card = @payment_profile.credit_cards.create!(
|
26
|
+
number: '1',
|
27
|
+
first_name: 'Ben',
|
28
|
+
last_name: 'Crouse',
|
29
|
+
month: '1',
|
30
|
+
year: (Time.now.year + 1).to_s,
|
31
|
+
cvv: '999'
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_index
|
36
|
+
get storefront_api.saved_credit_cards_path
|
37
|
+
result = JSON.parse(response.body)
|
38
|
+
|
39
|
+
assert_equal(@user.id.to_s, result['user_id'])
|
40
|
+
assert_equal(1, result['credit_cards'].count)
|
41
|
+
assert_equal(@credit_card.id.to_s, result['credit_cards'].last['id'])
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_show
|
45
|
+
get storefront_api.saved_credit_card_path(@credit_card)
|
46
|
+
result = JSON.parse(response.body)
|
47
|
+
|
48
|
+
assert_equal(@user.id.to_s, result['user_id'])
|
49
|
+
|
50
|
+
assert_equal(@credit_card.id.to_s, result['id'])
|
51
|
+
assert_equal(@credit_card.first_name, result['first_name'])
|
52
|
+
assert_equal(@credit_card.last_name, result['last_name'])
|
53
|
+
assert_equal(@credit_card.display_number, result['display_number'])
|
54
|
+
assert_equal(@credit_card.issuer, result['issuer'])
|
55
|
+
assert_equal(@credit_card.month, result['month'])
|
56
|
+
assert_equal(@credit_card.year, result['year'])
|
57
|
+
assert_equal(@credit_card.default, result['default'])
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_create
|
61
|
+
post storefront_api.saved_credit_cards_path,
|
62
|
+
params: {
|
63
|
+
number: '4111111111111111',
|
64
|
+
first_name: 'Ben',
|
65
|
+
last_name: 'Crouse',
|
66
|
+
month: '5',
|
67
|
+
year: (Time.now.year + 1).to_s,
|
68
|
+
cvv: '123'
|
69
|
+
}
|
70
|
+
|
71
|
+
assert(response.ok?)
|
72
|
+
assert(2, @payment_profile.reload.credit_cards.count)
|
73
|
+
|
74
|
+
credit_card = @payment_profile.reload.credit_cards.last
|
75
|
+
assert_equal(5, credit_card.month)
|
76
|
+
assert_equal(
|
77
|
+
ActiveMerchant::Billing::CreditCard.mask('4111111111111111'),
|
78
|
+
credit_card.display_number
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_update
|
83
|
+
year = Time.now.year + 2
|
84
|
+
|
85
|
+
patch storefront_api.saved_credit_card_path(@credit_card),
|
86
|
+
params: {
|
87
|
+
month: '5',
|
88
|
+
year: year.to_s,
|
89
|
+
cvv: '123'
|
90
|
+
}
|
91
|
+
|
92
|
+
assert(response.ok?)
|
93
|
+
assert(1, @payment_profile.reload.credit_cards.count)
|
94
|
+
|
95
|
+
credit_card = @payment_profile.reload.credit_cards.first
|
96
|
+
assert_equal(5, credit_card.month)
|
97
|
+
assert_equal(year, credit_card.year)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_destroy
|
101
|
+
delete storefront_api.saved_credit_card_path(@credit_card)
|
102
|
+
assert_equal(0, @payment_profile.reload.credit_cards.count)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class SearchesIntegrationTest < IntegrationTest
|
7
|
+
def test_showing_search_autocomplete
|
8
|
+
create_product(name: 'Foo')
|
9
|
+
create_category(name: 'Foo Category')
|
10
|
+
create_page(name: 'Foo Page')
|
11
|
+
|
12
|
+
Metrics::SearchByDay.save_search('foo', 3)
|
13
|
+
travel_to 1.weeks.from_now
|
14
|
+
GenerateInsights.generate_all!
|
15
|
+
BulkIndexSearches.perform
|
16
|
+
|
17
|
+
get storefront_api.searches_path(q: 'foo')
|
18
|
+
results = JSON.parse(response.body)['results']
|
19
|
+
assert_equal(4, results.length)
|
20
|
+
|
21
|
+
search = results.detect { |r| r['type'] == 'Searches' }
|
22
|
+
assert(search.present?)
|
23
|
+
assert_equal('foo', search['value'])
|
24
|
+
assert_equal(storefront_api.search_path(q: 'foo'), search['url'])
|
25
|
+
|
26
|
+
product = results.detect { |r| r['type'] == 'Products' }
|
27
|
+
assert(product.present?)
|
28
|
+
assert_equal('Foo', product['value'])
|
29
|
+
assert_match(/product_images/, product['image'])
|
30
|
+
assert_equal(storefront_api.product_path('foo'), product['url'])
|
31
|
+
|
32
|
+
category = results.detect { |r| r['type'] == 'Categories' }
|
33
|
+
assert(category.present?)
|
34
|
+
assert_equal('Foo Category', category['value'])
|
35
|
+
assert_equal(storefront_api.category_path('foo-category'), category['url'])
|
36
|
+
|
37
|
+
page = results.detect { |r| r['type'] == 'Pages' }
|
38
|
+
assert(page.present?)
|
39
|
+
assert_equal('Foo Page', page['value'])
|
40
|
+
assert_equal(storefront_api.page_path('foo-page'), page['url'])
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_shows_search_results
|
44
|
+
Search::Settings.current.update_attributes!(terms_facets: %w(Color Size))
|
45
|
+
create_product(
|
46
|
+
id: 'PRODUCT1',
|
47
|
+
name: 'Pretty Nice Shirt',
|
48
|
+
filters: { 'Size' => %w[Small Medium Large], 'Color' => 'Blue' },
|
49
|
+
variants: [{ sku: 'SKU', regular: 35.to_m }],
|
50
|
+
images: [{ image: product_image_file, option: 'Blue' }]
|
51
|
+
)
|
52
|
+
|
53
|
+
create_product(
|
54
|
+
id: 'PRODUCT2',
|
55
|
+
name: 'Great Pants',
|
56
|
+
filters: { 'Size' => %w[Small Medium Large], 'Color' => 'Brown' },
|
57
|
+
variants: [{ sku: 'SKU', regular: 50.to_m }],
|
58
|
+
images: [{ image: product_image_file, option: 'Brown' }]
|
59
|
+
)
|
60
|
+
|
61
|
+
content = Content.for('search')
|
62
|
+
content.blocks.create!(
|
63
|
+
area: :results,
|
64
|
+
type: :text,
|
65
|
+
data: { text: 'global search test content' }
|
66
|
+
)
|
67
|
+
|
68
|
+
get storefront_api.search_path(q: 'large')
|
69
|
+
result = JSON.parse(response.body)
|
70
|
+
|
71
|
+
assert(result['query_string'].present?)
|
72
|
+
assert(result.key?('message'))
|
73
|
+
assert(result.key?('redirect'))
|
74
|
+
|
75
|
+
content_blocks = result['content_blocks']
|
76
|
+
assert_equal(1, content_blocks.count)
|
77
|
+
|
78
|
+
assert_equal(2, result['total_results'])
|
79
|
+
assert_equal(2, result['facets'].count)
|
80
|
+
|
81
|
+
products = result['products']
|
82
|
+
assert_equal(2, products.count)
|
83
|
+
assert_includes(products.map { |r| r['id'] }, 'PRODUCT1')
|
84
|
+
assert_includes(products.map { |r| r['id'] }, 'PRODUCT2')
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_shows_no_search_results
|
88
|
+
Search::Settings.current.update_attributes!(terms_facets: %w(Color Size))
|
89
|
+
create_product(
|
90
|
+
id: 'PRODUCT1',
|
91
|
+
name: 'Pretty Nice Shirt',
|
92
|
+
filters: { 'Size' => %w[Small Medium Large], 'Color' => 'Blue' },
|
93
|
+
variants: [{ sku: 'SKU', regular: 35.to_m }],
|
94
|
+
images: [{ image: product_image_file, option: 'Blue' }]
|
95
|
+
)
|
96
|
+
|
97
|
+
content = Content.for('search')
|
98
|
+
content.blocks.create!(
|
99
|
+
area: :results,
|
100
|
+
type: :text,
|
101
|
+
data: { text: 'global search test content' }
|
102
|
+
)
|
103
|
+
content.blocks.create!(
|
104
|
+
area: :no_results,
|
105
|
+
type: :text,
|
106
|
+
data: { text: 'no results test content' }
|
107
|
+
)
|
108
|
+
|
109
|
+
get storefront_api.search_path(q: 'grand')
|
110
|
+
result = JSON.parse(response.body)
|
111
|
+
|
112
|
+
assert(result['query_string'].present?)
|
113
|
+
assert(result.key?('message'))
|
114
|
+
assert(result.key?('redirect'))
|
115
|
+
|
116
|
+
content_blocks = result['content_blocks']
|
117
|
+
assert_equal(2, content_blocks.count)
|
118
|
+
|
119
|
+
assert_equal(0, result['total_results'])
|
120
|
+
assert_equal(0, result['facets'].count)
|
121
|
+
|
122
|
+
products = result['products']
|
123
|
+
assert_equal(0, products.count)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class SystemContentIntegrationTest < IntegrationTest
|
7
|
+
include Workarea::Storefront::IntegrationTest
|
8
|
+
|
9
|
+
setup :set_content
|
10
|
+
|
11
|
+
def set_content
|
12
|
+
@content = Content.for('Layout')
|
13
|
+
@content.blocks.create!(
|
14
|
+
area: :header_promo,
|
15
|
+
type: :text,
|
16
|
+
data: { text: 'text' }
|
17
|
+
)
|
18
|
+
@content.blocks.create!(
|
19
|
+
area: :footer_navigation,
|
20
|
+
type: :text,
|
21
|
+
data: { text: 'text' }
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_shows_categories
|
26
|
+
get storefront_api.system_content_path('layout')
|
27
|
+
result = JSON.parse(response.body)
|
28
|
+
|
29
|
+
assert_equal(@content.id.to_s, result['id'])
|
30
|
+
assert_equal(2, result['content_blocks'].count)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class TaxonsIntegrationTest < IntegrationTest
|
7
|
+
setup :set_taxons
|
8
|
+
|
9
|
+
def set_taxons
|
10
|
+
@taxon = create_taxon(
|
11
|
+
name: 'Mens',
|
12
|
+
url: 'http://example.com/pages/mens'
|
13
|
+
)
|
14
|
+
|
15
|
+
@taxon.children.create!(name: 'Sale')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_show
|
19
|
+
get storefront_api.taxon_path(@taxon)
|
20
|
+
result = JSON.parse(response.body)
|
21
|
+
|
22
|
+
assert_equal(@taxon.id.to_s, result['taxon']['id'])
|
23
|
+
assert_equal(
|
24
|
+
'http://example.com/pages/mens',
|
25
|
+
result['taxon']['navigable_url']
|
26
|
+
)
|
27
|
+
|
28
|
+
assert_equal(1, result['children'].size)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_inactive_taxon
|
32
|
+
@taxon.update_attributes!(
|
33
|
+
url: nil,
|
34
|
+
navigable: create_page(active: false)
|
35
|
+
)
|
36
|
+
|
37
|
+
get storefront_api.taxon_path(@taxon)
|
38
|
+
refute(response.ok?)
|
39
|
+
assert_equal(404, response.status)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class UserCartsIntegrationTest < IntegrationTest
|
7
|
+
include AuthenticationTest
|
8
|
+
include OrdersTest
|
9
|
+
|
10
|
+
setup :set_user, :set_product, :set_order
|
11
|
+
|
12
|
+
def set_user
|
13
|
+
@user = create_user(first_name: 'Ben', last_name: 'Crouse')
|
14
|
+
set_current_user(@user)
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_product
|
18
|
+
@product = create_product(
|
19
|
+
name: 'Test Product',
|
20
|
+
variants: [
|
21
|
+
{ sku: 'SKU1', regular: 5.to_m },
|
22
|
+
{ sku: 'SKU2', regular: 6.to_m }
|
23
|
+
]
|
24
|
+
)
|
25
|
+
|
26
|
+
create_inventory(id: 'SKU1', policy: 'standard', available: 2)
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_order
|
30
|
+
@order = create_order(user_id: @user.id.to_s, email: @user.email)
|
31
|
+
add_item(@order, product_id: @product.id, sku: 'SKU1', quantity: 2)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_index_user_carts
|
35
|
+
get storefront_api.carts_path
|
36
|
+
result = JSON.parse(response.body)
|
37
|
+
|
38
|
+
assert_equal(@user.id.to_s, result['user_id'])
|
39
|
+
assert_equal(1, result['orders'].count)
|
40
|
+
|
41
|
+
order = result['orders'].first
|
42
|
+
assert_equal(@order.id, order['id'])
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_new_cart_for_user
|
46
|
+
post storefront_api.carts_path
|
47
|
+
result = JSON.parse(response.body)
|
48
|
+
|
49
|
+
assert(result['id'].present?)
|
50
|
+
assert(result['user_id'].present?)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class User
|
5
|
+
class AuthenticationTokenTestCase < TestCase
|
6
|
+
setup :set_user
|
7
|
+
|
8
|
+
def set_user
|
9
|
+
@user = create_user
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_authenticate
|
13
|
+
assert(AuthenticationToken.authenticate('asflkjasdflkjas').blank?)
|
14
|
+
|
15
|
+
auth = AuthenticationToken.create!(user: @user)
|
16
|
+
assert_equal(auth, AuthenticationToken.authenticate(auth.token))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_expired
|
20
|
+
auth = AuthenticationToken.create!(user: @user)
|
21
|
+
refute(auth.expired?)
|
22
|
+
|
23
|
+
expired = (Workarea.config.authentication_token_expiration + 1.day).from_now
|
24
|
+
travel_to expired
|
25
|
+
|
26
|
+
assert(auth.expired?)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
module AuthenticationTest
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
delegate :encode_credentials, to: ActionController::HttpAuthentication::Token
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_current_user(user)
|
12
|
+
Workarea::Api::Storefront::ApplicationController.subclasses.each do |klass|
|
13
|
+
if klass.method_defined?(:current_user)
|
14
|
+
klass.any_instance.stubs(:current_user).returns(user)
|
15
|
+
end
|
16
|
+
|
17
|
+
if klass.method_defined?(:authentication?)
|
18
|
+
klass.any_instance.stubs(:authentication?).returns(true)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|