workarea-api-storefront 4.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.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,51 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'workarea/api/documentation_test'
|
|
3
|
+
|
|
4
|
+
module Workarea
|
|
5
|
+
module Api
|
|
6
|
+
module Storefront
|
|
7
|
+
class AnalyticsDocumentationTest < DocumentationTest
|
|
8
|
+
resource 'Analytics'
|
|
9
|
+
|
|
10
|
+
def test_and_document_saving_a_category_view
|
|
11
|
+
description 'saving a category view'
|
|
12
|
+
route storefront_api.analytics_category_view_path(category_id: ':category_id')
|
|
13
|
+
explanation 'saving a category view will be reflected in admin reports'
|
|
14
|
+
|
|
15
|
+
record_request do
|
|
16
|
+
post storefront_api.analytics_category_view_path(category_id: '12345')
|
|
17
|
+
assert_equal(200, response.status)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_and_document_saving_a_product_view
|
|
22
|
+
description 'saving a product view'
|
|
23
|
+
route storefront_api.analytics_product_view_path(product_id: ':product_id')
|
|
24
|
+
explanation 'saving a product view will be reflected in admin reports'
|
|
25
|
+
|
|
26
|
+
record_request do
|
|
27
|
+
post storefront_api.analytics_product_view_path(product_id: '12345')
|
|
28
|
+
assert_equal(200, response.status)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_and_document_saving_a_search
|
|
33
|
+
description 'Saving a search'
|
|
34
|
+
route storefront_api.analytics_search_path
|
|
35
|
+
explanation <<-EOS
|
|
36
|
+
Saving a search will be reflected in admin reports. This is intended
|
|
37
|
+
to be called once per search performed by a customer.
|
|
38
|
+
EOS
|
|
39
|
+
|
|
40
|
+
record_request do
|
|
41
|
+
post storefront_api.analytics_search_path,
|
|
42
|
+
as: :json,
|
|
43
|
+
params: { q: 'foo', total_results: 5 }
|
|
44
|
+
|
|
45
|
+
assert_equal(200, response.status)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'workarea/api/documentation_test'
|
|
3
|
+
|
|
4
|
+
module Workarea
|
|
5
|
+
module Api
|
|
6
|
+
module Storefront
|
|
7
|
+
class AssetsDocumentationTest < DocumentationTest
|
|
8
|
+
resource 'Assets'
|
|
9
|
+
|
|
10
|
+
setup :set_asset
|
|
11
|
+
|
|
12
|
+
def set_asset
|
|
13
|
+
@asset = create_asset(name: 'Summer Sale Callout')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_and_document_showing_assets
|
|
17
|
+
description 'Showing an asset'
|
|
18
|
+
route storefront_api.asset_path(':id')
|
|
19
|
+
explanation <<-EOS
|
|
20
|
+
Use this endpoint to look up assets stored in Workarea. Often times
|
|
21
|
+
these will be referenced in content blocks.
|
|
22
|
+
EOS
|
|
23
|
+
|
|
24
|
+
record_request do
|
|
25
|
+
get storefront_api.asset_path(@asset)
|
|
26
|
+
assert_equal(200, response.status)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'workarea/api/documentation_test'
|
|
3
|
+
|
|
4
|
+
module Workarea
|
|
5
|
+
module Api
|
|
6
|
+
module Storefront
|
|
7
|
+
class AuthenticationDocumentationTest < DocumentationTest
|
|
8
|
+
include AuthenticationTest
|
|
9
|
+
|
|
10
|
+
resource 'Authentication'
|
|
11
|
+
|
|
12
|
+
setup :set_user
|
|
13
|
+
|
|
14
|
+
def set_user
|
|
15
|
+
@user = create_user(password: 'p@assword!')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def distance_of_time_in_words(*args)
|
|
19
|
+
ApplicationController.helpers.distance_of_time_in_words(*args)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_creating_an_authentication_token
|
|
23
|
+
description 'Creating an authentication token'
|
|
24
|
+
route storefront_api.authentication_tokens_path
|
|
25
|
+
explanation <<-EOS
|
|
26
|
+
Creating an authentication token is the first step in user
|
|
27
|
+
authentication. You will use this token to authenticate requests on
|
|
28
|
+
behalf of the user going forward. To get a token you can use to
|
|
29
|
+
authenticate an account, use this endpoint. You'll need the email
|
|
30
|
+
and password from the user, and we'll issue a token that can be used
|
|
31
|
+
to authenticate further requests for that customer. This token will
|
|
32
|
+
expire after #{distance_of_time_in_words(Workarea.config.authentication_token_expiration)}.
|
|
33
|
+
Tokens are also invalidated when a user changes their password. See
|
|
34
|
+
the "using an authentication token" example for how to use an
|
|
35
|
+
authentication token.
|
|
36
|
+
EOS
|
|
37
|
+
|
|
38
|
+
record_request do
|
|
39
|
+
post storefront_api.authentication_tokens_path,
|
|
40
|
+
params: { email: @user.email, password: 'p@assword!' },
|
|
41
|
+
as: :json
|
|
42
|
+
|
|
43
|
+
assert(response.ok?)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_using_an_authentication_token
|
|
48
|
+
description 'Using an authentication token'
|
|
49
|
+
route storefront_api.account_path
|
|
50
|
+
explanation <<-EOS
|
|
51
|
+
After obtaining an authentication token you can use it to request
|
|
52
|
+
authenticated endpoints by including it in the Authorization header
|
|
53
|
+
on the request, as demonstrated in this example.
|
|
54
|
+
EOS
|
|
55
|
+
|
|
56
|
+
auth = @user.authentication_tokens.create!
|
|
57
|
+
|
|
58
|
+
record_request do
|
|
59
|
+
get storefront_api.account_path,
|
|
60
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(auth.token) }
|
|
61
|
+
|
|
62
|
+
assert(response.ok?)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_refreshing_an_authentication_token
|
|
67
|
+
description 'Refreshing an authentication token'
|
|
68
|
+
route storefront_api.authentication_tokens_path
|
|
69
|
+
explanation <<-EOS
|
|
70
|
+
Refreshing an authentication token extends its expiration so that it
|
|
71
|
+
can continue to be used.
|
|
72
|
+
EOS
|
|
73
|
+
|
|
74
|
+
auth = @user.authentication_tokens.create!
|
|
75
|
+
|
|
76
|
+
record_request do
|
|
77
|
+
patch storefront_api.authentication_tokens_path,
|
|
78
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(auth.token) }
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'workarea/api/documentation_test'
|
|
3
|
+
|
|
4
|
+
module Workarea
|
|
5
|
+
module Api
|
|
6
|
+
module Storefront
|
|
7
|
+
class CartItemsDocumentationTest < DocumentationTest
|
|
8
|
+
include AuthenticationTest
|
|
9
|
+
include OrdersTest
|
|
10
|
+
|
|
11
|
+
resource 'Cart'
|
|
12
|
+
|
|
13
|
+
setup :set_user, :set_product, :set_order
|
|
14
|
+
|
|
15
|
+
def set_user
|
|
16
|
+
@user = create_user(first_name: 'Susan', last_name: 'Baker')
|
|
17
|
+
@auth = @user.authentication_tokens.create!
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def set_product
|
|
21
|
+
@product = create_product(
|
|
22
|
+
id: 'VINTEE',
|
|
23
|
+
name: 'Vintage Tee',
|
|
24
|
+
variants: [
|
|
25
|
+
{ sku: 'VT001', regular: 5.to_m },
|
|
26
|
+
{ sku: 'VT002', regular: 6.to_m }
|
|
27
|
+
]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
create_inventory(id: 'VT001', policy: 'standard', available: 2)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def set_order
|
|
34
|
+
@order = create_order(user_id: @user.id)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_and_document_adding_an_item
|
|
38
|
+
description 'Adding an item'
|
|
39
|
+
route storefront_api.cart_items_path(':cart_id')
|
|
40
|
+
explanation <<-EOS
|
|
41
|
+
Adds an item to the cart. Use the create a cart endpoint to get a
|
|
42
|
+
cart_id to use with this endpoint.
|
|
43
|
+
EOS
|
|
44
|
+
|
|
45
|
+
record_request do
|
|
46
|
+
post storefront_api.cart_items_path(@order),
|
|
47
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) },
|
|
48
|
+
as: :json,
|
|
49
|
+
params: {
|
|
50
|
+
product_id: @product.id,
|
|
51
|
+
sku: @product.skus.first,
|
|
52
|
+
quantity: 2
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
assert_equal(200, response.status)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_and_document_updating_an_item
|
|
60
|
+
add_item(@order, product_id: @product.id, sku: 'VT001', quantity: 2)
|
|
61
|
+
|
|
62
|
+
description 'Updating an item'
|
|
63
|
+
route storefront_api.cart_item_path(':cart_id', ':id')
|
|
64
|
+
explanation <<-EOS
|
|
65
|
+
Updates an item in the cart. Use the create a cart endpoint to get a
|
|
66
|
+
cart ID to use with this endpoint, and use the adding an item
|
|
67
|
+
endpoint to get an ID for an item.
|
|
68
|
+
EOS
|
|
69
|
+
|
|
70
|
+
record_request do
|
|
71
|
+
patch storefront_api.cart_item_path(@order, @order.items.first),
|
|
72
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) },
|
|
73
|
+
as: :json,
|
|
74
|
+
params: {
|
|
75
|
+
sku: @product.skus.last,
|
|
76
|
+
quantity: 3
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
assert_equal(200, response.status)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_and_document_deleting_an_item
|
|
84
|
+
add_item(@order, product_id: @product.id, sku: 'VT001', quantity: 2)
|
|
85
|
+
|
|
86
|
+
description 'Delete an item'
|
|
87
|
+
route storefront_api.cart_item_path(':cart_id', ':id')
|
|
88
|
+
explanation <<-EOS
|
|
89
|
+
Removes an item in the cart. Use the create a cart endpoint to get a
|
|
90
|
+
cart ID to use with this endpoint, and use the adding an item
|
|
91
|
+
endpoint to get an ID for an item.
|
|
92
|
+
EOS
|
|
93
|
+
|
|
94
|
+
record_request do
|
|
95
|
+
delete storefront_api.cart_item_path(@order, @order.items.first),
|
|
96
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
|
97
|
+
|
|
98
|
+
assert_equal(200, response.status)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'workarea/api/documentation_test'
|
|
3
|
+
|
|
4
|
+
module Workarea
|
|
5
|
+
module Api
|
|
6
|
+
module Storefront
|
|
7
|
+
class CartsDocumentationTest < DocumentationTest
|
|
8
|
+
include AuthenticationTest
|
|
9
|
+
include OrdersTest
|
|
10
|
+
|
|
11
|
+
resource 'Cart'
|
|
12
|
+
|
|
13
|
+
setup :set_user, :set_product, :set_order
|
|
14
|
+
|
|
15
|
+
def set_user
|
|
16
|
+
@user = create_user(first_name: 'Susan', last_name: 'Baker')
|
|
17
|
+
@auth = @user.authentication_tokens.create!
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def set_product
|
|
21
|
+
@product = create_product(
|
|
22
|
+
id: 'VINTEE',
|
|
23
|
+
name: 'Vintage Tee',
|
|
24
|
+
variants: [
|
|
25
|
+
{ sku: 'VT001', regular: 5.to_m },
|
|
26
|
+
{ sku: 'VT002', regular: 6.to_m }
|
|
27
|
+
]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
create_inventory(id: 'VT001', policy: 'standard', available: 2)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def set_order
|
|
34
|
+
@order = create_order(user_id: @user.id)
|
|
35
|
+
add_item(@order, product_id: @product.id, sku: 'VT001', quantity: 2)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_and_document_listing_carts
|
|
39
|
+
description "Listing user's carts"
|
|
40
|
+
route storefront_api.carts_path
|
|
41
|
+
explanation <<-EOS
|
|
42
|
+
You can get a listing of all of a user's open carts with this
|
|
43
|
+
endpoint. There will usually be one from the standard storefront,
|
|
44
|
+
but with the cart creation endpoint there is the potential to create
|
|
45
|
+
and manage multiple carts for a single user.
|
|
46
|
+
EOS
|
|
47
|
+
|
|
48
|
+
record_request do
|
|
49
|
+
get storefront_api.carts_path,
|
|
50
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
|
51
|
+
|
|
52
|
+
assert_equal(200, response.status)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_and_document_creating_a_guest_cart
|
|
57
|
+
description 'Creating a new guest cart'
|
|
58
|
+
route storefront_api.carts_path
|
|
59
|
+
explanation <<-EOS
|
|
60
|
+
Use this endpoint to create a cart. This allows the possibility of
|
|
61
|
+
multiple carts for a user.
|
|
62
|
+
EOS
|
|
63
|
+
|
|
64
|
+
record_request do
|
|
65
|
+
post storefront_api.carts_path
|
|
66
|
+
assert_equal(200, response.status)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_and_document_creating_a_logged_in_cart
|
|
71
|
+
description 'Creating a new cart for a user'
|
|
72
|
+
route storefront_api.carts_path
|
|
73
|
+
explanation <<-EOS
|
|
74
|
+
Here's how to create a cart for a user. This endpoint allows the
|
|
75
|
+
possibility of multiple carts for a user.
|
|
76
|
+
EOS
|
|
77
|
+
|
|
78
|
+
record_request do
|
|
79
|
+
post storefront_api.carts_path,
|
|
80
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
|
81
|
+
|
|
82
|
+
assert_equal(200, response.status)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def test_and_document_showing_a_cart
|
|
87
|
+
description 'Showing cart'
|
|
88
|
+
route storefront_api.cart_path(':id')
|
|
89
|
+
explanation <<-EOS
|
|
90
|
+
This will get details on a cart you've created with the cart
|
|
91
|
+
creation endpoint.
|
|
92
|
+
EOS
|
|
93
|
+
|
|
94
|
+
record_request do
|
|
95
|
+
get storefront_api.cart_path(@order),
|
|
96
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
|
97
|
+
|
|
98
|
+
assert_equal(200, response.status)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_and_document_adding_a_promo_code
|
|
103
|
+
description 'Adding a promo code'
|
|
104
|
+
route storefront_api.add_promo_code_to_cart_path(':id')
|
|
105
|
+
explanation 'This endpoint will add promo codes to the cart'
|
|
106
|
+
|
|
107
|
+
create_order_total_discount(promo_codes: %w(10OFF))
|
|
108
|
+
|
|
109
|
+
record_request do
|
|
110
|
+
post storefront_api.add_promo_code_to_cart_path(@order),
|
|
111
|
+
as: :json,
|
|
112
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) },
|
|
113
|
+
params: { promo_code: '10OFF' }
|
|
114
|
+
|
|
115
|
+
assert_equal(200, response.status)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'workarea/api/documentation_test'
|
|
3
|
+
|
|
4
|
+
module Workarea
|
|
5
|
+
module Api
|
|
6
|
+
module Storefront
|
|
7
|
+
class CategoriesDocumentationTest < DocumentationTest
|
|
8
|
+
resource 'Categories'
|
|
9
|
+
|
|
10
|
+
setup :set_product
|
|
11
|
+
setup :set_category
|
|
12
|
+
setup :set_taxonomy
|
|
13
|
+
setup :set_content
|
|
14
|
+
|
|
15
|
+
def set_product
|
|
16
|
+
@product = create_product(
|
|
17
|
+
name: 'Sweet Shirt',
|
|
18
|
+
filters: { size: %w[Small Medium Large], color: 'Blue' },
|
|
19
|
+
variants: [{ sku: 'SKU', details: { color: 'Blue' }, regular: 2.to_m }],
|
|
20
|
+
details: { size: 'Small', color: 'Red' },
|
|
21
|
+
images: [{ image: product_image_file, option: 'Blue' }]
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def set_category
|
|
26
|
+
@category = create_category(
|
|
27
|
+
name: 'Shirts',
|
|
28
|
+
product_ids: [@product.id],
|
|
29
|
+
terms_facets: %w(Size Color)
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def set_taxonomy
|
|
34
|
+
first_level = create_taxon(name: 'Mens')
|
|
35
|
+
@taxon = first_level.children.create!(navigable: @category)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def set_content
|
|
39
|
+
content = Content.for(@category)
|
|
40
|
+
content.blocks.build(
|
|
41
|
+
area: :above_results,
|
|
42
|
+
type: :text,
|
|
43
|
+
data: { text: 'text' }
|
|
44
|
+
)
|
|
45
|
+
content.blocks.build(
|
|
46
|
+
area: :below_results,
|
|
47
|
+
type: :text,
|
|
48
|
+
data: { text: 'text' }
|
|
49
|
+
)
|
|
50
|
+
content.save!
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_and_document_index
|
|
54
|
+
description 'Showing a listing of categories'
|
|
55
|
+
route storefront_api.categories_path
|
|
56
|
+
parameter 'page', 'Page number'
|
|
57
|
+
explanation <<-EOS
|
|
58
|
+
This endpoint will give you a paginated list of all active
|
|
59
|
+
categories, that is, all categories that could be shown on the
|
|
60
|
+
storefront.
|
|
61
|
+
EOS
|
|
62
|
+
|
|
63
|
+
create_category(name: 'Pants')
|
|
64
|
+
|
|
65
|
+
record_request do
|
|
66
|
+
get storefront_api.categories_path(page: '1')
|
|
67
|
+
assert_equal(200, response.status)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_and_document_show
|
|
72
|
+
description 'Showing a category'
|
|
73
|
+
route storefront_api.category_path(':slug')
|
|
74
|
+
parameter 'sort', 'Sort by'
|
|
75
|
+
parameter 'page', 'Page number'
|
|
76
|
+
parameter ':facet_name', 'Each facet setup on the category will have a corresponding parameter'
|
|
77
|
+
explanation <<-EOS
|
|
78
|
+
This endpoint includes everything you need to render a category,
|
|
79
|
+
including any associated content, products, and filters.
|
|
80
|
+
EOS
|
|
81
|
+
|
|
82
|
+
record_request do
|
|
83
|
+
get storefront_api.category_path(@category, page: '1', sort: 'price_desc')
|
|
84
|
+
assert_equal(200, response.status)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'workarea/api/documentation_test'
|
|
3
|
+
|
|
4
|
+
module Workarea
|
|
5
|
+
module Api
|
|
6
|
+
module Storefront
|
|
7
|
+
class CheckoutsDocumentationTest < DocumentationTest
|
|
8
|
+
include OrdersTest
|
|
9
|
+
|
|
10
|
+
resource 'Checkout'
|
|
11
|
+
|
|
12
|
+
setup :set_product, :set_order, :set_checkout_data
|
|
13
|
+
|
|
14
|
+
def set_product
|
|
15
|
+
@product = create_product(
|
|
16
|
+
id: 'VINTEE',
|
|
17
|
+
name: 'Vintage Tee',
|
|
18
|
+
variants: [
|
|
19
|
+
{ sku: 'VT001', regular: 5.to_m },
|
|
20
|
+
{ sku: 'VT002', regular: 6.to_m }
|
|
21
|
+
]
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
create_inventory(id: 'VT001', policy: 'standard', available: 2)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def set_order
|
|
28
|
+
@order = create_order(email: 'sbaker@workarea.com')
|
|
29
|
+
add_item(@order, product_id: @product.id, sku: 'VT001', quantity: 2)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def set_checkout_data
|
|
33
|
+
create_shipping_service(name: 'Standard', rates: [{ price: 5.to_m }])
|
|
34
|
+
create_shipping_service(name: 'Express', rates: [{ price: 10.to_m }])
|
|
35
|
+
create_shipping_service(name: 'Overnight', rates: [{ price: 20.to_m }])
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def address
|
|
39
|
+
{
|
|
40
|
+
first_name: 'Susan',
|
|
41
|
+
last_name: 'Baker',
|
|
42
|
+
street: '350 Fifth Avenue',
|
|
43
|
+
city: 'New York',
|
|
44
|
+
region: 'NY',
|
|
45
|
+
country: 'US',
|
|
46
|
+
postal_code: '10118',
|
|
47
|
+
phone_number: '6465552390'
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_and_document_show
|
|
52
|
+
description 'Showing a checkout'
|
|
53
|
+
route storefront_api.checkout_path(':id')
|
|
54
|
+
explanation <<-EOS
|
|
55
|
+
This will give you overview of the state of checkout for the
|
|
56
|
+
associated order ID. It includes full order information, as well
|
|
57
|
+
as summary information for each step of checkout.
|
|
58
|
+
EOS
|
|
59
|
+
|
|
60
|
+
record_request do
|
|
61
|
+
get storefront_api.checkout_path(@order)
|
|
62
|
+
assert_equal(200, response.status)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_and_document_update
|
|
67
|
+
description 'Updating a checkout'
|
|
68
|
+
route storefront_api.checkout_path(':id')
|
|
69
|
+
explanation <<-EOS
|
|
70
|
+
Use this endpoint to make updates to checkout. This will typically
|
|
71
|
+
mean setting addresses and shipping options for the checkout.
|
|
72
|
+
EOS
|
|
73
|
+
|
|
74
|
+
record_request do
|
|
75
|
+
patch storefront_api.checkout_path(@order),
|
|
76
|
+
as: :json,
|
|
77
|
+
params: {
|
|
78
|
+
email: 'susanb@workarea.com',
|
|
79
|
+
shipping_address: address,
|
|
80
|
+
billing_address: address,
|
|
81
|
+
shipping_service: 'Express'
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
assert_equal(200, response.status)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_and_document_complete
|
|
89
|
+
description 'Completing a checkout'
|
|
90
|
+
route storefront_api.complete_checkout_path(':id')
|
|
91
|
+
explanation <<-EOS
|
|
92
|
+
This endpoint completes checkout and places the order. Payment
|
|
93
|
+
tender information is required at this point, and should be included
|
|
94
|
+
with this request.
|
|
95
|
+
EOS
|
|
96
|
+
|
|
97
|
+
patch storefront_api.checkout_path(@order),
|
|
98
|
+
as: :json,
|
|
99
|
+
params: {
|
|
100
|
+
email: 'susanb@workarea.com',
|
|
101
|
+
shipping_address: address,
|
|
102
|
+
billing_address: address,
|
|
103
|
+
shipping_service: 'Express'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
order = JSON.parse(response.body)['order']
|
|
107
|
+
|
|
108
|
+
record_request do
|
|
109
|
+
post storefront_api.complete_checkout_path(order['id']),
|
|
110
|
+
as: :json,
|
|
111
|
+
params: {
|
|
112
|
+
payment: 'new_card',
|
|
113
|
+
credit_card: {
|
|
114
|
+
number: '4111111111111111',
|
|
115
|
+
month: '3',
|
|
116
|
+
year: Time.now.year + 2,
|
|
117
|
+
cvv: '123'
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
assert_equal(200, response.status)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_and_document_reset
|
|
125
|
+
description 'Showing a checkout'
|
|
126
|
+
route storefront_api.reset_checkout_path(':id')
|
|
127
|
+
explanation <<-EOS
|
|
128
|
+
This endpoint resets the checkout by wiping all private information
|
|
129
|
+
from the order and it's associated models. Use it for handling
|
|
130
|
+
timeouts, logouts, and any other situation where you want to ensure
|
|
131
|
+
the safety of the customer's information.
|
|
132
|
+
EOS
|
|
133
|
+
|
|
134
|
+
record_request do
|
|
135
|
+
get storefront_api.reset_checkout_path(@order)
|
|
136
|
+
assert_equal(200, response.status)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'workarea/api/documentation_test'
|
|
3
|
+
|
|
4
|
+
module Workarea
|
|
5
|
+
module Api
|
|
6
|
+
module Storefront
|
|
7
|
+
class ContactsDocumentationTest < DocumentationTest
|
|
8
|
+
resource 'Contacts'
|
|
9
|
+
|
|
10
|
+
setup :set_contact_params
|
|
11
|
+
|
|
12
|
+
def set_contact_params
|
|
13
|
+
@contact_params = {
|
|
14
|
+
name: 'Name',
|
|
15
|
+
email: 'email@example.com',
|
|
16
|
+
order_id: 'OrderID',
|
|
17
|
+
subject: :orders,
|
|
18
|
+
message: 'Message'
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_and_document_create
|
|
23
|
+
description 'Creating a contact'
|
|
24
|
+
route storefront_api.contacts_path
|
|
25
|
+
explanation <<-EOS
|
|
26
|
+
This endpoints creates a customer service inquiry on behalf of the
|
|
27
|
+
customer, and will send an email to the address in
|
|
28
|
+
Workarea.config.email_to
|
|
29
|
+
EOS
|
|
30
|
+
|
|
31
|
+
record_request do
|
|
32
|
+
post storefront_api.contacts_path, params: @contact_params, as: :json
|
|
33
|
+
assert_equal(200, response.status)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|