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.
Files changed (203) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/README.md +58 -0
  4. data/Rakefile +10 -0
  5. data/app/controllers/workarea/api/storefront/accounts_controller.rb +31 -0
  6. data/app/controllers/workarea/api/storefront/analytics_controller.rb +41 -0
  7. data/app/controllers/workarea/api/storefront/application_controller.rb +65 -0
  8. data/app/controllers/workarea/api/storefront/assets_controller.rb +11 -0
  9. data/app/controllers/workarea/api/storefront/authentication.rb +30 -0
  10. data/app/controllers/workarea/api/storefront/authentication_tokens_controller.rb +50 -0
  11. data/app/controllers/workarea/api/storefront/cart_items_controller.rb +100 -0
  12. data/app/controllers/workarea/api/storefront/carts_controller.rb +47 -0
  13. data/app/controllers/workarea/api/storefront/categories_controller.rb +25 -0
  14. data/app/controllers/workarea/api/storefront/checkouts_controller.rb +117 -0
  15. data/app/controllers/workarea/api/storefront/contacts_controller.rb +20 -0
  16. data/app/controllers/workarea/api/storefront/current_checkout.rb +60 -0
  17. data/app/controllers/workarea/api/storefront/email_signups_controller.rb +15 -0
  18. data/app/controllers/workarea/api/storefront/menus_controller.rb +19 -0
  19. data/app/controllers/workarea/api/storefront/orders_controller.rb +32 -0
  20. data/app/controllers/workarea/api/storefront/pages_controller.rb +14 -0
  21. data/app/controllers/workarea/api/storefront/password_resets_controller.rb +17 -0
  22. data/app/controllers/workarea/api/storefront/products_controller.rb +17 -0
  23. data/app/controllers/workarea/api/storefront/recent_views_controller.rb +46 -0
  24. data/app/controllers/workarea/api/storefront/recommendations_controller.rb +22 -0
  25. data/app/controllers/workarea/api/storefront/saved_addresses_controller.rb +38 -0
  26. data/app/controllers/workarea/api/storefront/saved_credit_cards_controller.rb +54 -0
  27. data/app/controllers/workarea/api/storefront/searches_controller.rb +29 -0
  28. data/app/controllers/workarea/api/storefront/system_content_controller.rb +16 -0
  29. data/app/controllers/workarea/api/storefront/taxons_controller.rb +20 -0
  30. data/app/controllers/workarea/api/storefront/user_activity.rb +36 -0
  31. data/app/controllers/workarea/storefront/application_controller.decorator +12 -0
  32. data/app/helpers/workarea/api/storefront/application_helper.rb +15 -0
  33. data/app/helpers/workarea/api/storefront/checkouts_helper.rb +11 -0
  34. data/app/helpers/workarea/api/storefront/content_blocks_helper.rb +38 -0
  35. data/app/models/workarea/catalog/category.decorator +7 -0
  36. data/app/models/workarea/user/authentication_token.rb +33 -0
  37. data/app/models/workarea/user.decorator +8 -0
  38. data/app/view_models/workarea/api/storefront/search_suggestion_view_model.rb +21 -0
  39. data/app/views/workarea/api/storefront/accounts/_account.json.jbuilder +7 -0
  40. data/app/views/workarea/api/storefront/accounts/create.json.jbuilder +7 -0
  41. data/app/views/workarea/api/storefront/accounts/show.json.jbuilder +1 -0
  42. data/app/views/workarea/api/storefront/assets/show.json.jbuilder +4 -0
  43. data/app/views/workarea/api/storefront/authentication_tokens/_authentication_token.json.jbuilder +2 -0
  44. data/app/views/workarea/api/storefront/authentication_tokens/create.json.jbuilder +1 -0
  45. data/app/views/workarea/api/storefront/authentication_tokens/update.json.jbuilder +1 -0
  46. data/app/views/workarea/api/storefront/cart_items/item.json.jbuilder +9 -0
  47. data/app/views/workarea/api/storefront/carts/index.json.jbuilder +4 -0
  48. data/app/views/workarea/api/storefront/carts/show.json.jbuilder +1 -0
  49. data/app/views/workarea/api/storefront/categories/_category.json.jbuilder +4 -0
  50. data/app/views/workarea/api/storefront/categories/index.json.jbuilder +3 -0
  51. data/app/views/workarea/api/storefront/categories/show.json.jbuilder +30 -0
  52. data/app/views/workarea/api/storefront/checkouts/_shipping_options.json.jbuilder +4 -0
  53. data/app/views/workarea/api/storefront/checkouts/show.json.jbuilder +17 -0
  54. data/app/views/workarea/api/storefront/checkouts/steps/_addresses.json.jbuilder +19 -0
  55. data/app/views/workarea/api/storefront/checkouts/steps/_payment.json.jbuilder +9 -0
  56. data/app/views/workarea/api/storefront/checkouts/steps/_shipping.json.jbuilder +9 -0
  57. data/app/views/workarea/api/storefront/content_blocks/_block.json.jbuilder +7 -0
  58. data/app/views/workarea/api/storefront/email_signups/create.json.jbuilder +2 -0
  59. data/app/views/workarea/api/storefront/email_signups/show.json.jbuilder +4 -0
  60. data/app/views/workarea/api/storefront/facets/_range.json.jbuilder +8 -0
  61. data/app/views/workarea/api/storefront/facets/_terms.json.jbuilder +8 -0
  62. data/app/views/workarea/api/storefront/fulfillments/_fulfillment.json.jbuilder +18 -0
  63. data/app/views/workarea/api/storefront/menus/_menu.json.jbuilder +11 -0
  64. data/app/views/workarea/api/storefront/menus/index.json.jbuilder +3 -0
  65. data/app/views/workarea/api/storefront/menus/show.json.jbuilder +1 -0
  66. data/app/views/workarea/api/storefront/orders/_item.json.jbuilder +26 -0
  67. data/app/views/workarea/api/storefront/orders/_order.json.jbuilder +42 -0
  68. data/app/views/workarea/api/storefront/orders/index.json.jbuilder +4 -0
  69. data/app/views/workarea/api/storefront/orders/show.json.jbuilder +7 -0
  70. data/app/views/workarea/api/storefront/orders/tenders/_credit_card.json.jbuilder +6 -0
  71. data/app/views/workarea/api/storefront/orders/tenders/_store_credit.json.jbuilder +2 -0
  72. data/app/views/workarea/api/storefront/pages/show.json.jbuilder +16 -0
  73. data/app/views/workarea/api/storefront/products/_image_urls.json.jbuilder +5 -0
  74. data/app/views/workarea/api/storefront/products/_product.json.jbuilder +41 -0
  75. data/app/views/workarea/api/storefront/products/show.json.jbuilder +9 -0
  76. data/app/views/workarea/api/storefront/recent_views/show.json.jbuilder +8 -0
  77. data/app/views/workarea/api/storefront/recommendations/show.json.jbuilder +3 -0
  78. data/app/views/workarea/api/storefront/saved_addresses/_saved_address.json.jbuilder +2 -0
  79. data/app/views/workarea/api/storefront/saved_addresses/index.json.jbuilder +4 -0
  80. data/app/views/workarea/api/storefront/saved_addresses/show.json.jbuilder +2 -0
  81. data/app/views/workarea/api/storefront/saved_credit_cards/_card.json.jbuilder +9 -0
  82. data/app/views/workarea/api/storefront/saved_credit_cards/index.json.jbuilder +4 -0
  83. data/app/views/workarea/api/storefront/saved_credit_cards/show.json.jbuilder +2 -0
  84. data/app/views/workarea/api/storefront/searches/index.json.jbuilder +1 -0
  85. data/app/views/workarea/api/storefront/searches/show.json.jbuilder +19 -0
  86. data/app/views/workarea/api/storefront/shared/_address.json.jbuilder +12 -0
  87. data/app/views/workarea/api/storefront/shared/_pagination.json.jbuilder +11 -0
  88. data/app/views/workarea/api/storefront/system_content/show.json.jbuilder +12 -0
  89. data/app/views/workarea/api/storefront/taxons/_taxon.json.jbuilder +10 -0
  90. data/app/views/workarea/api/storefront/taxons/show.json.jbuilder +7 -0
  91. data/app/workers/workarea/remove_authentication_tokens_on_password_changes.rb +19 -0
  92. data/bin/rails +18 -0
  93. data/config/initializers/config.rb +2 -0
  94. data/config/locales/en.yml +13 -0
  95. data/config/routes.rb +41 -0
  96. data/lib/workarea/api/storefront/engine.rb +10 -0
  97. data/lib/workarea/api/storefront.rb +15 -0
  98. data/test/documentation/workarea/api/storefront/accounts_documentation_test.rb +70 -0
  99. data/test/documentation/workarea/api/storefront/analytics_documentation_test.rb +51 -0
  100. data/test/documentation/workarea/api/storefront/assets_documentation_test.rb +32 -0
  101. data/test/documentation/workarea/api/storefront/authentication_documentation_test.rb +84 -0
  102. data/test/documentation/workarea/api/storefront/cart_items_documentation_test.rb +104 -0
  103. data/test/documentation/workarea/api/storefront/carts_documentation_test.rb +121 -0
  104. data/test/documentation/workarea/api/storefront/categories_documentation_test.rb +90 -0
  105. data/test/documentation/workarea/api/storefront/checkouts_documentation_test.rb +142 -0
  106. data/test/documentation/workarea/api/storefront/contacts_documentation_test.rb +39 -0
  107. data/test/documentation/workarea/api/storefront/email_signups_documentation_test.rb +53 -0
  108. data/test/documentation/workarea/api/storefront/menus_documentation_test.rb +67 -0
  109. data/test/documentation/workarea/api/storefront/orders_documentation_test.rb +127 -0
  110. data/test/documentation/workarea/api/storefront/pages_documentation_test.rb +66 -0
  111. data/test/documentation/workarea/api/storefront/password_resets_documentation_test.rb +30 -0
  112. data/test/documentation/workarea/api/storefront/products_documentation_test.rb +64 -0
  113. data/test/documentation/workarea/api/storefront/recent_views_documentation_test.rb +116 -0
  114. data/test/documentation/workarea/api/storefront/recommendations_documentation_test.rb +68 -0
  115. data/test/documentation/workarea/api/storefront/saved_addresses_documentation_test.rb +129 -0
  116. data/test/documentation/workarea/api/storefront/saved_credit_cards_documentation_test.rb +129 -0
  117. data/test/documentation/workarea/api/storefront/searches_documentation_test.rb +88 -0
  118. data/test/documentation/workarea/api/storefront/system_content_documentation_test.rb +66 -0
  119. data/test/documentation/workarea/api/storefront/taxons_documentation_test.rb +37 -0
  120. data/test/documentation/workarea/api/storefront/validation_documentation_test.rb +81 -0
  121. data/test/dummy/Rakefile +7 -0
  122. data/test/dummy/app/assets/config/manifest.js +4 -0
  123. data/test/dummy/app/assets/images/.keep +0 -0
  124. data/test/dummy/app/assets/javascripts/application.js +13 -0
  125. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  126. data/test/dummy/app/controllers/application_controller.rb +3 -0
  127. data/test/dummy/app/controllers/concerns/.keep +0 -0
  128. data/test/dummy/app/helpers/application_helper.rb +2 -0
  129. data/test/dummy/app/jobs/application_job.rb +2 -0
  130. data/test/dummy/app/mailers/.keep +0 -0
  131. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  132. data/test/dummy/app/models/.keep +0 -0
  133. data/test/dummy/app/models/concerns/.keep +0 -0
  134. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  135. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  136. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  137. data/test/dummy/bin/bundle +3 -0
  138. data/test/dummy/bin/rails +4 -0
  139. data/test/dummy/bin/rake +4 -0
  140. data/test/dummy/bin/setup +34 -0
  141. data/test/dummy/bin/update +29 -0
  142. data/test/dummy/config/application.rb +25 -0
  143. data/test/dummy/config/boot.rb +5 -0
  144. data/test/dummy/config/cable.yml +9 -0
  145. data/test/dummy/config/environment.rb +5 -0
  146. data/test/dummy/config/environments/development.rb +55 -0
  147. data/test/dummy/config/environments/production.rb +86 -0
  148. data/test/dummy/config/environments/test.rb +43 -0
  149. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  150. data/test/dummy/config/initializers/assets.rb +11 -0
  151. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  152. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  153. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  154. data/test/dummy/config/initializers/inflections.rb +16 -0
  155. data/test/dummy/config/initializers/mime_types.rb +4 -0
  156. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  157. data/test/dummy/config/initializers/session_store.rb +3 -0
  158. data/test/dummy/config/initializers/workarea.rb +8 -0
  159. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  160. data/test/dummy/config/locales/en.yml +23 -0
  161. data/test/dummy/config/puma.rb +47 -0
  162. data/test/dummy/config/routes.rb +6 -0
  163. data/test/dummy/config/secrets.yml +22 -0
  164. data/test/dummy/config/spring.rb +6 -0
  165. data/test/dummy/config.ru +4 -0
  166. data/test/dummy/db/seeds.rb +2 -0
  167. data/test/dummy/log/.keep +0 -0
  168. data/test/dummy/public/404.html +67 -0
  169. data/test/dummy/public/422.html +67 -0
  170. data/test/dummy/public/500.html +66 -0
  171. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  172. data/test/dummy/public/apple-touch-icon.png +0 -0
  173. data/test/dummy/public/favicon.ico +1 -0
  174. data/test/integration/workarea/api/storefront/accounts_integration_test.rb +49 -0
  175. data/test/integration/workarea/api/storefront/analytics_integration_test.rb +36 -0
  176. data/test/integration/workarea/api/storefront/assets_integration_test.rb +24 -0
  177. data/test/integration/workarea/api/storefront/authentication_integration_test.rb +50 -0
  178. data/test/integration/workarea/api/storefront/authentication_tokens_integration_test.rb +87 -0
  179. data/test/integration/workarea/api/storefront/cart_items_integration_test.rb +149 -0
  180. data/test/integration/workarea/api/storefront/carts_integration_test.rb +114 -0
  181. data/test/integration/workarea/api/storefront/categories_integration_test.rb +84 -0
  182. data/test/integration/workarea/api/storefront/checkouts_integration_test.rb +203 -0
  183. data/test/integration/workarea/api/storefront/contacts_integration_test.rb +28 -0
  184. data/test/integration/workarea/api/storefront/email_signups_integration_test.rb +35 -0
  185. data/test/integration/workarea/api/storefront/menus_integration_test.rb +53 -0
  186. data/test/integration/workarea/api/storefront/orders_integration_test.rb +115 -0
  187. data/test/integration/workarea/api/storefront/pages_integration_test.rb +57 -0
  188. data/test/integration/workarea/api/storefront/password_resets_integration_test.rb +20 -0
  189. data/test/integration/workarea/api/storefront/products_integration_test.rb +50 -0
  190. data/test/integration/workarea/api/storefront/recent_views_integration_test.rb +118 -0
  191. data/test/integration/workarea/api/storefront/recommendations_integration_test.rb +51 -0
  192. data/test/integration/workarea/api/storefront/saved_addresses_integration_test.rb +100 -0
  193. data/test/integration/workarea/api/storefront/saved_credit_cards_integration_test.rb +107 -0
  194. data/test/integration/workarea/api/storefront/searches_integration_test.rb +128 -0
  195. data/test/integration/workarea/api/storefront/system_content_integration_test.rb +35 -0
  196. data/test/integration/workarea/api/storefront/taxons_integration_test.rb +44 -0
  197. data/test/integration/workarea/api/storefront/user_carts_integration_test.rb +55 -0
  198. data/test/models/workarea/user/authentication_token_test.rb +30 -0
  199. data/test/support/authentication_test.rb +25 -0
  200. data/test/support/orders_test.rb +18 -0
  201. data/test/test_helper.rb +10 -0
  202. data/workarea-api-storefront.gemspec +18 -0
  203. metadata +277 -0
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+ require 'workarea/api/documentation_test'
3
+
4
+ module Workarea
5
+ module Api
6
+ module Storefront
7
+ class EmailSignupsDocumentationTest < DocumentationTest
8
+ resource 'Email Signups'
9
+
10
+ setup :set_content
11
+
12
+ def set_content
13
+ page = Workarea::Storefront::EmailSignupsViewModel.new
14
+ page.content.blocks.create!(
15
+ type: :text,
16
+ data: { text: 'Here is some administrated content' }
17
+ )
18
+ end
19
+
20
+ def test_and_document_show
21
+ description 'Showing an email signup content'
22
+ route storefront_api.email_signups_path
23
+ explanation <<-EOS
24
+ This endpoint will return all relevant data for showing an email
25
+ sign up form.
26
+ EOS
27
+
28
+ record_request do
29
+ get storefront_api.email_signups_path
30
+ assert_equal(200, response.status)
31
+ end
32
+ end
33
+
34
+ def test_and_document_create
35
+ description 'Creating an email signup'
36
+ route storefront_api.email_signups_path
37
+ explanation <<-EOS
38
+ Use this endpoint to create an email signup. This will usually be
39
+ forwarded to an Email Service Provider, but Workarea will keep a
40
+ record of it just in case.
41
+ EOS
42
+
43
+ record_request do
44
+ post storefront_api.email_signups_path,
45
+ as: :json,
46
+ params: { email: 'email@example.com' }
47
+ assert_equal(200, response.status)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,67 @@
1
+ require 'test_helper'
2
+ require 'workarea/api/documentation_test'
3
+
4
+ module Workarea
5
+ module Api
6
+ module Storefront
7
+ class MenusDocumentationTest < DocumentationTest
8
+ resource 'Menus'
9
+
10
+ setup :set_navigation_menu
11
+
12
+ def set_navigation_menu
13
+ @menus = ['Men', 'Women', 'Children'].map do |name|
14
+ first_level = create_taxon(
15
+ name: name,
16
+ url: "http://example.com/#{name.downcase}"
17
+ )
18
+
19
+ second_level = first_level.children.create!(name: 'Sale')
20
+
21
+ menu = create_menu(taxon: first_level)
22
+
23
+ content = Content.for(menu)
24
+ content.blocks.create!(
25
+ type: 'taxonomy',
26
+ data: { 'start' => second_level.id }
27
+ )
28
+
29
+ menu
30
+ end
31
+ end
32
+
33
+ def test_and_document_index
34
+ description 'Listing menus'
35
+ route storefront_api.menus_path
36
+ explanation <<-EOS
37
+ In the base HTML storefront, menus are used as the primary top-level
38
+ navigation entry points. Each menu has associated content (composed
39
+ of content blocks) that represent the navigation to be display when
40
+ that menu is selected (usually a hover or a click on a mobile
41
+ device). Each menu points at a particular spot in the taxonomy.
42
+ EOS
43
+
44
+ record_request do
45
+ get storefront_api.menus_path
46
+ assert_equal(200, response.status)
47
+ end
48
+ end
49
+
50
+ def test_and_document_show
51
+ description 'Showing a menu'
52
+ route storefront_api.menu_path(':id')
53
+ explanation <<-EOS
54
+ This endpoint will return all the data used to render a menu. This
55
+ includes the corresponding content, as well a link to where the
56
+ menu points at in the taxonomy.
57
+ EOS
58
+
59
+ record_request do
60
+ get storefront_api.menu_path(@menus.first)
61
+ assert_equal(200, response.status)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,127 @@
1
+ require 'test_helper'
2
+ require 'workarea/api/documentation_test'
3
+
4
+ module Workarea
5
+ module Api
6
+ module Storefront
7
+ class OrdersDocumentationTest < DocumentationTest
8
+ include AuthenticationTest
9
+
10
+ resource 'Orders'
11
+
12
+ setup :set_user
13
+ setup :set_order
14
+
15
+ def set_user
16
+ @user = create_user(
17
+ email: 'sbaker@workarea.com',
18
+ first_name: 'Susan',
19
+ last_name: 'Baker'
20
+ )
21
+ end
22
+
23
+ def set_order
24
+ @order ||= begin
25
+ order = Order.new(user_id: @user.id, email: @user.email)
26
+
27
+ product = create_product(
28
+ name: 'Product One',
29
+ variants: [{ sku: 'PROD1', regular: 5.to_m }]
30
+ )
31
+ order.add_item(product_id: product.id, sku: 'PROD1', quantity: 2)
32
+
33
+ product = create_product(
34
+ name: 'Product Two',
35
+ variants: [{ sku: 'PROD2', regular: 10.to_m }]
36
+ )
37
+ order.add_item(product_id: product.id, sku: 'PROD2', quantity: 1)
38
+
39
+ product = create_product(
40
+ name: 'Product Three',
41
+ variants: [{ sku: 'PROD3', regular: 20.to_m }]
42
+ )
43
+ order.add_item(
44
+ product_id: product.id,
45
+ sku: 'PROD3',
46
+ quantity: 1,
47
+ customizations: { 'foo' => 'bar' }
48
+ )
49
+
50
+ address = {
51
+ first_name: 'Susan',
52
+ last_name: 'Baker',
53
+ street: '350 Fifth Avenue',
54
+ city: 'New York',
55
+ region: 'NY',
56
+ country: 'US',
57
+ postal_code: '10118',
58
+ phone_number: '6465552390'
59
+ }
60
+
61
+ complete_checkout(
62
+ order,
63
+ shipping_address: address,
64
+ billing_address: address,
65
+ shipping_service: create_shipping_service(name: 'Express').name,
66
+ credit_card: {
67
+ number: '4111111111111111',
68
+ month: '3',
69
+ year: Time.now.year + 2,
70
+ cvv: '123'
71
+ }
72
+ )
73
+
74
+ fulfillment = Fulfillment.find(order.id)
75
+ fulfillment.ship_items(
76
+ '1Z',
77
+ [{ 'id' => order.items.first.id, 'quantity' => 2 }]
78
+ )
79
+
80
+ fulfillment.cancel_items(
81
+ [{ 'id' => order.items.second.id, 'quantity' => 1 }]
82
+ )
83
+
84
+ order
85
+ end
86
+ end
87
+
88
+ def test_and_show_index_of_orders
89
+ description "Listing the user's orders"
90
+ route storefront_api.orders_path
91
+ explanation <<-EOS
92
+ This endpoints returns recently placed orders for a customer. Use it
93
+ for showing an order history for the customer.
94
+ EOS
95
+
96
+ auth = @user.authentication_tokens.create!
97
+
98
+ record_request do
99
+ get storefront_api.orders_path,
100
+ headers: { 'HTTP_AUTHORIZATION' => encode_credentials(auth.token) }
101
+
102
+ assert_equal(200, response.status)
103
+ end
104
+ end
105
+
106
+ def test_and_document_show_a_single_order
107
+ description 'Showing an order'
108
+ route storefront_api.order_path(':id')
109
+ explanation <<-EOS
110
+ This endpoint returns everything needed to render an order for a
111
+ customer's order history including order details and fulfillment
112
+ status.
113
+ EOS
114
+
115
+ auth = @user.authentication_tokens.create!
116
+
117
+ record_request do
118
+ get storefront_api.order_path(@order),
119
+ headers: { 'HTTP_AUTHORIZATION' => encode_credentials(auth.token) }
120
+
121
+ assert_equal(200, response.status)
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ 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 PagesDocumentationTest < DocumentationTest
8
+ resource 'Pages'
9
+
10
+ setup :set_page
11
+ setup :set_taxonomy
12
+ setup :set_content
13
+
14
+ def set_page
15
+ @page = create_page(name: 'Summer Lookbook')
16
+ end
17
+
18
+ def set_taxonomy
19
+ first_level = create_taxon(
20
+ name: 'Women',
21
+ url: "#{Workarea.config.host}/women"
22
+ )
23
+
24
+ @taxon = first_level.children.create!(navigable: @page)
25
+ end
26
+
27
+ def set_content
28
+ content = Content.for(@page)
29
+ content.blocks.create!(
30
+ area: :default,
31
+ type: :text,
32
+ data: { text: 'Great new looks for summer' }
33
+ )
34
+ content.blocks.create!(
35
+ area: :default,
36
+ type: :image,
37
+ data: { image: asset.id.to_s, alt: 'splash' }
38
+ )
39
+ content.blocks.create!(
40
+ area: :default,
41
+ type: :text,
42
+ data: { text: 'Pool party fashion' }
43
+ )
44
+ end
45
+
46
+ def asset
47
+ @asset ||= create_asset(name: 'Splash')
48
+ end
49
+
50
+ def test_and_document_show
51
+ description 'Showing a page'
52
+ route storefront_api.page_path(':slug')
53
+ explanation <<-EOS
54
+ This endpoint will return all relevant data for showing a content
55
+ page.
56
+ EOS
57
+
58
+ record_request do
59
+ get storefront_api.page_path(@page)
60
+ assert_equal(200, response.status)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+ require 'workarea/api/documentation_test'
3
+
4
+ module Workarea
5
+ module Api
6
+ module Storefront
7
+ class PasswordResetsDocumentationTest < DocumentationTest
8
+ resource 'Password Resets'
9
+
10
+ def test_and_document_create
11
+ description 'Sending a forgot password email'
12
+ route storefront_api.password_resets_path
13
+ explanation <<-EOS
14
+ This will send a password reset email to the email address if there
15
+ is an account. The email will contain a link to the site where the
16
+ password reset can be completed.
17
+ EOS
18
+
19
+ record_request do
20
+ post storefront_api.password_resets_path,
21
+ as: :json,
22
+ params: { email: create_user.email }
23
+
24
+ assert_equal(200, response.status)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,64 @@
1
+ require 'test_helper'
2
+ require 'workarea/api/documentation_test'
3
+
4
+ module Workarea
5
+ module Api
6
+ module Storefront
7
+ class ProductsDocumentationTest < DocumentationTest
8
+ resource 'Products'
9
+
10
+ setup :set_product
11
+
12
+ def set_product
13
+ @product = create_product(
14
+ name: 'Nice Shirt',
15
+ filters: { size: %w[Small Medium Large], color: 'Blue' },
16
+ variants: [{ sku: 'SKU1', details: { color: 'Blue' }, regular: 2.to_m },
17
+ { sku: 'SKU2', details: { color: 'Red' }, regular: 3.to_m }],
18
+ details: { size: 'Small', color: 'Red' },
19
+ images: [{ image: product_image_file, option: 'Blue' }]
20
+ )
21
+
22
+ # for recommendations
23
+ create_product(
24
+ name: 'Fall Jacket',
25
+ filters: { size: %w[Small Medium Large], color: 'Blue' },
26
+ variants: [{ sku: 'SKU1', details: { color: 'Blue' }, regular: 2.to_m }],
27
+ details: { size: 'Small' },
28
+ images: [{ image: product_image_file, option: 'Blue' }]
29
+ )
30
+ end
31
+
32
+ def test_and_document_show
33
+ description 'Showing a product'
34
+ route storefront_api.product_path(':slug')
35
+ explanation <<-EOS
36
+ This endpoint includes everything you need to render a product
37
+ detail page including, variants, images, and recommendations.
38
+ EOS
39
+
40
+ record_request do
41
+ get storefront_api.product_path(@product)
42
+ assert_equal(200, response.status)
43
+ end
44
+ end
45
+
46
+ def test_and_document_show_with_sku_param
47
+ description 'Showing a product with a specific SKU selected'
48
+ route storefront_api.product_path(':slug')
49
+ parameter 'sku', 'View products details specifically for this SKU'
50
+ explanation <<-EOS
51
+ This demonstrates how to get product details for a specific SKU.
52
+ This will result in pricing, inventory, and images to match the
53
+ storefront logic for that SKU.
54
+ EOS
55
+
56
+ record_request do
57
+ get storefront_api.product_path(@product, sku: 'SKU2')
58
+ assert_equal(200, response.status)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,116 @@
1
+ require 'test_helper'
2
+ require 'workarea/api/documentation_test'
3
+
4
+ module Workarea
5
+ module Api
6
+ module Storefront
7
+ class RecentViewsDocumentationTest < DocumentationTest
8
+ include AuthenticationTest
9
+
10
+ resource 'Recent views'
11
+
12
+ def test_and_document_updating_with_authentication
13
+ description 'Updating recent views with authentication'
14
+ route storefront_api.recent_views_path
15
+ explanation <<-EOS
16
+ Use this endpoint like this to keep a accurate list of recent
17
+ activity by the authenticated customer. Each of the three resources
18
+ being tracked (products, categories, searches) are optional.
19
+ EOS
20
+
21
+ user = create_user
22
+ auth = user.authentication_tokens.create!
23
+
24
+ record_request do
25
+ patch storefront_api.recent_views_path,
26
+ headers: { 'HTTP_AUTHORIZATION' => encode_credentials(auth.token) },
27
+ as: :json,
28
+ params: {
29
+ product_id: '367A8BB9B5',
30
+ category_id: '596e739b021823358aabe9df',
31
+ search: 'shirts'
32
+ }
33
+
34
+ assert_equal(200, response.status)
35
+ end
36
+ end
37
+
38
+ def test_and_document_updating_by_session_id
39
+ description 'Updating recent views with a session_id'
40
+ route storefront_api.recent_views_path
41
+ parameter 'session_id', 'A unique session_id you keep for an anonymous browser'
42
+ explanation <<-EOS
43
+ You can also use this endpoint to maintain a recent activity for an
44
+ anonymous browser. Use a consistent session_id to maintain
45
+ continuity.
46
+ EOS
47
+
48
+ record_request do
49
+ patch storefront_api.recent_views_path,
50
+ as: :json,
51
+ params: {
52
+ session_id: ':session_id',
53
+ product_id: '367A8BB9B5',
54
+ category_id: '596e739b021823358aabe9df',
55
+ search: 'shirts'
56
+ }
57
+
58
+ assert_equal(200, response.status)
59
+ end
60
+ end
61
+
62
+ def test_and_document_showing_by_authentication
63
+ description 'Showing recent views from authentication'
64
+ route storefront_api.recent_views_path
65
+ explanation <<-EOS
66
+ Display recent views based on the currently authenticated customer.
67
+ EOS
68
+
69
+ user = create_user
70
+ auth = user.authentication_tokens.create!
71
+
72
+ product = create_product(name: 'Cool Shirt')
73
+ category = create_category(name: 'Shirts')
74
+ activity = create_user_activity(
75
+ product_ids: [product.id],
76
+ category_ids: [category.id],
77
+ searches: ['shirt']
78
+ )
79
+
80
+ record_request do
81
+ get storefront_api.recent_views_path,
82
+ headers: { 'HTTP_AUTHORIZATION' => encode_credentials(auth.token) }
83
+
84
+ assert_equal(200, response.status)
85
+ end
86
+ end
87
+
88
+ def test_and_document_showing_by_session_id
89
+ description 'Showing recent views with a session_id'
90
+ route storefront_api.recent_views_path
91
+ parameter 'session_id', 'A unique session_id you keep for an anonymous browser'
92
+ explanation <<-EOS
93
+ Display recent views based on a session_id you've kept for an
94
+ anonymous browser (as opposed to displaying them based on
95
+ authentication).
96
+ EOS
97
+
98
+ product = create_product(name: 'Cool Shirt')
99
+ category = create_category(name: 'Shirts')
100
+ activity = create_user_activity(
101
+ product_ids: [product.id],
102
+ category_ids: [category.id],
103
+ searches: ['shirt']
104
+ )
105
+
106
+ record_request do
107
+ get storefront_api.recent_views_path,
108
+ params: { session_id: activity.id }
109
+
110
+ assert_equal(200, response.status)
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,68 @@
1
+ require 'test_helper'
2
+ require 'workarea/api/documentation_test'
3
+
4
+ module Workarea
5
+ module Api
6
+ module Storefront
7
+ class RecommendationsDocumentationTest < DocumentationTest
8
+ include AuthenticationTest
9
+
10
+ resource 'Personalized Recommendations'
11
+
12
+ setup :set_auth
13
+ setup :set_products
14
+ setup :set_user_activity
15
+
16
+ def set_auth
17
+ user = create_user
18
+ @auth = user.authentication_tokens.create!
19
+ end
20
+
21
+ def set_products
22
+ 10.times { create_product }
23
+
24
+ top_products = Catalog::Product.sample(10).map { |p| { 'product_id' => p.id } }
25
+ create_top_products(results: top_products)
26
+ end
27
+
28
+ def set_user_activity
29
+ @activity = create_user_activity
30
+ end
31
+
32
+ def test_and_document_showing_by_authentication
33
+ description 'Showing recommendations with authentication'
34
+ route storefront_api.recommendations_path
35
+ explanation <<-EOS
36
+ Display personalized recommendations based on the currently
37
+ authenticated customer.
38
+ EOS
39
+
40
+ record_request do
41
+ get storefront_api.recommendations_path,
42
+ headers: { 'HTTP_AUTHORIZATION' => encode_credentials(@auth.token) }
43
+
44
+ assert_equal(200, response.status)
45
+ end
46
+ end
47
+
48
+ def test_and_document_showing_by_session_id
49
+ description 'Showing recommendations with a session ID'
50
+ route storefront_api.recommendations_path
51
+ parameter 'session_id', 'A unique session_id you keep for an anonymous browser'
52
+ explanation <<-EOS
53
+ Display personalized recommendations based on a session ID that
54
+ you've maintained for an anonymous browser (as opposed to
55
+ authentication).
56
+ EOS
57
+
58
+ record_request do
59
+ get storefront_api.recommendations_path,
60
+ params: { session_id: @activity.id }
61
+
62
+ assert_equal(200, response.status)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end