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,129 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'workarea/api/documentation_test'
|
3
|
+
|
4
|
+
module Workarea
|
5
|
+
module Api
|
6
|
+
module Storefront
|
7
|
+
class SavedAddressesDocumentationTest < DocumentationTest
|
8
|
+
include AuthenticationTest
|
9
|
+
|
10
|
+
resource 'Saved Addresses'
|
11
|
+
|
12
|
+
setup :set_user
|
13
|
+
setup :set_address
|
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_address
|
21
|
+
@address = @user.addresses.create!(
|
22
|
+
first_name: 'Susan',
|
23
|
+
last_name: 'Baker',
|
24
|
+
street: '350 Fifth Avenue',
|
25
|
+
city: 'New York',
|
26
|
+
region: 'NY',
|
27
|
+
country: 'US',
|
28
|
+
postal_code: '10118',
|
29
|
+
phone_number: '6465552390'
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_and_show_index_of_addresses
|
34
|
+
@user.addresses.create!(
|
35
|
+
first_name: 'Susan',
|
36
|
+
last_name: 'Baker',
|
37
|
+
street: '4059 Mt Lee Dr.',
|
38
|
+
city: 'Hollywood',
|
39
|
+
region: 'CA',
|
40
|
+
country: 'US',
|
41
|
+
postal_code: '90068',
|
42
|
+
phone_number: '7545552390'
|
43
|
+
)
|
44
|
+
|
45
|
+
description "Listing the user's saved addresses"
|
46
|
+
route storefront_api.saved_addresses_path
|
47
|
+
explanation <<-EOS
|
48
|
+
List a customer's saved addresses. Useful for account management and
|
49
|
+
for using saved addresses in checkout.
|
50
|
+
EOS
|
51
|
+
|
52
|
+
record_request do
|
53
|
+
get storefront_api.saved_addresses_path,
|
54
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
55
|
+
|
56
|
+
assert_equal(200, response.status)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_and_document_show_a_single_address
|
61
|
+
description 'Showing a saved address'
|
62
|
+
route storefront_api.saved_address_path(':id')
|
63
|
+
|
64
|
+
record_request do
|
65
|
+
get storefront_api.saved_address_path(@address),
|
66
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
67
|
+
|
68
|
+
assert_equal(200, response.status)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_and_document_creating_a_new_address
|
73
|
+
description 'Creating a saved address'
|
74
|
+
route storefront_api.saved_addresses_path
|
75
|
+
|
76
|
+
record_request do
|
77
|
+
post storefront_api.saved_addresses_path,
|
78
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) },
|
79
|
+
as: :json,
|
80
|
+
params: {
|
81
|
+
first_name: 'Susan',
|
82
|
+
last_name: 'Baker',
|
83
|
+
street: '4059 Mt Lee Dr.',
|
84
|
+
city: 'Hollywood',
|
85
|
+
region: 'CA',
|
86
|
+
country: 'US',
|
87
|
+
postal_code: '90068',
|
88
|
+
phone_number: '7545552390'
|
89
|
+
}
|
90
|
+
|
91
|
+
assert_equal(200, response.status)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_and_document_updating_an_address
|
96
|
+
description 'Updating a saved address'
|
97
|
+
route storefront_api.saved_address_path(':id')
|
98
|
+
|
99
|
+
record_request do
|
100
|
+
patch storefront_api.saved_address_path(@address),
|
101
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) },
|
102
|
+
as: :json,
|
103
|
+
params: {
|
104
|
+
street: '4059 Mt Lee Dr.',
|
105
|
+
city: 'Hollywood',
|
106
|
+
region: 'CA',
|
107
|
+
postal_code: '90068',
|
108
|
+
phone_number: '7545552390'
|
109
|
+
}
|
110
|
+
|
111
|
+
assert_equal(200, response.status)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_and_document_deleting_an_address
|
116
|
+
description 'Deleting a saved address'
|
117
|
+
route storefront_api.saved_address_path(':id')
|
118
|
+
|
119
|
+
record_request do
|
120
|
+
delete storefront_api.saved_address_path(@address),
|
121
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
122
|
+
|
123
|
+
assert_equal(204, response.status)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'workarea/api/documentation_test'
|
3
|
+
|
4
|
+
module Workarea
|
5
|
+
module Api
|
6
|
+
module Storefront
|
7
|
+
class SavedCreditCardsDocumentationTest < DocumentationTest
|
8
|
+
include AuthenticationTest
|
9
|
+
|
10
|
+
resource 'Saved Credit Cards'
|
11
|
+
|
12
|
+
setup :set_user
|
13
|
+
setup :set_payment_profile
|
14
|
+
setup :set_credit_card
|
15
|
+
|
16
|
+
def set_user
|
17
|
+
@user = create_user(first_name: 'Susan', last_name: 'Baker')
|
18
|
+
@auth = @user.authentication_tokens.create!
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_payment_profile
|
22
|
+
@payment_profile = Payment::Profile.lookup(
|
23
|
+
PaymentReference.new(@user)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_credit_card
|
28
|
+
@credit_card = @payment_profile.credit_cards.create!(
|
29
|
+
number: '4012888888881881',
|
30
|
+
first_name: 'Susan',
|
31
|
+
last_name: 'Baker',
|
32
|
+
month: '3',
|
33
|
+
year: (Time.now.year + 4).to_s,
|
34
|
+
cvv: '999'
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_and_show_index_of_credit_cards
|
39
|
+
@payment_profile.credit_cards.create!(
|
40
|
+
number: '4111111111111111',
|
41
|
+
first_name: 'Susan',
|
42
|
+
last_name: 'Baker',
|
43
|
+
month: '7',
|
44
|
+
year: (Time.now.year + 5).to_s,
|
45
|
+
cvv: '999'
|
46
|
+
)
|
47
|
+
|
48
|
+
description 'Listing the user\'s saved credit cards'
|
49
|
+
route storefront_api.saved_credit_cards_path
|
50
|
+
explanation <<-EOS
|
51
|
+
List a customer's saved addresses. Useful for account management.
|
52
|
+
These addresses will be available to the customer in an
|
53
|
+
authenticated checkout.
|
54
|
+
EOS
|
55
|
+
|
56
|
+
record_request do
|
57
|
+
get storefront_api.saved_credit_cards_path,
|
58
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
59
|
+
|
60
|
+
assert_equal(200, response.status)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_and_document_show_a_single_credit_card
|
65
|
+
description 'Showing a saved credit card'
|
66
|
+
route storefront_api.saved_credit_card_path(':id')
|
67
|
+
|
68
|
+
record_request do
|
69
|
+
get storefront_api.saved_credit_card_path(@credit_card),
|
70
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
71
|
+
|
72
|
+
assert_equal(200, response.status)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_and_document_creating_a_new_credit_card
|
77
|
+
description 'Creating a saved credit card'
|
78
|
+
route storefront_api.saved_credit_cards_path
|
79
|
+
|
80
|
+
record_request do
|
81
|
+
post storefront_api.saved_credit_cards_path,
|
82
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) },
|
83
|
+
as: :json,
|
84
|
+
params: {
|
85
|
+
number: '4111111111111111',
|
86
|
+
first_name: 'Susan',
|
87
|
+
last_name: 'Baker',
|
88
|
+
month: '7',
|
89
|
+
year: (Time.now.year + 5).to_s,
|
90
|
+
cvv: '123'
|
91
|
+
}
|
92
|
+
|
93
|
+
assert_equal(200, response.status)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_and_document_updating_an_credit_card
|
98
|
+
description 'Updating a saved credit card'
|
99
|
+
route storefront_api.saved_credit_card_path(':id')
|
100
|
+
|
101
|
+
record_request do
|
102
|
+
patch storefront_api.saved_credit_card_path(@credit_card),
|
103
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) },
|
104
|
+
as: :json,
|
105
|
+
params: {
|
106
|
+
month: '7',
|
107
|
+
year: (Time.now.year + 5).to_s,
|
108
|
+
cvv: '123'
|
109
|
+
}
|
110
|
+
|
111
|
+
assert_equal(200, response.status)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_and_document_deleting_an_credit_card
|
116
|
+
description 'Deleting a saved credit card'
|
117
|
+
route storefront_api.saved_credit_card_path(':id')
|
118
|
+
|
119
|
+
record_request do
|
120
|
+
delete storefront_api.saved_credit_card_path(@credit_card),
|
121
|
+
headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
|
122
|
+
|
123
|
+
assert_equal(204, response.status)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'workarea/api/documentation_test'
|
3
|
+
|
4
|
+
module Workarea
|
5
|
+
module Api
|
6
|
+
module Storefront
|
7
|
+
class SearchesDocumentationTest < DocumentationTest
|
8
|
+
resource 'Searches'
|
9
|
+
|
10
|
+
setup :set_content
|
11
|
+
|
12
|
+
def set_content
|
13
|
+
@content = Content.for('search')
|
14
|
+
@content.blocks.create!(
|
15
|
+
area: :results,
|
16
|
+
type: :text,
|
17
|
+
data: { text: 'Huzzah! Your search results are below!' }
|
18
|
+
)
|
19
|
+
@content.blocks.create!(
|
20
|
+
area: :no_results,
|
21
|
+
type: :text,
|
22
|
+
data: { text: 'Sorry, we can\'t find what you searched for!' }
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_and_document_autocomplete
|
27
|
+
description 'Showing search autocomplete suggestions'
|
28
|
+
route storefront_api.searches_path
|
29
|
+
explanation <<-EOS
|
30
|
+
This list will be based on popular search terms and matching
|
31
|
+
products, categories, etc. Useful for showing a autocomplete
|
32
|
+
drop-down as a customer types in a search bar.
|
33
|
+
EOS
|
34
|
+
|
35
|
+
create_product(name: 'Red Product')
|
36
|
+
create_category(name: 'Red Category')
|
37
|
+
create_page(name: 'Page about Red Products')
|
38
|
+
|
39
|
+
Metrics::SearchByDay.save_search('red', 3)
|
40
|
+
travel_to 1.weeks.from_now
|
41
|
+
GenerateInsights.generate_all!
|
42
|
+
BulkIndexSearches.perform
|
43
|
+
travel_back
|
44
|
+
|
45
|
+
record_request do
|
46
|
+
get storefront_api.searches_path(q: 'red')
|
47
|
+
assert_equal(200, response.status)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_and_document_show
|
52
|
+
description 'Showing search results'
|
53
|
+
route storefront_api.search_path
|
54
|
+
parameter 'q', 'The search query string entered by the customer'
|
55
|
+
parameter 'sort', 'Sort by'
|
56
|
+
parameter 'page', 'Page number'
|
57
|
+
parameter ':facet_name', 'Each facet setup on search settings will have a corresponding parameter'
|
58
|
+
explanation <<-EOS
|
59
|
+
This endpoint returns everything you'll need to show search results
|
60
|
+
to customers. This includes products, filters, and any content
|
61
|
+
that's been setup by an administrator.
|
62
|
+
EOS
|
63
|
+
|
64
|
+
create_product(
|
65
|
+
id: 'PRODUCT1',
|
66
|
+
name: 'Pretty Nice Shirt',
|
67
|
+
filters: { 'Size' => %w[Small Medium Large], 'Color' => 'Blue' },
|
68
|
+
variants: [{ sku: 'SKU', regular: 35.to_m }],
|
69
|
+
images: [{ image: product_image_file, option: 'Blue' }]
|
70
|
+
)
|
71
|
+
|
72
|
+
create_product(
|
73
|
+
id: 'PRODUCT2',
|
74
|
+
name: 'Great Pants',
|
75
|
+
filters: { 'Size' => %w[Small Medium Large], 'Color' => 'Brown' },
|
76
|
+
variants: [{ sku: 'SKU', regular: 50.to_m }],
|
77
|
+
images: [{ image: product_image_file, option: 'Brown' }]
|
78
|
+
)
|
79
|
+
|
80
|
+
record_request do
|
81
|
+
get storefront_api.search_path(q: 'large', page: '1', sort: 'price_desc')
|
82
|
+
assert_equal(200, response.status)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'workarea/api/documentation_test'
|
3
|
+
|
4
|
+
module Workarea
|
5
|
+
module Api
|
6
|
+
module Storefront
|
7
|
+
class SystemContentDocumentationTest < DocumentationTest
|
8
|
+
resource 'System Content'
|
9
|
+
|
10
|
+
def test_and_document_show_home_page
|
11
|
+
description 'Showing the home page'
|
12
|
+
route storefront_api.system_content_path('home_page')
|
13
|
+
explanation <<-EOS
|
14
|
+
This endpoint returns everything you'll need to render the home
|
15
|
+
page.
|
16
|
+
EOS
|
17
|
+
|
18
|
+
content = Content.for('Home Page')
|
19
|
+
content.blocks.create!(
|
20
|
+
area: :default,
|
21
|
+
type: :text,
|
22
|
+
data: { text: 'Summer is here!' }
|
23
|
+
)
|
24
|
+
content.blocks.create!(
|
25
|
+
area: :default,
|
26
|
+
type: :text,
|
27
|
+
data: { text: 'Get 20% off all swimwear' }
|
28
|
+
)
|
29
|
+
|
30
|
+
record_request do
|
31
|
+
get storefront_api.system_content_path('home_page')
|
32
|
+
assert_equal(200, response.status)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_and_document_show
|
37
|
+
description 'Showing system content'
|
38
|
+
route storefront_api.system_content_path(':name')
|
39
|
+
explanation <<-EOS
|
40
|
+
System content is content for an area of site not configured by the
|
41
|
+
CMS. Examples would be content for the cart page, content for
|
42
|
+
checkout, site layout content, etc. The home page is also an example
|
43
|
+
of system content and shown in a separate example.
|
44
|
+
EOS
|
45
|
+
|
46
|
+
content = Content.for('Layout')
|
47
|
+
content.blocks.create!(
|
48
|
+
area: :header_promo,
|
49
|
+
type: :text,
|
50
|
+
data: { text: 'Don\'t miss our sizzling summer deals!' }
|
51
|
+
)
|
52
|
+
content.blocks.create!(
|
53
|
+
area: :footer_navigation,
|
54
|
+
type: :text,
|
55
|
+
data: { text: 'Be the first to received our exclusive discounts' }
|
56
|
+
)
|
57
|
+
|
58
|
+
record_request do
|
59
|
+
get storefront_api.system_content_path('layout')
|
60
|
+
assert_equal(200, response.status)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'workarea/api/documentation_test'
|
3
|
+
|
4
|
+
module Workarea
|
5
|
+
module Api
|
6
|
+
module Storefront
|
7
|
+
class TaxonsDocumentationTest < DocumentationTest
|
8
|
+
resource 'Taxons'
|
9
|
+
|
10
|
+
setup :set_taxons
|
11
|
+
|
12
|
+
def set_taxons
|
13
|
+
@taxon = create_taxon(
|
14
|
+
name: 'Mens',
|
15
|
+
url: 'http://example.com/pages/mens'
|
16
|
+
)
|
17
|
+
|
18
|
+
@taxon.children.create!(name: 'Sale')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_and_document_show
|
22
|
+
description 'Showing a taxon'
|
23
|
+
route storefront_api.taxon_path(':id')
|
24
|
+
explanation <<-EOS
|
25
|
+
This endpoint will show details on a particular node (or taxon) of
|
26
|
+
the site taxonomy, along with its children.
|
27
|
+
EOS
|
28
|
+
|
29
|
+
record_request do
|
30
|
+
get storefront_api.taxon_path(@taxon)
|
31
|
+
assert_equal(200, response.status)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'workarea/api/documentation_test'
|
3
|
+
|
4
|
+
module Workarea
|
5
|
+
module Api
|
6
|
+
module Storefront
|
7
|
+
class ValidationDocumentationTest < DocumentationTest
|
8
|
+
include OrdersTest
|
9
|
+
|
10
|
+
resource 'Validation Errors'
|
11
|
+
|
12
|
+
def test_showing_validation_errors
|
13
|
+
description 'General validation errors'
|
14
|
+
route storefront_api.account_path
|
15
|
+
explanation <<-EOS
|
16
|
+
This demonstrates API responses when invalid data is submitted.
|
17
|
+
EOS
|
18
|
+
|
19
|
+
record_request do
|
20
|
+
post storefront_api.account_path,
|
21
|
+
as: :json,
|
22
|
+
params: { email: 'bob@', password: '' }
|
23
|
+
|
24
|
+
assert_equal(422, response.status)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_checkout_validation_errors
|
29
|
+
description 'Checkout validation errors'
|
30
|
+
route storefront_api.checkout_path(':id')
|
31
|
+
explanation <<-EOS
|
32
|
+
Due to the more complex nature of checkout updates and data,
|
33
|
+
checkout validation errors are returned inline with the resource
|
34
|
+
they are coming from as shown below. Note the response status can be
|
35
|
+
200 OK, due to some data being persisted properly.
|
36
|
+
EOS
|
37
|
+
|
38
|
+
product = create_product(
|
39
|
+
id: 'VINTEE',
|
40
|
+
name: 'Vintage Tee',
|
41
|
+
variants: [
|
42
|
+
{ sku: 'VT001', regular: 5.to_m },
|
43
|
+
{ sku: 'VT002', regular: 6.to_m }
|
44
|
+
]
|
45
|
+
)
|
46
|
+
|
47
|
+
order = create_order(email: 'sbaker@workarea.com')
|
48
|
+
add_item(order, product_id: product.id, sku: 'VT001', quantity: 2)
|
49
|
+
|
50
|
+
record_request do
|
51
|
+
patch storefront_api.checkout_path(order),
|
52
|
+
as: :json,
|
53
|
+
params: {
|
54
|
+
email: 'susanb@',
|
55
|
+
shipping_address: {
|
56
|
+
first_name: '',
|
57
|
+
last_name: 'Baker',
|
58
|
+
street: '350 Fifth Avenue',
|
59
|
+
city: 'New York',
|
60
|
+
region: 'NY',
|
61
|
+
country: 'US',
|
62
|
+
postal_code: '10118'
|
63
|
+
},
|
64
|
+
billing_address: {
|
65
|
+
first_name: 'Susan',
|
66
|
+
last_name: 'Baker',
|
67
|
+
street: '',
|
68
|
+
city: 'New York',
|
69
|
+
region: 'NY',
|
70
|
+
country: 'US',
|
71
|
+
postal_code: '10118'
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
assert_equal(200, response.status)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Rails.application.load_tasks
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
data/test/dummy/bin/rake
ADDED