workarea-api-admin 4.4.7 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/workarea/api/admin/categories_controller.rb +6 -0
  3. data/app/controllers/workarea/api/admin/content_assets_controller.rb +6 -0
  4. data/app/controllers/workarea/api/admin/content_controller.rb +6 -0
  5. data/app/controllers/workarea/api/admin/discounts_controller.rb +7 -0
  6. data/app/controllers/workarea/api/admin/email_signups_controller.rb +20 -4
  7. data/app/controllers/workarea/api/admin/fulfillments_controller.rb +6 -1
  8. data/app/controllers/workarea/api/admin/inventory_skus_controller.rb +7 -0
  9. data/app/controllers/workarea/api/admin/navigation_menus_controller.rb +7 -0
  10. data/app/controllers/workarea/api/admin/navigation_taxons_controller.rb +7 -0
  11. data/app/controllers/workarea/api/admin/orders_controller.rb +19 -1
  12. data/app/controllers/workarea/api/admin/pages_controller.rb +7 -0
  13. data/app/controllers/workarea/api/admin/payment_profiles_controller.rb +7 -0
  14. data/app/controllers/workarea/api/admin/payment_transactions_controller.rb +7 -0
  15. data/app/controllers/workarea/api/admin/payments_controller.rb +7 -0
  16. data/app/controllers/workarea/api/admin/pricing_skus_controller.rb +7 -0
  17. data/app/controllers/workarea/api/admin/products_controller.rb +11 -4
  18. data/app/controllers/workarea/api/admin/promo_code_lists_controller.rb +7 -0
  19. data/app/controllers/workarea/api/admin/redirects_controller.rb +7 -0
  20. data/app/controllers/workarea/api/admin/releases_controller.rb +7 -0
  21. data/app/controllers/workarea/api/admin/shipping_services_controller.rb +7 -0
  22. data/app/controllers/workarea/api/admin/shippings_controller.rb +7 -0
  23. data/app/controllers/workarea/api/admin/swagger_controller.rb +33 -0
  24. data/app/controllers/workarea/api/admin/tax_categories_controller.rb +2 -0
  25. data/app/controllers/workarea/api/admin/users_controller.rb +28 -14
  26. data/app/models/workarea/api/admin/date_filtering.rb +27 -0
  27. data/lib/workarea/api/admin/engine.rb +11 -0
  28. data/test/documentation/workarea/api/admin/email_signups_documentation_test.rb +14 -2
  29. data/test/documentation/workarea/api/admin/global_functionality_documentation_test.rb +140 -0
  30. data/test/documentation/workarea/api/admin/orders_documentation_test.rb +13 -6
  31. data/test/documentation/workarea/api/admin/users_documentation_test.rb +14 -2
  32. data/test/dummy/config/initializers/session_store.rb +3 -1
  33. data/test/integration/workarea/api/admin/categories_integration_test.rb +32 -0
  34. data/test/integration/workarea/api/admin/content_assets_integration_test.rb +32 -0
  35. data/test/integration/workarea/api/admin/content_integration_test.rb +32 -0
  36. data/test/integration/workarea/api/admin/discounts_integration_test.rb +32 -0
  37. data/test/integration/workarea/api/admin/email_signups_integration_test.rb +38 -1
  38. data/test/integration/workarea/api/admin/fulfillments_integration_test.rb +22 -0
  39. data/test/integration/workarea/api/admin/inventory_skus_integration_test.rb +32 -0
  40. data/test/integration/workarea/api/admin/navigation_menus_integration_test.rb +32 -0
  41. data/test/integration/workarea/api/admin/navigation_taxons_integration_test.rb +32 -0
  42. data/test/integration/workarea/api/admin/orders_integration_test.rb +41 -2
  43. data/test/integration/workarea/api/admin/pages_integration_test.rb +32 -0
  44. data/test/integration/workarea/api/admin/payment_profiles_integration_test.rb +32 -0
  45. data/test/integration/workarea/api/admin/payment_transactions_integration_test.rb +32 -0
  46. data/test/integration/workarea/api/admin/payments_integration_test.rb +32 -0
  47. data/test/integration/workarea/api/admin/pricing_skus_integration_test.rb +32 -0
  48. data/test/integration/workarea/api/admin/products_integration_test.rb +35 -0
  49. data/test/integration/workarea/api/admin/promo_code_lists_integration_test.rb +31 -0
  50. data/test/integration/workarea/api/admin/redirects_integration_test.rb +31 -0
  51. data/test/integration/workarea/api/admin/releases_integration_test.rb +31 -0
  52. data/test/integration/workarea/api/admin/shipping_services_integration_test.rb +31 -0
  53. data/test/integration/workarea/api/admin/shippings_integration_test.rb +31 -0
  54. data/test/integration/workarea/api/admin/tax_categories_integration_test.rb +31 -0
  55. data/test/integration/workarea/api/admin/users_integration_test.rb +44 -1
  56. metadata +5 -3
@@ -36,6 +36,11 @@ module Workarea
36
36
  key :default, 'desc'
37
37
  end
38
38
 
39
+ parameter :updated_at_starts_at
40
+ parameter :updated_at_ends_at
41
+ parameter :created_at_starts_at
42
+ parameter :created_at_ends_at
43
+
39
44
  response 200 do
40
45
  key :description, 'Redirects'
41
46
  schema do
@@ -97,6 +102,8 @@ module Workarea
97
102
  def index
98
103
  @redirects = Navigation::Redirect
99
104
  .all
105
+ .by_updated_at(starts_at: params[:updated_at_starts_at], ends_at: params[:updated_at_ends_at])
106
+ .by_created_at(starts_at: params[:created_at_starts_at], ends_at: params[:created_at_ends_at])
100
107
  .order_by(sort_field => sort_direction)
101
108
  .page(params[:page])
102
109
 
@@ -36,6 +36,11 @@ module Workarea
36
36
  key :default, 'desc'
37
37
  end
38
38
 
39
+ parameter :updated_at_starts_at
40
+ parameter :updated_at_ends_at
41
+ parameter :created_at_starts_at
42
+ parameter :created_at_ends_at
43
+
39
44
  response 200 do
40
45
  key :description, 'Releases'
41
46
  schema do
@@ -97,6 +102,8 @@ module Workarea
97
102
  def index
98
103
  @releases = Release
99
104
  .all
105
+ .by_updated_at(starts_at: params[:updated_at_starts_at], ends_at: params[:updated_at_ends_at])
106
+ .by_created_at(starts_at: params[:created_at_starts_at], ends_at: params[:created_at_ends_at])
100
107
  .order_by(sort_field => sort_direction)
101
108
  .page(params[:page])
102
109
  respond_with releases: @releases
@@ -36,6 +36,11 @@ module Workarea
36
36
  key :default, 'desc'
37
37
  end
38
38
 
39
+ parameter :updated_at_starts_at
40
+ parameter :updated_at_ends_at
41
+ parameter :created_at_starts_at
42
+ parameter :created_at_ends_at
43
+
39
44
  response 200 do
40
45
  key :description, 'Shipping services'
41
46
  schema do
@@ -97,6 +102,8 @@ module Workarea
97
102
  def index
98
103
  @shipping_services = Shipping::Service
99
104
  .all
105
+ .by_updated_at(starts_at: params[:updated_at_starts_at], ends_at: params[:updated_at_ends_at])
106
+ .by_created_at(starts_at: params[:created_at_starts_at], ends_at: params[:created_at_ends_at])
100
107
  .order_by(sort_field => sort_direction)
101
108
  .page(params[:page])
102
109
 
@@ -34,6 +34,11 @@ module Workarea
34
34
  key :default, 'desc'
35
35
  end
36
36
 
37
+ parameter :updated_at_starts_at
38
+ parameter :updated_at_ends_at
39
+ parameter :created_at_starts_at
40
+ parameter :created_at_ends_at
41
+
37
42
  response 200 do
38
43
  key :description, 'Shippings'
39
44
  schema do
@@ -52,6 +57,8 @@ module Workarea
52
57
  def index
53
58
  @shippings = Shipping
54
59
  .all
60
+ .by_updated_at(starts_at: params[:updated_at_starts_at], ends_at: params[:updated_at_ends_at])
61
+ .by_created_at(starts_at: params[:created_at_starts_at], ends_at: params[:created_at_ends_at])
55
62
  .order_by(sort_field => sort_direction)
56
63
  .page(params[:page])
57
64
 
@@ -25,6 +25,39 @@ module Workarea
25
25
  key :consumes, ['application/json']
26
26
  key :produces, ['application/json']
27
27
 
28
+ # define update_at params for re-use later
29
+ parameter :updated_at_starts_at do
30
+ key :name, :updated_at_starts_at
31
+ key :in, :query
32
+ key :description, 'Starting datetime for filtering on last updated'
33
+ key :type, :string
34
+ key :format, 'date-time'
35
+ end
36
+
37
+ parameter :updated_at_ends_at do
38
+ key :name, :updated_at_ends_at
39
+ key :in, :query
40
+ key :description, 'Ending datetime for filtering on last updated'
41
+ key :type, :string
42
+ key :format, 'date-time'
43
+ end
44
+
45
+ parameter :created_at_starts_at do
46
+ key :name, :created_at_starts_at
47
+ key :in, :query
48
+ key :description, 'Starting datetime for filtering on creation date'
49
+ key :type, :string
50
+ key :format, 'date-time'
51
+ end
52
+
53
+ parameter :created_at_ends_at do
54
+ key :name, :created_at_ends_at
55
+ key :in, :query
56
+ key :description, 'Ending datetime for filtering on creation date'
57
+ key :type, :string
58
+ key :format, 'date-time'
59
+ end
60
+
28
61
  security_definition :BasicAuth do
29
62
  key :type, :basic
30
63
  end
@@ -72,6 +72,8 @@ module Workarea
72
72
  def index
73
73
  @tax_categories = Tax::Category
74
74
  .all
75
+ .by_updated_at(starts_at: params[:updated_at_starts_at], ends_at: params[:updated_at_ends_at])
76
+ .by_created_at(starts_at: params[:created_at_starts_at], ends_at: params[:created_at_ends_at])
75
77
  .order_by(sort_field => sort_direction)
76
78
  .page(params[:page])
77
79
 
@@ -36,6 +36,11 @@ module Workarea
36
36
  key :default, 'desc'
37
37
  end
38
38
 
39
+ parameter :updated_at_starts_at
40
+ parameter :updated_at_ends_at
41
+ parameter :created_at_starts_at
42
+ parameter :created_at_ends_at
43
+
39
44
  response 200 do
40
45
  key :description, 'User'
41
46
  schema do
@@ -94,12 +99,19 @@ module Workarea
94
99
  end
95
100
  end
96
101
 
97
-
98
102
  def index
99
- @users = User
100
- .all
101
- .order_by(sort_field => sort_direction)
102
- .page(params[:page])
103
+ criteria = User.all
104
+
105
+ if params[:email].present?
106
+ criteria = criteria.where(email: params[:email])
107
+ end
108
+
109
+ @users =
110
+ criteria
111
+ .by_updated_at(starts_at: params[:updated_at_starts_at], ends_at: params[:updated_at_ends_at])
112
+ .by_created_at(starts_at: params[:created_at_starts_at], ends_at: params[:created_at_ends_at])
113
+ .order_by(sort_field => sort_direction)
114
+ .page(params[:page].presence || 1)
103
115
 
104
116
  respond_with users: @users.to_a.map { |u| api_attributes_for(u) }
105
117
  end
@@ -113,17 +125,17 @@ module Workarea
113
125
  )
114
126
  end
115
127
 
116
- swagger_path '/users/{id}' do
128
+ swagger_path '/users/{id_or_email}' do
117
129
  operation :get do
118
- key :summary, 'Show User by ID'
119
- key :description, 'Returns a user by ID'
130
+ key :summary, 'Show User by ID or Email'
131
+ key :description, 'Returns a user by ID or email address'
120
132
  key :operationId, 'showUser'
121
133
  key :produces, ['application/json']
122
134
 
123
135
  parameter do
124
- key :name, :id
136
+ key :name, :id_or_email
125
137
  key :in, :path
126
- key :description, 'user ID'
138
+ key :description, 'user ID or URL escaped email address'
127
139
  key :required, true
128
140
  key :type, :string
129
141
  end
@@ -145,9 +157,9 @@ module Workarea
145
157
  key :operationId, 'updateUser'
146
158
 
147
159
  parameter do
148
- key :name, :id
160
+ key :name, :id_or_email
149
161
  key :in, :path
150
- key :description, 'ID of user to update'
162
+ key :description, 'ID or email address of user to update'
151
163
  key :required, true
152
164
  key :type, :string
153
165
  end
@@ -203,9 +215,9 @@ module Workarea
203
215
  key :operationId, 'removeUser'
204
216
 
205
217
  parameter do
206
- key :name, :id
218
+ key :name, :id_or_email
207
219
  key :in, :path
208
- key :description, 'ID of user to remove'
220
+ key :description, 'ID or email address of user to remove'
209
221
  key :required, true
210
222
  key :type, :string
211
223
  end
@@ -285,6 +297,8 @@ module Workarea
285
297
 
286
298
  def find_user
287
299
  @user = User.find(params[:id])
300
+ rescue Mongoid::Errors::DocumentNotFound
301
+ @user = User.find_by(email: URI.unescape(params[:id]))
288
302
  end
289
303
 
290
304
  def api_attributes_for(user)
@@ -0,0 +1,27 @@
1
+ module Workarea
2
+ module Api
3
+ module Admin
4
+ module DateFiltering
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ index({ updated_at: 1 })
8
+ index({ created_at: 1 })
9
+
10
+ scope :by_updated_at, ->(starts_at:, ends_at:) do
11
+ query = criteria
12
+ query = query.where(:updated_at.gte => starts_at) unless starts_at.nil?
13
+ query = query.where(:updated_at.lte => ends_at) unless ends_at.nil?
14
+ query
15
+ end
16
+
17
+ scope :by_created_at, ->(starts_at:, ends_at:) do
18
+ query = criteria
19
+ query = query.where(:created_at.gte => starts_at) unless starts_at.nil?
20
+ query = query.where(:created_at.lte => ends_at) unless ends_at.nil?
21
+ query
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -5,9 +5,20 @@ module Workarea
5
5
  include Workarea::Plugin
6
6
  isolate_namespace Workarea::Api::Admin
7
7
 
8
+ # Depending on plugin loading order, to_prepare may cause an autoload of
9
+ # {ApplicationDocument}s so make sure we add this dependency before
10
+ # `config.to_prepare`
11
+ initializer 'workarea.api.admin.date_filtering' do
12
+ Workarea::ApplicationDocument.include(DateFiltering)
13
+ end
14
+
8
15
  config.after_initialize do
9
16
  Workarea::Api::Admin::Swagger.generate!
10
17
  end
18
+
19
+ config.to_prepare do
20
+ ApplicationDocument.include(DateFiltering)
21
+ end
11
22
  end
12
23
  end
13
24
  end
@@ -26,8 +26,8 @@ module Workarea
26
26
  end
27
27
  end
28
28
 
29
- def test_and_document_show
30
- description 'Showing an email signup'
29
+ def test_and_document_show_by_id
30
+ description 'Showing an email signup by ID'
31
31
  route admin_api.email_signup_path(':id')
32
32
 
33
33
  record_request do
@@ -35,6 +35,18 @@ module Workarea
35
35
  assert_equal(200, response.status)
36
36
  end
37
37
  end
38
+
39
+ def test_and_document_show_by_email
40
+ description 'Showing an email signup by email'
41
+ route admin_api.email_signup_path(':email')
42
+
43
+ signup = create_email_signup(email: 'test@workarea.com')
44
+
45
+ record_request do
46
+ get admin_api.email_signup_path(URI.escape(signup.email, '+@.'))
47
+ assert_equal(200, response.status)
48
+ end
49
+ end
38
50
  end
39
51
  end
40
52
  end
@@ -0,0 +1,140 @@
1
+ require 'test_helper'
2
+ require 'workarea/api/documentation_test'
3
+
4
+ module Workarea
5
+ module Api
6
+ module Admin
7
+ class GlobalFunctionalityDocumentationTest < DocumentationTest
8
+ include Workarea::Admin::IntegrationTest
9
+
10
+ resource 'Global Functionality'
11
+
12
+ def test_and_document_locale
13
+ description 'Dealing with locales'
14
+ route admin_api.products_path
15
+ parameter :locale, 'I18n locale key'
16
+
17
+ set_locales(available: [:en, :es], default: :en)
18
+ create_product(name_translations: {
19
+ en: 'Test Product',
20
+ es: 'Producto de prueba'
21
+ }
22
+ )
23
+
24
+ record_request do
25
+ get admin_api.products_path,
26
+ params: {
27
+ locale: 'en'
28
+ }
29
+
30
+ assert_equal(200, response.status)
31
+ end
32
+
33
+ record_request do
34
+ get admin_api.products_path,
35
+ params: {
36
+ locale: 'es'
37
+ }
38
+
39
+ assert_equal(200, response.status)
40
+ end
41
+ end
42
+
43
+ def test_and_document_filtered_by_updated_at
44
+ description 'Filtering by updated time stamp'
45
+ route admin_api.products_path
46
+ parameter :updated_at_starts_at, 'Start of a last updated at date range'
47
+ parameter :updated_at_ends_at, 'End of a last updated at date range'
48
+
49
+ 2.times { create_product }
50
+
51
+ record_request do
52
+ get admin_api.products_path,
53
+ params: {
54
+ updated_at_starts_at: 1.day.ago,
55
+ updated_at_ends_at: 1.day.from_now
56
+ }
57
+
58
+ assert_equal(200, response.status)
59
+ end
60
+ end
61
+
62
+ def test_and_document_filtered_by_created_at
63
+ description 'Filtering by created at time stamp'
64
+ route admin_api.products_path
65
+
66
+ parameter :created_at_starts_at, 'Start of a created at date range'
67
+ parameter :created_at_ends_at, 'End of a created at date range'
68
+
69
+
70
+ 2.times { create_product }
71
+
72
+ record_request do
73
+ get admin_api.products_path,
74
+ params: {
75
+ created_at_starts_at: 1.day.ago,
76
+ created_at_ends_at: 1.day.from_now
77
+ }
78
+ assert_equal(200, response.status)
79
+ end
80
+ end
81
+
82
+ def test_and_document_sorting
83
+ description 'Sorting results'
84
+ route admin_api.products_path
85
+
86
+ parameter :sort_by, 'Field on which to sort (see responses for possible values)'
87
+ parameter :sort_direction, 'Direction to sort (asc or desc)'
88
+
89
+ 2.times { create_product }
90
+
91
+ record_request do
92
+ get admin_api.products_path,
93
+ params: {
94
+ sort_by: 'created_at',
95
+ sort_direction: 'desc',
96
+ }
97
+ assert_equal(200, response.status)
98
+ end
99
+ end
100
+
101
+ def test_and_document_pagination
102
+ description 'Paging results'
103
+ route admin_api.products_path
104
+
105
+ parameter :page, 'Current page'
106
+
107
+ 2.times { create_product }
108
+
109
+ record_request do
110
+ get admin_api.products_path,
111
+ params: {
112
+ page: 1
113
+ }
114
+ assert_equal(200, response.status)
115
+ end
116
+ end
117
+
118
+ def test_and_document_additional_pages
119
+ description 'Retrieving addtional pages of results'
120
+ route admin_api.products_path
121
+
122
+ parameter :page, 'Current page'
123
+
124
+ Workarea.with_config do |config|
125
+ config.per_page = 2
126
+
127
+ 3.times { create_product }
128
+ record_request do
129
+ get admin_api.products_path,
130
+ params: {
131
+ page: 2
132
+ }
133
+ assert_equal(200, response.status)
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
@@ -34,17 +34,24 @@ module Workarea
34
34
  parameter :sort_direction, 'Direction to sort (asc or desc)'
35
35
  parameter :placed_at_greater_than, 'Start of a placed_at date range'
36
36
  parameter :placed_at_less_than, 'End of a placed_at date range'
37
+ parameter :email, 'Email address on the order'
37
38
 
38
39
  3.times { |i| create_placed_order(id: 1000 + i, placed_at: i.weeks.ago) }
39
40
 
41
+ create_placed_order(email: 'test@workarea.com', id: 10000, placed_at: 0.weeks.ago)
42
+ create_placed_order(email: 'test@workarea.com', id: 10001, placed_at: 1.weeks.ago)
43
+ create_placed_order(email: 'test@workarea.com', id: 10002, placed_at: 2.weeks.ago)
44
+
40
45
  record_request do
41
46
  get admin_api.orders_path,
42
- params:
43
- { page: 1,
44
- sort_by: 'created_at',
45
- sort_direction: 'desc',
46
- placed_at_greater_than: 2.weeks.ago - 1.day,
47
- placed_at_less_than: 2.weeks.ago + 1.day }
47
+ params: {
48
+ page: 1,
49
+ sort_by: 'created_at',
50
+ sort_direction: 'desc',
51
+ placed_at_greater_than: 2.weeks.ago - 1.day,
52
+ placed_at_less_than: 2.weeks.ago + 1.day,
53
+ email: 'test@workarea.com'
54
+ }
48
55
 
49
56
  assert_equal(200, response.status)
50
57
  end