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,84 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class CategoriesIntegrationTest < IntegrationTest
|
7
|
+
setup :set_product
|
8
|
+
setup :set_category
|
9
|
+
setup :set_taxonomy
|
10
|
+
setup :set_content
|
11
|
+
|
12
|
+
def set_product
|
13
|
+
@product = create_product(
|
14
|
+
filters: { size: %w[Small Medium Large], color: 'Blue' },
|
15
|
+
variants: [{ sku: 'SKU', details: { color: 'Blue' }, regular: 2.to_m }],
|
16
|
+
details: { size: 'Small', color: 'Red' },
|
17
|
+
images: [{ image: product_image_file, option: 'Blue' }]
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_category
|
22
|
+
@category = create_category(
|
23
|
+
product_ids: [@product.id],
|
24
|
+
terms_facets: %w(Size Color)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_taxonomy
|
29
|
+
first_level = create_taxon(name: 'First Level')
|
30
|
+
@taxon = first_level.children.create!(navigable: @category)
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_content
|
34
|
+
content = Content.for(@category)
|
35
|
+
content.blocks.build(
|
36
|
+
area: :above_results,
|
37
|
+
type: :text,
|
38
|
+
data: { text: 'text' }
|
39
|
+
)
|
40
|
+
content.blocks.build(
|
41
|
+
area: :below_results,
|
42
|
+
type: :text,
|
43
|
+
data: { text: 'text' }
|
44
|
+
)
|
45
|
+
content.save!
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_shows_categories_index
|
49
|
+
create_category
|
50
|
+
|
51
|
+
get storefront_api.categories_path
|
52
|
+
result = JSON.parse(response.body)
|
53
|
+
|
54
|
+
assert_equal(2, result['categories'].size)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_shows_categories
|
58
|
+
get storefront_api.category_path(@category.slug)
|
59
|
+
result = JSON.parse(response.body)
|
60
|
+
|
61
|
+
assert_equal(@category.id.to_s, result['id'])
|
62
|
+
|
63
|
+
assert_equal(3, result['breadcrumbs'].count)
|
64
|
+
assert_equal(@taxon.id.to_s, result['breadcrumbs'].last['id'])
|
65
|
+
|
66
|
+
assert_equal(2, result['content_blocks'].count)
|
67
|
+
|
68
|
+
assert_equal(1, result['total_results'])
|
69
|
+
|
70
|
+
assert_equal(1, result['facets'].count)
|
71
|
+
|
72
|
+
product_result = result['products'].first
|
73
|
+
assert_equal(1, result['products'].count)
|
74
|
+
assert_equal(@product.id, product_result['id'])
|
75
|
+
|
76
|
+
processors = product_result['images'].first['urls'].map { |p| p['type'].to_sym }
|
77
|
+
processors.each do |processor|
|
78
|
+
refute_includes(Workarea.config.api_product_image_jobs_blacklist, processor)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class CheckoutsIntegrationTest < IntegrationTest
|
7
|
+
include OrdersTest
|
8
|
+
|
9
|
+
setup :set_product, :set_order, :set_checkout_data
|
10
|
+
|
11
|
+
def set_product
|
12
|
+
@product = create_product(
|
13
|
+
name: 'Test Product',
|
14
|
+
variants: [
|
15
|
+
{ sku: 'SKU1', regular: 5.to_m },
|
16
|
+
{ sku: 'SKU2', regular: 6.to_m }
|
17
|
+
]
|
18
|
+
)
|
19
|
+
|
20
|
+
create_inventory(id: 'SKU1', policy: 'standard', available: 2)
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_order
|
24
|
+
@order = create_order
|
25
|
+
add_item(@order, product_id: @product.id, sku: 'SKU1', quantity: 2)
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_checkout_data
|
29
|
+
create_shipping_service(name: 'Standard', rates: [{ price: 5.to_m }])
|
30
|
+
create_shipping_service(name: 'Express', rates: [{ price: 10.to_m }])
|
31
|
+
create_shipping_service(name: 'Overnight', rates: [{ price: 20.to_m }])
|
32
|
+
end
|
33
|
+
|
34
|
+
def address
|
35
|
+
{
|
36
|
+
first_name: 'Ben',
|
37
|
+
last_name: 'Crouse',
|
38
|
+
street: '22 S. 3rd St.',
|
39
|
+
street_2: 'Second Floor',
|
40
|
+
city: 'Philadelphia',
|
41
|
+
region: 'PA',
|
42
|
+
postal_code: '19106',
|
43
|
+
country: 'US'
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_preventing_checkout_with_a_placed_order
|
48
|
+
order = create_placed_order
|
49
|
+
|
50
|
+
get storefront_api.cart_path(order)
|
51
|
+
refute(response.ok?)
|
52
|
+
assert_equal(404, response.status)
|
53
|
+
|
54
|
+
get storefront_api.checkout_path(order)
|
55
|
+
refute(response.ok?)
|
56
|
+
assert_equal(404, response.status)
|
57
|
+
|
58
|
+
patch storefront_api.checkout_path(order)
|
59
|
+
refute(response.ok?)
|
60
|
+
assert_equal(404, response.status)
|
61
|
+
|
62
|
+
post storefront_api.complete_checkout_path(order)
|
63
|
+
refute(response.ok?)
|
64
|
+
assert_equal(404, response.status)
|
65
|
+
|
66
|
+
get storefront_api.reset_checkout_path(order)
|
67
|
+
refute(response.ok?)
|
68
|
+
assert_equal(404, response.status)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_show
|
72
|
+
get storefront_api.checkout_path(@order)
|
73
|
+
results = JSON.parse(response.body)
|
74
|
+
order = results['order']
|
75
|
+
|
76
|
+
assert(order['id'].present?)
|
77
|
+
refute(order['user_id'].present?)
|
78
|
+
|
79
|
+
checkout = results['checkout']
|
80
|
+
assert(checkout['started_at'].present?)
|
81
|
+
|
82
|
+
assert(checkout['addresses'].present?)
|
83
|
+
refute(checkout['addresses']['complete'])
|
84
|
+
|
85
|
+
assert(checkout['shipping'].present?)
|
86
|
+
refute(checkout['shipping']['complete'])
|
87
|
+
|
88
|
+
assert(checkout['payment'].present?)
|
89
|
+
refute(checkout['payment']['complete'])
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_update
|
93
|
+
patch storefront_api.checkout_path(@order),
|
94
|
+
params: {
|
95
|
+
email: 'test@workarea.com',
|
96
|
+
shipping_address: address,
|
97
|
+
billing_address: address,
|
98
|
+
}
|
99
|
+
|
100
|
+
results = JSON.parse(response.body)
|
101
|
+
order = results['order']
|
102
|
+
checkout = results['checkout']
|
103
|
+
|
104
|
+
assert(checkout['addresses']['complete'])
|
105
|
+
assert_equal('test@workarea.com', order['email'])
|
106
|
+
|
107
|
+
shipping_address = order['shipping_address']
|
108
|
+
assert(shipping_address.present?)
|
109
|
+
assert_equal('Ben', shipping_address['first_name'])
|
110
|
+
assert_equal('Crouse', shipping_address['last_name'])
|
111
|
+
assert_equal('22 S. 3rd St.', shipping_address['street'])
|
112
|
+
assert_equal('Second Floor', shipping_address['street_2'])
|
113
|
+
assert_equal('PA', shipping_address['region'])
|
114
|
+
assert_equal('US', shipping_address['country'])
|
115
|
+
assert_equal('19106', shipping_address['postal_code'])
|
116
|
+
|
117
|
+
billing_address = order['billing_address']
|
118
|
+
assert(billing_address.present?)
|
119
|
+
assert_equal('Ben', billing_address['first_name'])
|
120
|
+
assert_equal('Crouse', billing_address['last_name'])
|
121
|
+
assert_equal('22 S. 3rd St.', billing_address['street'])
|
122
|
+
assert_equal('Second Floor', billing_address['street_2'])
|
123
|
+
assert_equal('PA', billing_address['region'])
|
124
|
+
assert_equal('US', billing_address['country'])
|
125
|
+
assert_equal('19106', billing_address['postal_code'])
|
126
|
+
|
127
|
+
shipping_options = checkout['shipping']['shipping_options']
|
128
|
+
assert(shipping_options.present?)
|
129
|
+
assert_equal('Standard', shipping_options.first['name'])
|
130
|
+
assert_equal('Express', shipping_options.second['name'])
|
131
|
+
assert_equal('Overnight', shipping_options.third['name'])
|
132
|
+
|
133
|
+
patch storefront_api.checkout_path(order['id']),
|
134
|
+
params: { shipping_service: 'Express' }
|
135
|
+
|
136
|
+
checkout = JSON.parse(response.body)['checkout']
|
137
|
+
assert(checkout['shipping']['complete'])
|
138
|
+
|
139
|
+
assert_equal('Express', checkout['shipping']['shipping_service'])
|
140
|
+
assert_equal(1000, checkout['shipping']['shipping_total']['cents'])
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_complete
|
144
|
+
patch storefront_api.checkout_path(@order),
|
145
|
+
params: {
|
146
|
+
email: 'test@workarea.com',
|
147
|
+
shipping_address: address,
|
148
|
+
billing_address: address,
|
149
|
+
shipping_service: 'Express',
|
150
|
+
}
|
151
|
+
result = JSON.parse(response.body)
|
152
|
+
|
153
|
+
assert(result['checkout']['shipping']['complete'])
|
154
|
+
|
155
|
+
post storefront_api.complete_checkout_path(result['order']['id']),
|
156
|
+
params: {
|
157
|
+
payment: 'new_card',
|
158
|
+
credit_card: {
|
159
|
+
number: '1',
|
160
|
+
month: '1',
|
161
|
+
year: Time.now.year + 1,
|
162
|
+
cvv: '999'
|
163
|
+
}
|
164
|
+
}
|
165
|
+
result = JSON.parse(response.body)
|
166
|
+
|
167
|
+
assert(result['order']['placed_at'])
|
168
|
+
assert_equal(2000, result['order']['pricing']['total_price']['cents'])
|
169
|
+
|
170
|
+
tender = result['order']['tenders'].first
|
171
|
+
assert_equal('credit_card', tender['type'])
|
172
|
+
assert_equal(2000, tender['amount']['cents'])
|
173
|
+
|
174
|
+
order = Order.first
|
175
|
+
assert_equal('storefront_api', order.source)
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_reset
|
179
|
+
patch storefront_api.checkout_path(@order),
|
180
|
+
params: {
|
181
|
+
email: 'test@workarea.com',
|
182
|
+
shipping_address: address,
|
183
|
+
billing_address: address,
|
184
|
+
}
|
185
|
+
|
186
|
+
results = JSON.parse(response.body)
|
187
|
+
order = results['order']
|
188
|
+
checkout = results['checkout']
|
189
|
+
|
190
|
+
assert(checkout['addresses']['complete'])
|
191
|
+
started_at = checkout['started_at']
|
192
|
+
assert(started_at.present?)
|
193
|
+
|
194
|
+
get storefront_api.reset_checkout_path(order['id'])
|
195
|
+
checkout = JSON.parse(response.body)['checkout']
|
196
|
+
|
197
|
+
refute(checkout['addresses']['complete'])
|
198
|
+
refute_equal(started_at, checkout['started_at'])
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class ContactsIntegrationTest < IntegrationTest
|
7
|
+
setup :set_contact_params
|
8
|
+
|
9
|
+
def set_contact_params
|
10
|
+
@contact_params = {
|
11
|
+
name: 'Name',
|
12
|
+
email: 'email@example.com',
|
13
|
+
order_id: 'OrderID',
|
14
|
+
subject: :orders,
|
15
|
+
message: 'Message'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_create_inquiries
|
20
|
+
data = @contact_params
|
21
|
+
assert_difference 'Inquiry.count', 1 do
|
22
|
+
post storefront_api.contacts_path, params: data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class EmailSignupsIntegrationTest < IntegrationTest
|
7
|
+
setup :set_content
|
8
|
+
|
9
|
+
def set_content
|
10
|
+
page = Workarea::Storefront::EmailSignupsViewModel.new
|
11
|
+
page.content.blocks.create!(
|
12
|
+
type: :text,
|
13
|
+
data: { text: 'foo bar' }
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_show_email_signups
|
18
|
+
get storefront_api.email_signups_path
|
19
|
+
result = JSON.parse(response.body)
|
20
|
+
|
21
|
+
result_block = result['content_blocks'].first
|
22
|
+
assert_equal('text', result_block['type'])
|
23
|
+
assert_equal('foo bar', result_block['data']['text'])
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_create_email_signups
|
27
|
+
assert_difference 'Email::Signup.count', 2 do
|
28
|
+
post storefront_api.email_signups_path, params: { email: 'email@example.com' }
|
29
|
+
post storefront_api.email_signups_path, params: { email: 'email2@example.com' }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class MenusIntegrationTest < IntegrationTest
|
7
|
+
include Workarea::Storefront::IntegrationTest
|
8
|
+
|
9
|
+
setup :set_navigation_menu
|
10
|
+
|
11
|
+
def set_navigation_menu
|
12
|
+
@menus = ['Men', 'Women', 'Children'].map do |name|
|
13
|
+
first_level = create_taxon(
|
14
|
+
name: name,
|
15
|
+
url: "http://example.com/#{name.downcase}"
|
16
|
+
)
|
17
|
+
|
18
|
+
second_level = first_level.children.create!(name: 'Sale')
|
19
|
+
|
20
|
+
menu = create_menu(taxon: first_level)
|
21
|
+
|
22
|
+
content = Content.for(menu)
|
23
|
+
content.blocks.create!(
|
24
|
+
type: 'taxonomy',
|
25
|
+
data: { 'start' => second_level.id }
|
26
|
+
)
|
27
|
+
|
28
|
+
menu
|
29
|
+
end
|
30
|
+
|
31
|
+
@menu = @menus.first
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_lists_menus
|
35
|
+
get storefront_api.menus_path
|
36
|
+
result = JSON.parse(response.body)
|
37
|
+
|
38
|
+
assert_equal(@menus.count, result['menus'].count)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_shows_menus
|
42
|
+
get storefront_api.menu_path(@menu)
|
43
|
+
result = JSON.parse(response.body)
|
44
|
+
|
45
|
+
result_block = result['content_blocks'].first
|
46
|
+
assert_equal(@menu.id.to_s, result['id'])
|
47
|
+
assert_equal(1, result['content_blocks'].count)
|
48
|
+
assert_equal('taxonomy', result_block['type'])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class OrdersIntegrationTest < IntegrationTest
|
7
|
+
include AuthenticationTest
|
8
|
+
|
9
|
+
setup :set_user
|
10
|
+
setup :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_order
|
18
|
+
@order = begin
|
19
|
+
order = Order.new(user_id: @user.id, email: @user.email)
|
20
|
+
|
21
|
+
product = create_product(
|
22
|
+
name: 'Product One',
|
23
|
+
variants: [{ sku: 'PROD1', regular: 5.to_m }]
|
24
|
+
)
|
25
|
+
order.add_item(product_id: product.id, sku: 'PROD1', quantity: 2)
|
26
|
+
|
27
|
+
product = create_product(
|
28
|
+
name: 'Product Two',
|
29
|
+
variants: [{ sku: 'PROD2', regular: 10.to_m }]
|
30
|
+
)
|
31
|
+
order.add_item(product_id: product.id, sku: 'PROD2', quantity: 1)
|
32
|
+
|
33
|
+
product = create_product(
|
34
|
+
name: 'Product Three',
|
35
|
+
variants: [{ sku: 'PROD3', regular: 20.to_m }]
|
36
|
+
)
|
37
|
+
order.add_item(
|
38
|
+
product_id: product.id,
|
39
|
+
sku: 'PROD3',
|
40
|
+
quantity: 1,
|
41
|
+
customizations: { 'foo' => 'bar' }
|
42
|
+
)
|
43
|
+
|
44
|
+
complete_checkout(
|
45
|
+
order,
|
46
|
+
shipping_service: create_shipping_service(name: 'Express').name,
|
47
|
+
credit_card: {
|
48
|
+
number: '4111111111111111',
|
49
|
+
month: '3',
|
50
|
+
year: Time.now.year + 2,
|
51
|
+
cvv: '123'
|
52
|
+
}
|
53
|
+
|
54
|
+
)
|
55
|
+
|
56
|
+
fulfillment = Fulfillment.find(order.id)
|
57
|
+
fulfillment.ship_items(
|
58
|
+
'1Z',
|
59
|
+
[{ 'id' => order.items.first.id, 'quantity' => 2 }]
|
60
|
+
)
|
61
|
+
|
62
|
+
fulfillment.cancel_items(
|
63
|
+
[{ 'id' => order.items.second.id, 'quantity' => 1 }]
|
64
|
+
)
|
65
|
+
|
66
|
+
order
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_index
|
71
|
+
get storefront_api.orders_path
|
72
|
+
result = JSON.parse(response.body)
|
73
|
+
|
74
|
+
assert_equal(@user.id.to_s, result['user_id'])
|
75
|
+
assert_equal(1, result['orders'].count)
|
76
|
+
assert_equal(@order.id.to_s, result['orders'].last['id'])
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_show
|
80
|
+
get storefront_api.order_path(@order)
|
81
|
+
results = JSON.parse(response.body)
|
82
|
+
order = results['order']
|
83
|
+
|
84
|
+
assert_equal(@user.id.to_s, order['user_id'])
|
85
|
+
assert_equal(@order.id, order['id'])
|
86
|
+
assert(order['placed_at'].present?)
|
87
|
+
|
88
|
+
assert(order['shipping_address'].present?)
|
89
|
+
assert(order['shipping_service'].present?)
|
90
|
+
|
91
|
+
assert(order['billing_address'].present?)
|
92
|
+
assert_equal(1, order['tenders'].count)
|
93
|
+
|
94
|
+
pricing = order['pricing']
|
95
|
+
assert(pricing['shipping_total'].present?)
|
96
|
+
assert(pricing['tax_total'].present?)
|
97
|
+
assert(pricing['subtotal_price'].present?)
|
98
|
+
assert(pricing['total_price'].present?)
|
99
|
+
assert(pricing['paid_amount'].present?)
|
100
|
+
|
101
|
+
assert_equal(3, order['items'].count)
|
102
|
+
assert(order['items'].one? { |i| i['customizations'].present? })
|
103
|
+
|
104
|
+
fulfillment = results['fulfillment']
|
105
|
+
assert(fulfillment['status'].present?)
|
106
|
+
assert_equal(1, fulfillment['packages'].count)
|
107
|
+
assert(fulfillment['packages'].first['tracking_number'].present?)
|
108
|
+
assert_equal(1, fulfillment['packages'].first['items'].count)
|
109
|
+
assert_equal(1, fulfillment['pending_items'].count)
|
110
|
+
assert_equal(1, fulfillment['canceled_items'].count)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class PagesIntegrationTest < IntegrationTest
|
7
|
+
setup :set_page
|
8
|
+
setup :set_taxonomy
|
9
|
+
setup :set_content
|
10
|
+
|
11
|
+
def set_page
|
12
|
+
@page = create_page
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_taxonomy
|
16
|
+
first_level = create_taxon(
|
17
|
+
name: 'First Level'
|
18
|
+
)
|
19
|
+
|
20
|
+
@taxon = first_level.children.create!(navigable: @page)
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_content
|
24
|
+
content = Content.for(@page)
|
25
|
+
content.blocks.create!(
|
26
|
+
area: :default,
|
27
|
+
type: :text,
|
28
|
+
data: { text: 'text' }
|
29
|
+
)
|
30
|
+
content.blocks.create!(
|
31
|
+
area: :default,
|
32
|
+
type: :image,
|
33
|
+
data: { image: asset.id.to_s, alt: 'Foo' }
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def asset
|
38
|
+
@asset ||= create_asset
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_shows_pages
|
42
|
+
get storefront_api.page_path(@page)
|
43
|
+
result = JSON.parse(response.body)
|
44
|
+
|
45
|
+
assert_equal(@page.id.to_s, result['id'])
|
46
|
+
assert_equal(3, result['breadcrumbs'].count)
|
47
|
+
assert_equal(@taxon.id.to_s, result['breadcrumbs'].last['id'])
|
48
|
+
assert_equal(2, result['content_blocks'].count)
|
49
|
+
|
50
|
+
block = result['content_blocks'].last
|
51
|
+
assert(block['data']['image_url'])
|
52
|
+
assert(block['html'])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class PasswordResetsIntegrationTest < Workarea::IntegrationTest
|
7
|
+
def test_forgotten_passwords_emails
|
8
|
+
user = create_user(password: 'p@assword!')
|
9
|
+
|
10
|
+
assert_difference 'User::PasswordReset.count', 1 do
|
11
|
+
post storefront_api.password_resets_path,
|
12
|
+
params: { email: user.email }
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_equal(user, User::PasswordReset.first.user)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Storefront
|
6
|
+
class ProductsIntegrationTest < Workarea::IntegrationTest
|
7
|
+
setup :set_product
|
8
|
+
|
9
|
+
def set_product
|
10
|
+
@product = create_product(
|
11
|
+
filters: { size: %w[Small Medium Large], color: 'Blue' },
|
12
|
+
variants: [{ sku: 'SKU1', details: { color: 'Blue' }, regular: 2.to_m },
|
13
|
+
{ sku: 'SKU2', details: { color: 'Red' }, regular: 3.to_m }],
|
14
|
+
details: { size: 'Small', color: 'Red' },
|
15
|
+
images: [{ image: product_image_file, option: 'Blue' }]
|
16
|
+
)
|
17
|
+
|
18
|
+
# for recommendations
|
19
|
+
create_top_products(results: [{ 'product_id' => create_product.id }])
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_shows_products
|
23
|
+
get storefront_api.product_path(@product)
|
24
|
+
results = JSON.parse(response.body)
|
25
|
+
product = results['product']
|
26
|
+
recommendations = results['recommendations']
|
27
|
+
|
28
|
+
assert_equal(1, recommendations.size)
|
29
|
+
|
30
|
+
assert_equal(@product.id, product['id'])
|
31
|
+
assert_equal(2, product['variants'].count)
|
32
|
+
assert_equal(200.0, product['original_min_price']['cents'])
|
33
|
+
|
34
|
+
processors = product['images'].first['urls'].map { |p| p['type'].to_sym }
|
35
|
+
processors.each do |processor|
|
36
|
+
refute_includes(Workarea.config.api_product_image_jobs_blacklist, processor)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_shows_products_with_sku_selected
|
41
|
+
get storefront_api.product_path(@product, sku: 'SKU2')
|
42
|
+
result = JSON.parse(response.body)['product']
|
43
|
+
|
44
|
+
assert_equal(@product.id, result['id'])
|
45
|
+
assert_equal(300.0, result['original_min_price']['cents'])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|