kaui 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/kaui/kaui.js +118 -11
  3. data/app/assets/stylesheets/kaui/common.less +91 -6
  4. data/app/assets/stylesheets/kaui/payment.less +1 -0
  5. data/app/controllers/kaui/account_children_controller.rb +1 -4
  6. data/app/controllers/kaui/accounts_controller.rb +4 -7
  7. data/app/controllers/kaui/admin_allowed_users_controller.rb +24 -7
  8. data/app/controllers/kaui/admin_tenants_controller.rb +59 -20
  9. data/app/controllers/kaui/audit_logs_controller.rb +3 -2
  10. data/app/controllers/kaui/charges_controller.rb +1 -1
  11. data/app/controllers/kaui/credits_controller.rb +1 -1
  12. data/app/controllers/kaui/home_controller.rb +273 -10
  13. data/app/controllers/kaui/invoice_items_controller.rb +1 -1
  14. data/app/controllers/kaui/invoices_controller.rb +3 -3
  15. data/app/controllers/kaui/payments_controller.rb +5 -3
  16. data/app/controllers/kaui/refunds_controller.rb +2 -2
  17. data/app/controllers/kaui/subscriptions_controller.rb +2 -1
  18. data/app/helpers/kaui/object_helper.rb +4 -0
  19. data/app/helpers/kaui/plugin_helper.rb +36 -20
  20. data/app/helpers/kaui/uuid_helper.rb +9 -0
  21. data/app/models/kaui/admin.rb +3 -1
  22. data/app/models/kaui/admin_tenant.rb +58 -10
  23. data/app/models/kaui/allowed_user.rb +1 -0
  24. data/app/models/kaui/catalog.rb +2 -2
  25. data/app/models/kaui/credit.rb +0 -2
  26. data/app/models/kaui/overdue.rb +5 -5
  27. data/app/views/kaui/account_children/index.html.erb +3 -3
  28. data/app/views/kaui/accounts/_account_info.html.erb +45 -91
  29. data/app/views/kaui/accounts/_billing_info.html.erb +12 -8
  30. data/app/views/kaui/accounts/_parent.html.erb +1 -1
  31. data/app/views/kaui/accounts/_payment_methods.html.erb +1 -1
  32. data/app/views/kaui/accounts/_personal_info.html.erb +74 -0
  33. data/app/views/kaui/accounts/index.html.erb +4 -4
  34. data/app/views/kaui/accounts/show.html.erb +9 -3
  35. data/app/views/kaui/admin_allowed_users/_form.html.erb +38 -10
  36. data/app/views/kaui/admin_tenants/_form_plugin_config.erb +82 -17
  37. data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +11 -3
  38. data/app/views/kaui/admin_tenants/_show_overdue.erb +4 -4
  39. data/app/views/kaui/admin_tenants/_tenant_details.html.erb +7 -1
  40. data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +1 -1
  41. data/app/views/kaui/audit_logs/_show_history_modal.html.erb +1 -1
  42. data/app/views/kaui/audit_logs/index.html.erb +4 -0
  43. data/app/views/kaui/home/_advanced_search_modal.html.erb +80 -0
  44. data/app/views/kaui/home/index.html.erb +18 -5
  45. data/app/views/kaui/invoices/show.html.erb +7 -1
  46. data/app/views/kaui/layouts/kaui_flash.html.erb +14 -3
  47. data/app/views/kaui/layouts/kaui_navbar.html.erb +11 -9
  48. data/app/views/kaui/payments/_form.html.erb +8 -10
  49. data/app/views/kaui/payments/_payment_table.html.erb +40 -37
  50. data/app/views/kaui/payments/index.html.erb +1 -0
  51. data/app/views/kaui/payments/show.html.erb +5 -7
  52. data/app/views/kaui/queues/index.html.erb +22 -4
  53. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +1 -1
  54. data/app/views/kaui/tag_definitions/index.html.erb +1 -1
  55. data/config/routes.rb +2 -0
  56. data/lib/kaui/version.rb +1 -1
  57. data/test/functional/kaui/accounts_controller_test.rb +35 -0
  58. data/test/functional/kaui/admin_allowed_users_controller_test.rb +55 -2
  59. data/test/functional/kaui/admin_tenants_controller_test.rb +67 -6
  60. data/test/functional/kaui/home_controller_test.rb +389 -15
  61. data/test/functional/kaui/subscriptions_controller_test.rb +1 -1
  62. data/test/killbill_test_helper.rb +2 -2
  63. data/test/unit/helpers/kaui/uuid_helper_test.rb +16 -0
  64. data/test/unit/kaui/admin_tenant_test.rb +49 -0
  65. metadata +6 -4
  66. data/test/unit/kaui/uuid_helper_test.rb +0 -10
@@ -43,7 +43,7 @@
43
43
  </td>
44
44
  <% end %>
45
45
  <td>
46
- <span class="subscription-id-popover" data-toggle="popover" data-trigger="hover" title="Subscription ID" data-content="<%= sub.subscription_id %>">
46
+ <span id="<%= sub.subscription_id %>-popover" class="object-id-popover" title="Subscription ID" data-id="<%= sub.subscription_id %>">
47
47
  <%= humanized_subscription_product_category(sub) %>
48
48
  </span>
49
49
  </td>
@@ -22,7 +22,7 @@
22
22
  <tbody>
23
23
  <% @tag_definitions.each do |tag_definition| %>
24
24
  <tr>
25
- <td><%= truncate_uuid(tag_definition.id) %></td>
25
+ <td><%= object_id_popover(tag_definition.id) %></td>
26
26
  <td><%= tag_definition.name %></td>
27
27
  <td><%= tag_definition.description %></td>
28
28
  <td><%= tag_definition.is_system_tag? %></td>
@@ -186,6 +186,8 @@ Kaui::Engine.routes.draw do
186
186
  match '/allowed_users' => 'admin_tenants#allowed_users', :via => :get, :as => 'admin_tenant_allowed_users'
187
187
  match '/catalog_by_effective_date' => 'admin_tenants#catalog_by_effective_date', :via => :get, :as => 'catalog_by_effective_date'
188
188
  match '/suggest_plugin_name' => 'admin_tenants#suggest_plugin_name', :via => :get, :as => 'suggest_plugin_name'
189
+ match '/switch' => 'admin_tenants#switch_tenant', :via => :get, :as => 'switch_tenant'
190
+ match '/:id/download_catalog' => 'admin_tenants#download_catalog_xml', :via => :get, :as => 'download_catalog_xml'
189
191
  end
190
192
  resources :admin_tenants, :only => [ :index, :new, :create, :show ]
191
193
 
@@ -1,3 +1,3 @@
1
1
  module Kaui
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -55,6 +55,41 @@ class Kaui::AccountsControllerTest < Kaui::FunctionalTestHelper
55
55
  assert_not_nil assigns(:payment_methods)
56
56
  end
57
57
 
58
+ test 'should check that overdue state is Good' do
59
+ get :show, :account_id => @account.account_id
60
+ assert_response 200
61
+
62
+ overdue_status_proc_count = 0
63
+
64
+ assert_select 'table' do |tables|
65
+ tables.each do |table|
66
+ assert_select table, 'tr' do |rows|
67
+ rows.each do |row|
68
+ # find overdue status in the response
69
+ is_overdue_state = false
70
+ assert_select row, 'th' do |col|
71
+ is_overdue_state = col[0].text.eql?('Overdue status')
72
+ end
73
+
74
+ # if found
75
+ if is_overdue_state
76
+ overdue_status_proc_count += 1
77
+ assert_select row, 'td' do |col|
78
+ assert_select col, 'span' do |content|
79
+ assert 'Good', content[0].text
80
+ overdue_status_proc_count += 1 if content[0].text.eql?('Good')
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ # assert that overdue state is found with result equal to Good
90
+ assert overdue_status_proc_count, 2
91
+ end
92
+
58
93
  test 'should handle Kill Bill errors when creating account' do
59
94
  post :create
60
95
  assert_redirected_to home_path
@@ -10,10 +10,10 @@ module Kaui
10
10
 
11
11
  test 'should get create local only' do
12
12
  parameters = {
13
- :allowed_user => {:kb_username => 'Albator', :description => 'My french super hero'},
13
+ :allowed_user => {:kb_username => 'Albator', :description => 'My french super hero' },
14
+ :external => '1' ,
14
15
  :password => 'Albator',
15
16
  :roles => nil,
16
- :external => '1'
17
17
  }
18
18
  post :create, parameters
19
19
  assert_equal 'User was successfully configured', flash[:notice]
@@ -156,6 +156,59 @@ module Kaui
156
156
  assert response_path.include?(expected_response_path(au.id)), "#{response_path} is expected to contain #{expected_response_path(au.id)}"
157
157
  end
158
158
 
159
+ test 'should detect if a user is managed externally' do
160
+ allowed_user = {:kb_username => 'Local', :description => 'adding only locally'}
161
+
162
+ # adding only locally will make the user managed externally
163
+ au = Kaui::AllowedUser.new
164
+ au.kb_username = allowed_user[:kb_username]
165
+ au.description = allowed_user[:description]
166
+ au.save!
167
+
168
+ # edit the added user and validate that the checkbox of managed externally is disabled
169
+ get :edit, :id => au.id
170
+ assert_response :success
171
+ assert_select 'form input#external' do |checkbox|
172
+ assert_equal checkbox[0]['disabled'], 'disabled'
173
+ end
174
+
175
+ # create a user that is managed externally
176
+ parameters = {
177
+ :allowed_user => {:kb_username => 'LDAP', :description => 'LDAP' },
178
+ :external => '1'
179
+ }
180
+ post :create, parameters
181
+ assert_equal 'User was successfully configured', flash[:notice]
182
+ assert_response 302
183
+ added_au_id = response_path.gsub('/kaui/admin_allowed_users/','')
184
+
185
+ # edit the added user and validate that the checkbox of managed externally is disabled
186
+ get :edit, :id => added_au_id
187
+ assert_response :success
188
+ assert_select 'form input#external' do |checkbox|
189
+ assert_equal checkbox[0]['disabled'], 'disabled'
190
+ end
191
+
192
+ # create a user that is not managed externally
193
+ parameters = {
194
+ :allowed_user => {:kb_username => 'JDBC', :description => 'Kill Bill JDBC Realm' },
195
+ :external => '0',
196
+ :password => 'jdbc',
197
+ :roles => nil
198
+ }
199
+ post :create, parameters
200
+ assert_equal 'User was successfully configured', flash[:notice]
201
+ assert_response 302
202
+ added_au_id = response_path.gsub('/kaui/admin_allowed_users/','')
203
+
204
+ # edit the added user and validate that the password is not disabled
205
+ get :edit, :id => added_au_id
206
+ assert_response :success
207
+ assert_select 'form input#password' do |input|
208
+ assert_nil input[0]['disabled']
209
+ end
210
+ end
211
+
159
212
  private
160
213
  def expected_response_path(id=nil)
161
214
  "/kaui/admin_allowed_users#{id.nil? ? '' : "/#{id}" }"
@@ -192,7 +192,7 @@ class Kaui::AdminTenantsControllerTest < Kaui::FunctionalTestHelper
192
192
  :states => { '0' => {
193
193
  :name => 'Overdue_test',
194
194
  :external_message => 'Overdue_Test_Ya',
195
- :block_changes => true,
195
+ :is_block_changes => true,
196
196
  :subscription_cancellation_policy => 'NONE',
197
197
  :condition => {
198
198
  :time_since_earliest_unpaid_invoice_equals_or_exceeds => 1,
@@ -285,15 +285,60 @@ class Kaui::AdminTenantsControllerTest < Kaui::FunctionalTestHelper
285
285
  end
286
286
 
287
287
  test 'should suggest a plugin name' do
288
- plugin_anchor = "'<a id=\"suggested\" data-plugin-name=\"killbill-paypal-express\" data-plugin-key=\"paypal\" href=\"#\">killbill-paypal-express</a>'"
288
+ plugin_anchor = "'<a id=\"suggested\" data-plugin-name=\"killbill-paypal-express\" data-plugin-key=\"paypal_express\" data-plugin-type=\"ruby\" href=\"#\">killbill-paypal-express</a>'"
289
+
290
+ # Similar plugin already installed test will run, if there are plugin installed
291
+ installed_plugins = installed_plugins()
292
+ unless installed_plugins.blank?
293
+ installed_plugins.each do |plugin|
294
+ installed_plugin_anchor = "'<a id=\"suggested\" data-plugin-name=\"#{plugin[:plugin_name]}\" data-plugin-key=\"#{plugin[:plugin_key]}\".*href=\"#\">#{plugin[:plugin_name]}</a>'"
295
+
296
+ get :suggest_plugin_name, :plugin_name => plugin[:plugin_name][0, plugin[:plugin_name].length - 1]
297
+ assert_response :success
298
+ assert_match /Similar plugin already installed: #{installed_plugin_anchor}/, JSON[@response.body]['suggestion']
299
+ end
300
+ end
289
301
 
290
- get :validate_plugin_name, :plugin_name => 'paypal-express'
302
+ get :suggest_plugin_name, :plugin_name => 'pypl'
291
303
  assert_response :success
292
- assert_equal JSON[@response.body]['suggestion'], "Similar plugin already installed: #{plugin_anchor}"
304
+ assert_equal "Did you mean #{plugin_anchor}?", JSON[@response.body]['suggestion']
305
+ end
306
+
307
+ test 'should switch tenant' do
308
+ other_tenant = setup_and_create_test_tenant(1)
309
+ other_tenant_kaui = Kaui::Tenant.find_by_kb_tenant_id(other_tenant.tenant_id)
310
+
311
+ get :switch_tenant, :kb_tenant_id => other_tenant.tenant_id
312
+ assert_redirected_to admin_tenant_path(other_tenant_kaui.id)
313
+ assert_equal flash[:notice], "Tenant was switched to #{other_tenant_kaui.name}"
314
+
315
+ # switch back
316
+ tenant_kaui = Kaui::Tenant.find_by_kb_tenant_id(@tenant.tenant_id)
317
+ get :switch_tenant, :kb_tenant_id => @tenant.tenant_id
318
+ assert_redirected_to admin_tenant_path(tenant_kaui.id)
319
+ assert_equal flash[:notice], "Tenant was switched to #{tenant_kaui.name}"
320
+ end
321
+
322
+ test 'should download a catalog' do
323
+ effective_date = '2013-02-08T00:00:00+00:00'
324
+ tenant = create_kaui_tenant
325
+ post :upload_catalog, :id => tenant.id, :catalog => fixture_file_upload('catalog-v1.xml')
326
+
327
+ assert_redirected_to admin_tenant_path(tenant.id)
328
+ assert_equal 'Catalog was successfully uploaded', flash[:notice]
293
329
 
294
- get :validate_plugin_name, :plugin_name => 'pypl'
330
+ get :download_catalog_xml, :effective_date => effective_date, :id => tenant.id
295
331
  assert_response :success
296
- assert_equal JSON[@response.body]['suggestion'], "Did you mean #{plugin_anchor}?"
332
+ assert_equal 'application/xml', @response.header['Content-Type']
333
+ assert_equal "attachment; filename=\"catalog_#{effective_date}.xml\"", @response.header['Content-Disposition']
334
+
335
+ doc = nil
336
+ assert_nothing_raised { doc = Nokogiri::XML(@response.body) { |config| config.strict } }
337
+
338
+ catalog = doc.xpath("//catalog")
339
+ expected_effective_date = Date.parse(catalog[0].search("effectiveDate").text)
340
+
341
+ assert_equal Date.parse(effective_date), expected_effective_date
297
342
  end
298
343
 
299
344
  private
@@ -308,4 +353,20 @@ class Kaui::AdminTenantsControllerTest < Kaui::FunctionalTestHelper
308
353
  assert_equal 'Tenant was successfully configured', flash[:notice]
309
354
  tenant
310
355
  end
356
+
357
+ def installed_plugins
358
+ installed_plugins = []
359
+ nodes_info = KillBillClient::Model::NodesInfo.nodes_info(build_options(@tenant, USERNAME, PASSWORD)) || []
360
+ plugins_info = nodes_info.first.plugins_info || []
361
+ plugins_info.each do |plugin|
362
+ next if plugin.version.nil?
363
+ next if installed_plugins.any? { |p| p[:plugin_name].eql?(plugin.plugin_name) }
364
+ installed_plugins << {
365
+ plugin_key: Kaui::AdminTenant.rewrite_plugin_key(plugin.plugin_key),
366
+ plugin_name: plugin.plugin_name
367
+ }
368
+ end
369
+
370
+ installed_plugins
371
+ end
311
372
  end
@@ -7,27 +7,401 @@ class Kaui::HomeControllerTest < Kaui::FunctionalTestHelper
7
7
  assert_response :success
8
8
  end
9
9
 
10
- test 'should understand search queries' do
11
- get :search, :q => 'John Doe'
12
- assert_redirected_to accounts_path(:q => 'John Doe')
10
+ test 'should understand account search queries' do
11
+ dummy_uuid = SecureRandom.uuid.to_s
12
+ # search defaults using a UUID
13
+ get :search, :q => @account.account_id
14
+ assert_redirected_to account_path(@account.account_id)
13
15
 
14
- get :search, :q => 'de305d54-75b4-431b-adb2-eb6b9e546014'
15
- assert_redirected_to accounts_path(:q => 'de305d54-75b4-431b-adb2-eb6b9e546014')
16
+ # search defaults using a String
17
+ get :search, :q => @account.name
18
+ assert_redirected_to accounts_path(:fast => 0, :q => @account.name)
16
19
 
17
- get :search, :q => 'invoice:de305d54-75b4-431b-adb2-eb6b9e546014'
18
- assert_redirected_to invoice_path(:id => 'de305d54-75b4-431b-adb2-eb6b9e546014')
20
+ # search by ID
21
+ get :search, :q => query_builder('ACCOUNT',@account.account_id, 'ID')
22
+ assert_redirected_to account_path(@account.account_id)
19
23
 
20
- get :search, :q => 'payment:de305d54-75b4-431b-adb2-eb6b9e546014'
21
- assert_redirected_to payment_path(:id => 'de305d54-75b4-431b-adb2-eb6b9e546014')
24
+ # search by ID and fails
25
+ get :search, :q => query_builder('ACCOUNT',dummy_uuid, 'ID')
26
+ assert_redirected_to home_path
27
+ assert_equal "No account matches \"#{dummy_uuid}\"", flash[:error]
22
28
 
23
- get :search, :q => 'invoice:546014'
24
- assert_redirected_to invoice_path(:id => '546014')
29
+ # search by EXTERNAL_KEY
30
+ get :search, :q => query_builder('ACCOUNT',@account.external_key, 'EXTERNAL_KEY')
31
+ assert_redirected_to account_path(@account.account_id)
25
32
 
26
- get :search, :q => 'payment:546014'
27
- assert_redirected_to payment_path(:id => '546014')
33
+ # search by EXTERNAL_KEY and fails
34
+ get :search, :q => query_builder('ACCOUNT',dummy_uuid, 'EXTERNAL_KEY')
35
+ assert_redirected_to home_path
36
+ assert_equal "No account matches \"#{dummy_uuid}\"", flash[:error]
28
37
 
29
- get :search, :q => "transaction:#{@payment.transactions.first.transaction_id}"
30
- assert_redirected_to transaction_path(:id => @payment.transactions.first.transaction_id)
38
+ # search by BLANK only first
39
+ get :search, :q => query_builder('ACCOUNT',@account.name, nil, '1')
40
+ assert_redirected_to account_path(@account.account_id)
31
41
 
42
+ # search by BLANK
43
+ get :search, :q => query_builder('ACCOUNT',@account.name)
44
+ assert_redirected_to accounts_path(:fast => 0, :q => @account.name)
45
+
46
+ # search by BLANK and fails
47
+ get :search, :q => query_builder('ACCOUNT',dummy_uuid)
48
+ assert_redirected_to home_path
49
+ assert_equal "No account matches \"#{dummy_uuid}\"", flash[:error]
50
+ end
51
+
52
+ test 'should understand invoice search queries' do
53
+ # search by ID
54
+ get :search, :q => query_builder('INVOICE',@invoice_item.invoice_id, 'ID')
55
+ assert_redirected_to account_invoice_path(@invoice_item.account_id, @invoice_item.invoice_id)
56
+
57
+ # search by ID and fails
58
+ get :search, :q => query_builder('INVOICE','112', 'ID')
59
+ assert_redirected_to home_path
60
+ assert_equal "No invoice matches \"112\"", flash[:error]
61
+
62
+ # search by EXTERNAL_KEY and fails
63
+ get :search, :q => query_builder('INVOICE','112', 'EXTERNAL_KEY')
64
+ assert_redirected_to home_path
65
+ assert_equal "\"INVOICE\": Search by \"EXTERNAL KEY\" is not supported.", flash[:error]
66
+
67
+ # search by BLANK only first
68
+ get :search, :q => query_builder('INVOICE',@bundle_invoice.invoice_number, nil, '1')
69
+ assert_redirected_to account_invoice_path(@bundle_invoice.account_id, @bundle_invoice.invoice_id)
70
+
71
+ # search by BLANK only first (invoice item)
72
+ get :search, :q => query_builder('INVOICE',@bundle_invoice.items[0].invoice_item_id, nil, '1')
73
+ assert_redirected_to account_invoice_path(@bundle_invoice.account_id, @bundle_invoice.invoice_id)
74
+
75
+ # search by BLANK
76
+ get :search, :q => query_builder('INVOICE',@bundle_invoice.invoice_number)
77
+ assert_redirected_to account_invoices_path(:account_id => @bundle_invoice.account_id, :q => @bundle_invoice.invoice_number, :fast => '0')
78
+
79
+ # search by BLANK and fails
80
+ get :search, :q => query_builder('INVOICE','112')
81
+ assert_redirected_to home_path
82
+ assert_equal "No invoice matches \"112\"", flash[:error]
83
+ end
84
+
85
+ test 'should understand payment search queries' do
86
+ dummy_uuid = SecureRandom.uuid.to_s
87
+ # search by ID
88
+ get :search, :q => query_builder('PAYMENT',@payment.payment_id, 'ID')
89
+ assert_redirected_to account_payment_path(@payment.account_id,@payment.payment_id)
90
+
91
+ # search by ID and fails
92
+ get :search, :q => query_builder('PAYMENT',dummy_uuid, 'ID')
93
+ assert_redirected_to home_path
94
+ assert_equal "No payment matches \"#{dummy_uuid}\"", flash[:error]
95
+
96
+ # search by EXTERNAL_KEY
97
+ get :search, :q => query_builder('PAYMENT',@payment.payment_external_key, 'EXTERNAL_KEY')
98
+ assert_redirected_to account_payment_path(@payment.account_id,@payment.payment_id)
99
+
100
+ # search by EXTERNAL_KEY and fails
101
+ get :search, :q => query_builder('PAYMENT',dummy_uuid, 'EXTERNAL_KEY')
102
+ assert_redirected_to home_path
103
+ assert_equal "No payment matches \"#{dummy_uuid}\"", flash[:error]
104
+
105
+ # search by BLANK only first
106
+ get :search, :q => query_builder('PAYMENT','SUCCESS', nil, '1')
107
+ assert_redirected_to account_payment_path(@payment.account_id,@payment.payment_id)
108
+
109
+ # search by BLANK
110
+ get :search, :q => query_builder('PAYMENT','SUCCESS')
111
+ assert_redirected_to account_payments_path(:account_id => @payment.account_id, :q => 'SUCCESS', :fast => '0')
112
+
113
+ # search by BLANK and fails
114
+ get :search, :q => query_builder('PAYMENT','FAILED')
115
+ assert_redirected_to home_path
116
+ assert_equal "No payment matches \"FAILED\"", flash[:error]
117
+ end
118
+
119
+ test 'should understand transaction search queries' do
120
+ dummy_uuid = SecureRandom.uuid.to_s
121
+ # search by ID
122
+ get :search, :q => query_builder('TRANSACTION',@payment.transactions[0].transaction_id, 'ID')
123
+ assert_redirected_to account_payment_path(@payment.account_id, @payment.payment_id)
124
+
125
+ # search by ID and fails
126
+ get :search, :q => query_builder('TRANSACTION',dummy_uuid, 'ID')
127
+ assert_redirected_to home_path
128
+ assert_equal "No transaction matches \"#{dummy_uuid}\"", flash[:error]
129
+
130
+ # search by EXTERNAL_KEY
131
+ get :search, :q => query_builder('TRANSACTION',@payment.transactions[0].transaction_external_key, 'EXTERNAL_KEY')
132
+ assert_redirected_to account_payment_path(@payment.account_id,@payment.payment_id)
133
+
134
+ # search by EXTERNAL_KEY and fails
135
+ get :search, :q => query_builder('TRANSACTION',dummy_uuid, 'EXTERNAL_KEY')
136
+ assert_redirected_to home_path
137
+ assert_equal "No transaction matches \"#{dummy_uuid}\"", flash[:error]
138
+
139
+ # search by BLANK only first
140
+ get :search, :q => query_builder('TRANSACTION',@payment.transactions[0].transaction_id, nil, '1')
141
+ assert_redirected_to account_payment_path(@payment.account_id, @payment.payment_id)
142
+
143
+ # search by BLANK
144
+ get :search, :q => query_builder('TRANSACTION',@payment.transactions[0].transaction_id)
145
+ assert_redirected_to account_payment_path(@payment.account_id, @payment.payment_id)
146
+
147
+ # search by BLANK and fails
148
+ get :search, :q => query_builder('TRANSACTION','112')
149
+ assert_redirected_to home_path
150
+ assert_equal "No transaction matches \"112\"", flash[:error]
151
+ end
152
+
153
+ test 'should understand bundle search queries' do
154
+ dummy_uuid = SecureRandom.uuid.to_s
155
+ # search by ID
156
+ get :search, :q => query_builder('BUNDLE',@bundle.bundle_id, 'ID')
157
+ assert_redirected_to account_bundles_path(@bundle.account_id)
158
+
159
+ # search by ID and fails
160
+ get :search, :q => query_builder('BUNDLE',dummy_uuid, 'ID')
161
+ assert_redirected_to home_path
162
+ assert_equal "No bundle matches \"#{dummy_uuid}\"", flash[:error]
163
+
164
+ # search by EXTERNAL_KEY
165
+ get :search, :q => query_builder('BUNDLE',@bundle.external_key, 'EXTERNAL_KEY')
166
+ assert_redirected_to account_bundles_path(@bundle.account_id)
167
+
168
+ # search by EXTERNAL_KEY and fails
169
+ get :search, :q => query_builder('BUNDLE',dummy_uuid, 'EXTERNAL_KEY')
170
+ assert_redirected_to home_path
171
+ assert_equal "No bundle matches \"#{dummy_uuid}\"", flash[:error]
172
+
173
+ # search by BLANK only first
174
+ get :search, :q => query_builder('BUNDLE',@bundle.account_id, nil, '1')
175
+ assert_redirected_to account_bundles_path(@bundle.account_id)
176
+
177
+ # search by BLANK
178
+ get :search, :q => query_builder('BUNDLE',@bundle.account_id)
179
+ assert_redirected_to account_bundles_path(@bundle.account_id)
180
+
181
+ # search by BLANK and fails
182
+ get :search, :q => query_builder('BUNDLE',dummy_uuid)
183
+ assert_redirected_to home_path
184
+ assert_equal "No bundle matches \"#{dummy_uuid}\"", flash[:error]
185
+ end
186
+
187
+ test 'should understand credit search queries' do
188
+ dummy_uuid = SecureRandom.uuid.to_s
189
+ credit = create_credit
190
+ # search by ID
191
+ get :search, :q => query_builder('CREDIT',credit.credit_id, 'ID')
192
+ assert_redirected_to account_invoice_path(credit.account_id, credit.invoice_id)
193
+
194
+ # search by ID and fails
195
+ get :search, :q => query_builder('CREDIT',dummy_uuid, 'ID')
196
+ assert_redirected_to home_path
197
+ assert_equal "No credit matches \"#{dummy_uuid}\"", flash[:error]
198
+
199
+ # search by EXTERNAL_KEY and fails
200
+ get :search, :q => query_builder('CREDIT',dummy_uuid, 'EXTERNAL_KEY')
201
+ assert_redirected_to home_path
202
+ assert_equal "\"CREDIT\": Search by \"EXTERNAL KEY\" is not supported.", flash[:error]
203
+
204
+ # search by BLANK only first
205
+ get :search, :q => query_builder('CREDIT',credit.credit_id, nil, '1')
206
+ assert_redirected_to account_invoice_path(credit.account_id, credit.invoice_id)
207
+
208
+ # search by BLANK
209
+ get :search, :q => query_builder('CREDIT',credit.credit_id)
210
+ assert_redirected_to account_invoice_path(credit.account_id, credit.invoice_id)
211
+
212
+ # search by BLANK and fails
213
+ get :search, :q => query_builder('CREDIT',dummy_uuid)
214
+ assert_redirected_to home_path
215
+ assert_equal "No credit matches \"#{dummy_uuid}\"", flash[:error]
216
+ end
217
+
218
+ test 'should understand custom field search queries' do
219
+ dummy_uuid = SecureRandom.uuid.to_s
220
+ custom_field = create_custom_field
221
+ # search by ID
222
+ get :search, :q => query_builder('CUSTOM_FIELD',custom_field[0].custom_field_id, 'ID')
223
+ assert_redirected_to custom_fields_path(:q => custom_field[0].custom_field_id, :fast => '0')
224
+
225
+ # search by ID and fails
226
+ get :search, :q => query_builder('CUSTOM_FIELD',dummy_uuid, 'ID')
227
+ assert_redirected_to home_path
228
+ assert_equal "No custom field matches \"#{dummy_uuid}\"", flash[:error]
229
+
230
+ # search by EXTERNAL_KEY and fails
231
+ get :search, :q => query_builder('CUSTOM_FIELD','test', 'EXTERNAL_KEY')
232
+ assert_redirected_to home_path
233
+ assert_equal "\"CUSTOM FIELD\": Search by \"EXTERNAL KEY\" is not supported.", flash[:error]
234
+
235
+ # search by BLANK only first
236
+ get :search, :q => query_builder('CUSTOM_FIELD','test', nil, '1')
237
+ assert_redirected_to custom_fields_path(:q => 'test', :fast => '1')
238
+
239
+ # search by BLANK
240
+ get :search, :q => query_builder('CUSTOM_FIELD','test')
241
+ assert_redirected_to custom_fields_path(:q => 'test', :fast => '0')
242
+
243
+ # search by BLANK and fails
244
+ get :search, :q => query_builder('CUSTOM_FIELD','test_uui')
245
+ assert_redirected_to home_path
246
+ assert_equal "No custom field matches \"test_uui\"", flash[:error]
247
+ end
248
+
249
+ test 'should understand invoice payment search queries' do
250
+ dummy_uuid = SecureRandom.uuid.to_s
251
+ # search by ID
252
+ get :search, :q => query_builder('INVOICE_PAYMENT', @payment.payment_id, 'ID')
253
+ assert_redirected_to account_payment_path(@payment.account_id, @payment.payment_id)
254
+
255
+ # search by ID and fails
256
+ get :search, :q => query_builder('INVOICE_PAYMENT',dummy_uuid, 'ID')
257
+ assert_redirected_to home_path
258
+ assert_equal "No invoice payment matches \"#{dummy_uuid}\"", flash[:error]
259
+
260
+ # search by EXTERNAL_KEY and fails
261
+ get :search, :q => query_builder('INVOICE_PAYMENT','test', 'EXTERNAL_KEY')
262
+ assert_redirected_to home_path
263
+ assert_equal "\"INVOICE PAYMENT\": Search by \"EXTERNAL KEY\" is not supported.", flash[:error]
264
+
265
+ # search by BLANK only first
266
+ get :search, :q => query_builder('INVOICE_PAYMENT',@payment.payment_id, nil, '1')
267
+ assert_redirected_to account_payment_path(@payment.account_id, @payment.payment_id)
268
+
269
+ # search by BLANK
270
+ get :search, :q => query_builder('INVOICE_PAYMENT',@payment.payment_id)
271
+ assert_redirected_to account_payment_path(@payment.account_id, @payment.payment_id)
272
+
273
+ # search by BLANK and fails
274
+ get :search, :q => query_builder('INVOICE_PAYMENT',dummy_uuid)
275
+ assert_redirected_to home_path
276
+ assert_equal "No invoice payment matches \"#{dummy_uuid}\"", flash[:error]
277
+ end
278
+
279
+ test 'should understand subscription search queries' do
280
+ dummy_uuid = SecureRandom.uuid.to_s
281
+ subscription = @bundle.subscriptions[0]
282
+ # search by ID
283
+ get :search, :q => query_builder('SUBSCRIPTION', subscription.subscription_id, 'ID')
284
+ assert_redirected_to account_bundles_path(subscription.account_id)
285
+
286
+ # search by ID and fails
287
+ get :search, :q => query_builder('SUBSCRIPTION',dummy_uuid, 'ID')
288
+ assert_redirected_to home_path
289
+ assert_equal "No subscription matches \"#{dummy_uuid}\"", flash[:error]
290
+
291
+ # search by EXTERNAL_KEY and fails
292
+ get :search, :q => query_builder('SUBSCRIPTION','test', 'EXTERNAL_KEY')
293
+ assert_redirected_to home_path
294
+ assert_equal "\"SUBSCRIPTION\": Search by \"EXTERNAL KEY\" is not supported.", flash[:error]
295
+
296
+ # search by BLANK only first
297
+ get :search, :q => query_builder('SUBSCRIPTION',subscription.subscription_id, nil, '1')
298
+ assert_redirected_to account_bundles_path(subscription.account_id)
299
+
300
+ # search by BLANK
301
+ get :search, :q => query_builder('SUBSCRIPTION',subscription.subscription_id)
302
+ assert_redirected_to account_bundles_path(subscription.account_id)
303
+
304
+ # search by BLANK and fails
305
+ get :search, :q => query_builder('SUBSCRIPTION',dummy_uuid)
306
+ assert_redirected_to home_path
307
+ assert_equal "No subscription matches \"#{dummy_uuid}\"", flash[:error]
308
+ end
309
+
310
+ test 'should understand tag search queries' do
311
+ dummy_uuid = SecureRandom.uuid.to_s
312
+ tag = create_tag
313
+ # search by ID
314
+ get :search, :q => query_builder('TAG', tag[0].tag_id, 'ID')
315
+ assert_redirected_to tags_path(:q => tag[0].tag_id, :fast => '0')
316
+
317
+ # search by ID and fails
318
+ get :search, :q => query_builder('TAG',dummy_uuid, 'ID')
319
+ assert_redirected_to home_path
320
+ assert_equal "No tag matches \"#{dummy_uuid}\"", flash[:error]
321
+
322
+ # search by EXTERNAL_KEY and fails
323
+ get :search, :q => query_builder('TAG','test', 'EXTERNAL_KEY')
324
+ assert_redirected_to home_path
325
+ assert_equal "\"TAG\": Search by \"EXTERNAL KEY\" is not supported.", flash[:error]
326
+
327
+ # search by BLANK only first
328
+ get :search, :q => query_builder('TAG','account', nil, '1')
329
+ assert_redirected_to tags_path(:q => 'account', :fast => '1')
330
+
331
+ # search by BLANK
332
+ get :search, :q => query_builder('TAG','account')
333
+ assert_redirected_to tags_path(:q => 'account', :fast => '0')
334
+
335
+ # search by BLANK and fails
336
+ get :search, :q => query_builder('TAG',dummy_uuid)
337
+ assert_redirected_to home_path
338
+ assert_equal "No tag matches \"#{dummy_uuid}\"", flash[:error]
339
+ end
340
+
341
+ test 'should understand tag definition search queries' do
342
+ dummy_uuid = SecureRandom.uuid.to_s
343
+ tag_definition = create_account_tag_definition
344
+ # search by ID
345
+ get :search, :q => query_builder('TAG_DEFINITION', tag_definition.id, 'ID')
346
+ assert_redirected_to tag_definitions_path(:q => tag_definition.id, :fast => '0')
347
+
348
+ # search by ID and fails
349
+ get :search, :q => query_builder('TAG_DEFINITION',dummy_uuid, 'ID')
350
+ assert_redirected_to home_path
351
+ assert_equal "No tag definition matches \"#{dummy_uuid}\"", flash[:error]
352
+
353
+ # search by EXTERNAL_KEY and fails
354
+ get :search, :q => query_builder('TAG_DEFINITION','test', 'EXTERNAL_KEY')
355
+ assert_redirected_to home_path
356
+ assert_equal "\"TAG DEFINITION\": Search by \"EXTERNAL KEY\" is not supported.", flash[:error]
357
+
358
+ # search by BLANK only first
359
+ get :search, :q => query_builder('TAG_DEFINITION','account', nil, '1')
360
+ assert_redirected_to tag_definitions_path(:q => 'account', :fast => '1')
361
+
362
+ # search by BLANK
363
+ get :search, :q => query_builder('TAG_DEFINITION','account')
364
+ assert_redirected_to tag_definitions_path(:q => 'account', :fast => '0')
365
+
366
+ # search by BLANK and fails
367
+ get :search, :q => query_builder('TAG_DEFINITION',dummy_uuid)
368
+ assert_redirected_to home_path
369
+ assert_equal "No tag definition matches \"#{dummy_uuid}\"", flash[:error]
370
+ end
371
+
372
+ private
373
+
374
+ def query_builder(object_type, search_for, search_by = nil, fast = nil)
375
+ "FIND:#{object_type} #{(search_by.nil? ? '' : "BY:#{search_by}")} FOR:#{search_for} #{(fast.nil? ? '' : "ONLY_FIRST:#{fast}")}"
376
+ end
377
+
378
+ def create_credit
379
+ credit = KillBillClient::Model::Credit.new(:invoice_id => nil, :account_id => @account.account_id, :credit_amount => 2.22)
380
+ credit = credit.create(true, 'kaui search test', nil, nil, build_options(@tenant, USERNAME, PASSWORD))
381
+ credit
382
+ end
383
+
384
+ def create_custom_field
385
+ custom_field = Kaui::CustomField.new({ object_id: @account.account_id,
386
+ objectType: 'ACCOUNT',
387
+ name: 'test',
388
+ value: 'test' })
389
+ @account.add_custom_field(custom_field, 'kaui search test', nil, nil, build_options(@tenant, USERNAME, PASSWORD))
390
+ end
391
+
392
+ def create_account_tag_definition(name = 'account', description = 'i am an account')
393
+
394
+ tag_definition = Kaui::TagDefinition.new({is_control_tag: false,
395
+ name: name,
396
+ description: description,
397
+ applicable_object_types: ['ACCOUNT']})
398
+
399
+ tag_definition.create('kaui search test', nil, nil, build_options(@tenant, USERNAME, PASSWORD))
400
+ end
401
+
402
+ def create_tag
403
+ tag_definition = create_account_tag_definition
404
+ tags = [tag_definition.id]
405
+ Kaui::Tag.set_for_account(@account.account_id, tags, 'kaui search test', nil, nil, build_options(@tenant, USERNAME, PASSWORD ))
32
406
  end
33
407
  end