kaui 2.1.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +8 -7
  3. data/Rakefile +4 -2
  4. data/app/assets/config/kaui_manifest.js +45 -0
  5. data/app/assets/javascripts/jquery.spin.js +76 -0
  6. data/app/assets/javascripts/kaui/kaui.js +76 -0
  7. data/app/assets/javascripts/kaui_application.js +25 -0
  8. data/app/assets/javascripts/spin.js +76 -0
  9. data/app/assets/stylesheets/bootstrap_and_overrides.scss +240 -0
  10. data/app/assets/stylesheets/kaui/{account.less → account.scss} +4 -0
  11. data/app/assets/stylesheets/kaui/{audit.less → audit.scss} +5 -1
  12. data/app/assets/stylesheets/kaui/{common.less → common.scss} +17 -15
  13. data/app/assets/stylesheets/kaui/{datatable.less → datatable.scss} +6 -3
  14. data/app/assets/stylesheets/kaui/{header.less → header.scss} +16 -12
  15. data/app/assets/stylesheets/kaui/{home.less → home.scss} +7 -4
  16. data/app/assets/stylesheets/kaui/{invoice.less → invoice.scss} +7 -3
  17. data/app/assets/stylesheets/kaui/kaui.scss +265 -0
  18. data/app/assets/stylesheets/kaui/kaui_bootstrap.scss +3 -0
  19. data/app/assets/stylesheets/kaui/{overdue.less → overdue.scss} +3 -1
  20. data/app/assets/stylesheets/kaui/{payment.less → payment.scss} +3 -0
  21. data/app/assets/stylesheets/kaui/{subscription.less → subscription.scss} +4 -1
  22. data/app/assets/stylesheets/kaui/{tags.less → tags.scss} +9 -5
  23. data/app/assets/stylesheets/kaui/timeline.scss +7 -0
  24. data/app/assets/stylesheets/kaui/tooltip.scss +15 -0
  25. data/app/controllers/kaui/account_children_controller.rb +25 -28
  26. data/app/controllers/kaui/account_custom_fields_controller.rb +16 -15
  27. data/app/controllers/kaui/account_emails_controller.rb +28 -25
  28. data/app/controllers/kaui/account_tags_controller.rb +37 -34
  29. data/app/controllers/kaui/account_timelines_controller.rb +38 -33
  30. data/app/controllers/kaui/accounts_controller.rb +268 -250
  31. data/app/controllers/kaui/admin_allowed_users_controller.rb +105 -99
  32. data/app/controllers/kaui/admin_controller.rb +32 -31
  33. data/app/controllers/kaui/admin_tenants_controller.rb +434 -388
  34. data/app/controllers/kaui/audit_logs_controller.rb +86 -83
  35. data/app/controllers/kaui/bundle_tags_controller.rb +24 -20
  36. data/app/controllers/kaui/bundles_controller.rb +96 -82
  37. data/app/controllers/kaui/chargebacks_controller.rb +36 -33
  38. data/app/controllers/kaui/charges_controller.rb +23 -20
  39. data/app/controllers/kaui/credits_controller.rb +28 -25
  40. data/app/controllers/kaui/custom_fields_controller.rb +172 -38
  41. data/app/controllers/kaui/engine_controller.rb +2 -1
  42. data/app/controllers/kaui/engine_controller_util.rb +128 -117
  43. data/app/controllers/kaui/home_controller.rb +230 -217
  44. data/app/controllers/kaui/invoice_items_controller.rb +43 -39
  45. data/app/controllers/kaui/invoice_tags_controller.rb +24 -20
  46. data/app/controllers/kaui/invoices_controller.rb +132 -117
  47. data/app/controllers/kaui/login_proxy_controller.rb +2 -1
  48. data/app/controllers/kaui/payment_methods_controller.rb +102 -94
  49. data/app/controllers/kaui/payments_controller.rb +95 -92
  50. data/app/controllers/kaui/queues_controller.rb +47 -14
  51. data/app/controllers/kaui/refunds_controller.rb +36 -33
  52. data/app/controllers/kaui/registrations_controller.rb +7 -7
  53. data/app/controllers/kaui/role_definitions_controller.rb +17 -14
  54. data/app/controllers/kaui/sessions_controller.rb +7 -4
  55. data/app/controllers/kaui/subscriptions_controller.rb +197 -187
  56. data/app/controllers/kaui/tag_definitions_controller.rb +28 -27
  57. data/app/controllers/kaui/tags_controller.rb +25 -22
  58. data/app/controllers/kaui/tenants_controller.rb +30 -28
  59. data/app/controllers/kaui/transactions_controller.rb +43 -38
  60. data/app/helpers/kaui/account_helper.rb +16 -14
  61. data/app/helpers/kaui/application_helper.rb +8 -3
  62. data/app/helpers/kaui/date_helper.rb +4 -3
  63. data/app/helpers/kaui/home_helper.rb +2 -0
  64. data/app/helpers/kaui/locale_helper.rb +7 -6
  65. data/app/helpers/kaui/money_helper.rb +2 -1
  66. data/app/helpers/kaui/object_helper.rb +11 -10
  67. data/app/helpers/kaui/payment_helper.rb +7 -6
  68. data/app/helpers/kaui/payment_method_helper.rb +3 -2
  69. data/app/helpers/kaui/permissions_helper.rb +9 -9
  70. data/app/helpers/kaui/plugin_helper.rb +25 -23
  71. data/app/helpers/kaui/subscription_helper.rb +27 -29
  72. data/app/helpers/kaui/us_states_helper.rb +7 -6
  73. data/app/helpers/kaui/uuid_helper.rb +8 -6
  74. data/app/models/kaui/ability.rb +19 -12
  75. data/app/models/kaui/account.rb +45 -28
  76. data/app/models/kaui/account_email.rb +23 -20
  77. data/app/models/kaui/account_timeline.rb +5 -1
  78. data/app/models/kaui/admin.rb +65 -64
  79. data/app/models/kaui/admin_tenant.rb +81 -82
  80. data/app/models/kaui/allowed_user.rb +13 -9
  81. data/app/models/kaui/allowed_user_tenant.rb +4 -2
  82. data/app/models/kaui/application_record.rb +2 -0
  83. data/app/models/kaui/audit_log.rb +6 -3
  84. data/app/models/kaui/base.rb +13 -7
  85. data/app/models/kaui/bundle.rb +41 -24
  86. data/app/models/kaui/catalog.rb +118 -113
  87. data/app/models/kaui/chargeback.rb +5 -1
  88. data/app/models/kaui/credit.rb +4 -1
  89. data/app/models/kaui/custom_field.rb +9 -6
  90. data/app/models/kaui/invoice.rb +25 -22
  91. data/app/models/kaui/invoice_item.rb +9 -6
  92. data/app/models/kaui/invoice_payment.rb +49 -54
  93. data/app/models/kaui/killbill_authenticatable.rb +14 -8
  94. data/app/models/kaui/killbill_registerable.rb +7 -0
  95. data/app/models/kaui/overdue.rb +64 -65
  96. data/app/models/kaui/payment.rb +22 -19
  97. data/app/models/kaui/payment_method.rb +48 -39
  98. data/app/models/kaui/payment_state.rb +41 -38
  99. data/app/models/kaui/rails_methods.rb +9 -9
  100. data/app/models/kaui/refund.rb +7 -1
  101. data/app/models/kaui/role_definition.rb +5 -1
  102. data/app/models/kaui/simple_plan.rb +5 -3
  103. data/app/models/kaui/subscription.rb +10 -7
  104. data/app/models/kaui/tag.rb +25 -22
  105. data/app/models/kaui/tag_definition.rb +50 -45
  106. data/app/models/kaui/tenant.rb +6 -5
  107. data/app/models/kaui/transaction.rb +43 -31
  108. data/app/models/kaui/user.rb +10 -16
  109. data/app/models/kaui/user_role.rb +8 -5
  110. data/app/views/kaui/accounts/_billing_info.html.erb +1 -1
  111. data/app/views/kaui/accounts/_form.html.erb +2 -2
  112. data/app/views/kaui/accounts/index.html.erb +2 -0
  113. data/app/views/kaui/admin_allowed_users/_form.html.erb +3 -3
  114. data/app/views/kaui/admin_tenants/_form_catalog_translation.erb +1 -1
  115. data/app/views/kaui/admin_tenants/_form_invoice_template.erb +1 -1
  116. data/app/views/kaui/admin_tenants/_form_invoice_translation.erb +1 -1
  117. data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +11 -5
  118. data/app/views/kaui/admin_tenants/new_catalog.html.erb +2 -2
  119. data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +2 -2
  120. data/app/views/kaui/admin_tenants/new_plan_currency.html.erb +1 -1
  121. data/app/views/kaui/bundles/index.html.erb +1 -1
  122. data/app/views/kaui/bundles/transfer.html.erb +13 -5
  123. data/app/views/kaui/invoices/_invoice_table.html.erb +1 -1
  124. data/app/views/kaui/layouts/kaui_flash.html.erb +24 -0
  125. data/app/views/kaui/layouts/kaui_header.html.erb +19 -2
  126. data/app/views/kaui/payment_methods/_payment_methods_details_table.html.erb +13 -4
  127. data/app/views/kaui/payments/_payment_table.html.erb +21 -11
  128. data/app/views/kaui/payments/index.html.erb +9 -9
  129. data/app/views/kaui/queues/index.html.erb +1 -1
  130. data/app/views/kaui/subscriptions/_cancel_by_date_modal.html.erb +1 -4
  131. data/app/views/kaui/subscriptions/_edit_form.html.erb +1 -1
  132. data/app/views/kaui/subscriptions/_form.html.erb +1 -1
  133. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +3 -3
  134. data/app/views/kaui/subscriptions/edit_bcd.erb +1 -1
  135. data/app/views/kaui/tag_definitions/index.html.erb +2 -2
  136. data/app/views/kaui/tags/index.html.erb +1 -0
  137. data/config/initializers/bootstrap_datepicker_rails.rb +3 -0
  138. data/config/initializers/devise.rb +8 -6
  139. data/config/initializers/js_routes.rb +9 -0
  140. data/config/initializers/kilbill_client_init.rb +13 -0
  141. data/config/initializers/killbill_authenticatable.rb +71 -21
  142. data/config/initializers/killbill_registerable.rb +5 -3
  143. data/config/initializers/time_formats.rb +6 -4
  144. data/config/locales/en.yml +78 -1
  145. data/config/routes.rb +34 -32
  146. data/db/migrate/20130812155313_devise_create_kaui_users.rb +10 -8
  147. data/db/migrate/20150109214021_create_kaui_tenants.rb +10 -8
  148. data/db/migrate/20150112232813_create_kaui_allowed_users.rb +10 -8
  149. data/lib/generators/kaui/install/install_generator.rb +23 -20
  150. data/lib/generators/kaui/install/templates/config/initializers/kaui.rb +3 -1
  151. data/lib/kaui/engine.rb +17 -5
  152. data/lib/kaui/installer/installer.rb +27 -26
  153. data/lib/kaui/version.rb +3 -1
  154. data/lib/kaui.rb +28 -30
  155. data/lib/tasks/kaui_tasks.rake +1 -0
  156. metadata +136 -438
  157. data/app/assets/javascripts/application.js +0 -17
  158. data/app/assets/javascripts/kaui/bootstrap-tweaks.js +0 -172
  159. data/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -44
  160. data/app/assets/stylesheets/kaui/kaui.less +0 -21
  161. data/app/assets/stylesheets/kaui/timeline.less +0 -4
  162. data/config/initializers/asset.rb +0 -1
  163. data/config/initializers/kilbill-client-init.rb +0 -9
  164. data/db/schema.rb +0 -15
  165. data/test/dummy/README.rdoc +0 -261
  166. data/test/dummy/Rakefile +0 -7
  167. data/test/dummy/app/controllers/application_controller.rb +0 -9
  168. data/test/dummy/app/helpers/application_helper.rb +0 -2
  169. data/test/dummy/bin/bundle +0 -3
  170. data/test/dummy/bin/rails +0 -4
  171. data/test/dummy/bin/rake +0 -4
  172. data/test/dummy/bin/setup +0 -38
  173. data/test/dummy/bin/update +0 -29
  174. data/test/dummy/bin/yarn +0 -11
  175. data/test/dummy/config/application.rb +0 -18
  176. data/test/dummy/config/boot.rb +0 -3
  177. data/test/dummy/config/database.yml +0 -27
  178. data/test/dummy/config/environment.rb +0 -5
  179. data/test/dummy/config/environments/development.rb +0 -58
  180. data/test/dummy/config/environments/production.rb +0 -91
  181. data/test/dummy/config/environments/test.rb +0 -49
  182. data/test/dummy/config/initializers/application_controller_renderer.rb +0 -6
  183. data/test/dummy/config/initializers/assets.rb +0 -14
  184. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  185. data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
  186. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  187. data/test/dummy/config/initializers/inflections.rb +0 -16
  188. data/test/dummy/config/initializers/killbill_client.rb +0 -1
  189. data/test/dummy/config/initializers/mime_types.rb +0 -4
  190. data/test/dummy/config/initializers/money.rb +0 -2
  191. data/test/dummy/config/initializers/new_framework_defaults_5_1.rb +0 -14
  192. data/test/dummy/config/initializers/secret_token.rb +0 -7
  193. data/test/dummy/config/initializers/session_store.rb +0 -8
  194. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  195. data/test/dummy/config/locales/en.yml +0 -33
  196. data/test/dummy/config/routes.rb +0 -3
  197. data/test/dummy/config/secrets.yml +0 -32
  198. data/test/dummy/config/symmetric-encryption.yml +0 -135
  199. data/test/dummy/config.ru +0 -4
  200. data/test/dummy/db/schema.rb +0 -52
  201. data/test/dummy/public/404.html +0 -26
  202. data/test/dummy/public/422.html +0 -26
  203. data/test/dummy/public/500.html +0 -25
  204. data/test/dummy/public/favicon.ico +0 -0
  205. data/test/dummy/script/rails +0 -6
  206. data/test/fixtures/SpyCarAdvanced.xml +0 -824
  207. data/test/fixtures/catalog-v1.xml +0 -73
  208. data/test/fixtures/catalog_translation_fr-v1.properties +0 -1
  209. data/test/fixtures/invoice_template-v1.html +0 -100
  210. data/test/fixtures/invoice_translation_fr-v1.properties +0 -23
  211. data/test/fixtures/overdue-v1.xml +0 -49
  212. data/test/fixtures/stripe.yml +0 -2
  213. data/test/functional/kaui/account_children_controller_test.rb +0 -32
  214. data/test/functional/kaui/account_custom_fields_controller_test.rb +0 -29
  215. data/test/functional/kaui/account_emails_controller_test.rb +0 -55
  216. data/test/functional/kaui/account_tags_controller_test.rb +0 -48
  217. data/test/functional/kaui/account_timelines_controller_test.rb +0 -20
  218. data/test/functional/kaui/accounts_controller_test.rb +0 -297
  219. data/test/functional/kaui/admin_allowed_users_controller_test.rb +0 -234
  220. data/test/functional/kaui/admin_controller_test.rb +0 -45
  221. data/test/functional/kaui/admin_tenants_controller_test.rb +0 -352
  222. data/test/functional/kaui/audit_logs_controller_test.rb +0 -71
  223. data/test/functional/kaui/bundle_tags_controller_test.rb +0 -23
  224. data/test/functional/kaui/bundles_controller_test.rb +0 -130
  225. data/test/functional/kaui/chargebacks_controller_test.rb +0 -42
  226. data/test/functional/kaui/charges_controller_test.rb +0 -60
  227. data/test/functional/kaui/credits_controller_test.rb +0 -54
  228. data/test/functional/kaui/custom_fields_controller_test.rb +0 -52
  229. data/test/functional/kaui/functional_test_helper.rb +0 -13
  230. data/test/functional/kaui/functional_test_helper_nosetup.rb +0 -120
  231. data/test/functional/kaui/home_controller_test.rb +0 -407
  232. data/test/functional/kaui/invoice_items_controller_test.rb +0 -82
  233. data/test/functional/kaui/invoices_controller_test.rb +0 -88
  234. data/test/functional/kaui/login_proxy_controller_test.rb +0 -12
  235. data/test/functional/kaui/payment_methods_controller_test.rb +0 -52
  236. data/test/functional/kaui/payments_controller_test.rb +0 -59
  237. data/test/functional/kaui/queues_controller_test.rb +0 -17
  238. data/test/functional/kaui/refunds_controller_test.rb +0 -63
  239. data/test/functional/kaui/registrations_controller_test.rb +0 -49
  240. data/test/functional/kaui/role_definitions_controller_test.rb +0 -47
  241. data/test/functional/kaui/subscriptions_controller_test.rb +0 -194
  242. data/test/functional/kaui/tag_definitions_controller_test.rb +0 -29
  243. data/test/functional/kaui/tags_controller_test.rb +0 -21
  244. data/test/functional/kaui/tenants_controller_test.rb +0 -60
  245. data/test/functional/kaui/transactions_controller_test.rb +0 -90
  246. data/test/integration/kaui/date_helper_integration_test.rb +0 -16
  247. data/test/integration/kaui/integration_test_helper.rb +0 -32
  248. data/test/integration/kaui/navigation_test.rb +0 -43
  249. data/test/killbill_test_helper.rb +0 -219
  250. data/test/test_helper.rb +0 -22
  251. data/test/unit/helpers/kaui/admin_allowed_users_helper_test.rb +0 -6
  252. data/test/unit/helpers/kaui/admin_tenants_helper_test.rb +0 -6
  253. data/test/unit/helpers/kaui/payment_method_helper_test.rb +0 -17
  254. data/test/unit/helpers/kaui/tenants_helper_test.rb +0 -6
  255. data/test/unit/helpers/kaui/uuid_helper_test.rb +0 -16
  256. data/test/unit/kaui/account_email_test.rb +0 -19
  257. data/test/unit/kaui/account_test.rb +0 -14
  258. data/test/unit/kaui/admin_tenant_test.rb +0 -132
  259. data/test/unit/kaui/allowed_user_test.rb +0 -34
  260. data/test/unit/kaui/base_test.rb +0 -23
  261. data/test/unit/kaui/date_helper_test.rb +0 -26
  262. data/test/unit/kaui/invoice_item_test.rb +0 -11
  263. data/test/unit/kaui/invoice_payment_test.rb +0 -42
  264. data/test/unit/kaui/invoice_test.rb +0 -20
  265. data/test/unit/kaui/money_helper_test.rb +0 -16
  266. data/test/unit/kaui/payment_test.rb +0 -42
  267. data/test/unit/kaui/tag_definition_test.rb +0 -11
  268. data/test/unit/kaui/tenant_test.rb +0 -19
  269. /data/app/assets/stylesheets/{application.css → kaui_application.css} +0 -0
@@ -1,297 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Kaui::AccountsControllerTest < Kaui::FunctionalTestHelper
4
-
5
- test 'should get index' do
6
- get :index
7
- assert_response 200
8
- end
9
-
10
- test 'should get index one account' do
11
- parameters = {
12
- :fast => '1',
13
- :q => @account.account_id
14
- }
15
-
16
- get :index, parameters
17
- assert_response :redirect
18
- assert_redirected_to account_path(@account.account_id)
19
-
20
- parameters = {
21
- :fast => '1',
22
- :q => 'THIS_IS_NOT_FOUND_REDIRECT'
23
- }
24
-
25
- get :index, parameters
26
- assert_response :redirect
27
- assert_redirected_to home_path
28
- end
29
-
30
- test 'should list accounts' do
31
- # Test pagination
32
- get :pagination, :format => :json
33
- verify_pagination_results!
34
- end
35
-
36
- test 'should search accounts' do
37
- # Test search
38
- get :pagination, :sSearch => 'foo', :format => :json
39
- verify_pagination_results!
40
- end
41
-
42
- test 'should handle Kill Bill errors when showing account details' do
43
- account_id = SecureRandom.uuid.to_s
44
- get :show, :account_id => account_id
45
- assert_redirected_to home_path
46
- assert_equal "Error while communicating with the Kill Bill server: Object id=#{account_id} type=ACCOUNT doesn't exist!", flash[:error]
47
- end
48
-
49
- test 'should find account by id' do
50
- get :show, :account_id => @account.account_id
51
- assert_response 200
52
- assert_not_nil assigns(:tags)
53
- assert_not_nil assigns(:account_emails)
54
- assert_not_nil assigns(:overdue_state)
55
- assert_not_nil assigns(:payment_methods)
56
- end
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
-
93
- test 'should handle Kill Bill errors when creating account' do
94
- post :create
95
- assert_redirected_to home_path
96
- assert_equal 'Required parameter missing: account', flash[:error]
97
-
98
- external_key = SecureRandom.uuid.to_s
99
- post :create, :account => {:external_key => external_key}
100
- assert_redirected_to account_path(assigns(:account).account_id)
101
-
102
- post :create, :account => {:external_key => external_key}
103
- assert_template :new
104
- assert_equal "Error while creating account: Account already exists for key #{external_key}", flash[:error]
105
- end
106
-
107
- test 'should create account' do
108
- get :new
109
- assert_response 200
110
- assert_not_nil assigns(:account)
111
-
112
- post :create,
113
- :account => {
114
- :name => SecureRandom.uuid.to_s,
115
- :external_key => SecureRandom.uuid.to_s,
116
- :email => SecureRandom.uuid.to_s + '@example.com',
117
- :time_zone => '-06:00',
118
- :country => 'AR',
119
- :is_migrated => '1'
120
- }
121
- assert_redirected_to account_path(assigns(:account).account_id)
122
- assert_equal 'Account was successfully created', flash[:notice]
123
-
124
- assert_equal '-06:00', assigns(:account).time_zone
125
- assert_equal 'AR', assigns(:account).country
126
- assert assigns(:account).is_migrated
127
- end
128
-
129
- test 'should update account' do
130
- get :edit, :account_id => @account.account_id
131
- assert_response 200
132
- assert_not_nil assigns(:account)
133
-
134
- latest_account_attributes = assigns(:account).to_hash
135
- put :update,
136
- :account_id => @account.account_id,
137
- :account => latest_account_attributes.merge({
138
- :name => SecureRandom.uuid.to_s,
139
- :email => SecureRandom.uuid.to_s + '@example.com'
140
- })
141
- assert_redirected_to account_path(assigns(:account).account_id)
142
- assert_equal 'Account successfully updated', flash[:notice]
143
- end
144
-
145
- test 'should be redirected if no payment_method_id is specified when setting default payment method' do
146
- put :set_default_payment_method, :account_id => @account.account_id
147
- assert_redirected_to account_path(@account.account_id)
148
- assert_equal 'Required parameter missing: payment_method_id', flash[:error]
149
- end
150
-
151
- test 'should handle Kill Bill errors when setting default payment method' do
152
- account_id = SecureRandom.uuid.to_s
153
- put :set_default_payment_method, :account_id => account_id, :payment_method_id => @payment_method.payment_method_id
154
- assert_redirected_to home_path
155
- assert_equal "Error while communicating with the Kill Bill server: Object id=#{account_id} type=ACCOUNT doesn't exist!", flash[:error]
156
- end
157
-
158
- test 'should set default payment method' do
159
- put :set_default_payment_method, :account_id => @account.account_id, :payment_method_id => @payment_method.payment_method_id
160
- assert_response 302
161
- end
162
-
163
- test 'should handle Kill Bill errors when paying all invoices' do
164
- account_id = SecureRandom.uuid.to_s
165
- post :pay_all_invoices, :account_id => account_id
166
- assert_redirected_to home_path
167
- assert_equal "Error while communicating with the Kill Bill server: Object id=#{account_id} type=ACCOUNT doesn't exist!", flash[:error]
168
- end
169
-
170
- test 'should pay all invoices' do
171
- post :pay_all_invoices, :account_id => @account.account_id, :is_external_payment => true
172
- assert_response 302
173
- end
174
-
175
- test 'should trigger invoice' do
176
- account = create_account(@tenant)
177
- bundle = create_bundle(account, @tenant)
178
-
179
- parameters = {
180
- :account_id => account.account_id,
181
- :dry_run => '0'
182
- }
183
-
184
- post :trigger_invoice, parameters
185
- assert_equal 'Nothing to generate for target date today', flash[:notice]
186
- assert_redirected_to account_path(account.account_id)
187
-
188
- today_next_month = (Date.parse(@kb_clock['localDate']) + 31).to_s
189
- # generate a dry run invoice
190
- parameters = {
191
- :account_id => account.account_id,
192
- :dry_run => '1',
193
- :target_date => today_next_month
194
- }
195
-
196
- post :trigger_invoice, parameters
197
- assert_response :success
198
- assert_select 'table tbody tr:first' do
199
- assert_select 'td:first', "sports-monthly-evergreen"
200
- assert_select 'td:nth-child(4)', bundle.subscriptions.first.subscription_id
201
- end
202
-
203
-
204
- # persist it
205
- parameters[:dry_run] = '0'
206
- post :trigger_invoice, parameters
207
- assert_response :redirect
208
- assert_match(/Generated invoice.*for target date.*/, flash[:notice])
209
- a_tag = (/<a.href="(?<href>.*?)">/).match(@response.body)
210
- assert_redirected_to a_tag[:href]
211
- end
212
-
213
- test 'should get next_invoice_date' do
214
- get :next_invoice_date, :account_id => @account.account_id
215
- assert_not_nil @response.body
216
- end
217
-
218
- test 'should validate external key if found' do
219
- get :validate_external_key, :external_key => 'foo'
220
- assert_response :success
221
- assert_equal JSON[@response.body]['is_found'], false
222
-
223
- external_key = SecureRandom.uuid.to_s
224
- post :create, :account => {:external_key => external_key}
225
- assert_redirected_to account_path(get_redirected_account_id)
226
-
227
- get :validate_external_key, :external_key => external_key
228
- assert_response :success
229
- assert_equal JSON[@response.body]['is_found'], true
230
- end
231
-
232
- test 'should link and un-link to parent' do
233
- parent = create_account(@tenant)
234
- child = create_account(@tenant)
235
-
236
- # force an error linking a parent account
237
- child.parent_account_id = SecureRandom.uuid.to_s
238
- put :link_to_parent, {
239
- :account => child.to_hash,
240
- :account_id => child.account_id
241
- }
242
- assert_equal "Parent account id not found: #{child.parent_account_id}",flash[:error]
243
- assert_redirected_to account_path(child.account_id)
244
-
245
- # link parent account
246
- child.parent_account_id = parent.account_id
247
- put :link_to_parent, {
248
- :account => child.to_hash,
249
- :account_id => child.account_id
250
- }
251
- assert_equal 'Account successfully updated',flash[:notice]
252
- assert_redirected_to account_path(child.account_id)
253
-
254
- # un-link parent account
255
- delete :link_to_parent, :account_id => child.account_id
256
- assert_equal 'Account successfully updated',flash[:notice]
257
- assert_redirected_to account_path(child.account_id)
258
-
259
- end
260
-
261
- test 'should set email notifications configuration if plugin is available' do
262
-
263
- parameters = {
264
- :configuration => {
265
- :account_id => @account.account_id,
266
- :event_types => ['INVOICE_NOTIFICATION']
267
- }
268
- }
269
-
270
- post :set_email_notifications_configuration, parameters
271
- assert_equal('Email notification plugin is not installed',flash[:error]) unless flash[:error].blank?
272
- assert_equal("Email notifications for account #{@account.account_id} was successfully updated",flash[:notice]) if flash[:error].blank?
273
- assert_redirected_to account_path(@account.account_id)
274
-
275
- end
276
-
277
- test 'should close an account' do
278
- account_to_be_closed = create_account(@tenant)
279
-
280
- delete :destroy, :account_id => account_to_be_closed.account_id
281
- assert_redirected_to account_path(account_to_be_closed.account_id)
282
- assert_equal "Account #{account_to_be_closed.account_id} successfully closed", flash[:notice]
283
-
284
- end
285
-
286
- private
287
-
288
- def get_redirected_account_id
289
-
290
- fields = /<a.href="http:\/.*\/.*?\/(?<id>.*?)">/.match(@response.body) if fields.nil?
291
-
292
- return nil if fields.nil?
293
-
294
- fields.nil? ? nil : fields[:id]
295
- end
296
-
297
- end
@@ -1,234 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Kaui
4
- class AdminAllowedUsersControllerTest < Kaui::FunctionalTestHelper
5
-
6
- test 'should get new' do
7
- post :new
8
- assert_response :success
9
- end
10
-
11
- test 'should get create local only' do
12
- parameters = {
13
- :allowed_user => {:kb_username => 'Albator', :description => 'My french super hero' },
14
- :external => '1' ,
15
- :password => 'Albator',
16
- :roles => nil,
17
- }
18
- post :create, parameters
19
- assert_equal 'User was successfully configured', flash[:notice]
20
- assert_response 302
21
-
22
- # validate redirect path
23
- id = get_allowed_id(@response.body)
24
- assert response_path.include?(expected_response_path(id)), "#{response_path} is expected to contain #{expected_response_path(id)}"
25
- end
26
-
27
- test 'should get create' do
28
- parameters = {
29
- :allowed_user => {:kb_username => 'Albator', :description => 'My french super hero'},
30
- :password => 'Albator',
31
- :roles => nil
32
- }
33
- post :create, parameters
34
- assert_equal 'User was successfully configured', flash[:notice]
35
- assert_response 302
36
-
37
- # validate redirect path
38
- id = get_allowed_id(@response.body)
39
- assert response_path.include?(expected_response_path(id)), "#{response_path} is expected to contain #{expected_response_path(id)}"
40
-
41
- # should return an error that the user already exists
42
- post :create, parameters
43
- assert_equal "User with name #{parameters[:allowed_user][:kb_username]} already exists!", flash[:error]
44
- assert_response :success
45
- end
46
-
47
- test 'should get index' do
48
- get :index
49
- assert_response 200
50
- end
51
-
52
- test 'should get show' do
53
- au = Kaui::AllowedUser.new
54
- au.kb_username = 'Mad Max'
55
- au.description = 'My super hero'
56
- au.save!
57
-
58
- get :show, :id => au.id
59
- assert_response :success
60
- end
61
-
62
- test 'should get edit' do
63
- au = Kaui::AllowedUser.new
64
- au.kb_username = 'Mad Max'
65
- au.description = 'My super hero'
66
- au.save!
67
-
68
- get :edit, :id => au.id
69
-
70
- allowed_username = get_allowed_username
71
- assert_equal allowed_username, au.kb_username
72
- assert_response :success
73
- end
74
-
75
- test 'should update allowed user' do
76
- parameters = {
77
- :allowed_user => {:kb_username => 'Mad Max', :description => 'My super hero'},
78
- :password => 'Batman',
79
- :roles => nil
80
- }
81
- post :create, parameters
82
- assert_equal 'User was successfully configured', flash[:notice]
83
- assert_response :redirect
84
-
85
- # validate redirect path
86
- id = get_allowed_id(@response.body)
87
- assert response_path.include?(expected_response_path(id)), "#{response_path} is expected to contain #{expected_response_path(id)}"
88
-
89
- parameters = {
90
- :id => id,
91
- :allowed_user => { :description => 'An post-apocalyptic super hero' },
92
- :roles => 'one,two'
93
- }
94
-
95
- put :update, parameters
96
- assert_equal 'User was successfully updated', flash[:notice]
97
- assert_response :redirect
98
- # validate redirect path
99
- assert response_path.include?(expected_response_path(id)), "#{response_path} is expected to contain #{expected_response_path(id)}"
100
-
101
- # get the user to verify that the data was actually updated
102
- get :edit, :id => id
103
- description = get_allowed_description
104
- assert_response :success
105
- assert_equal parameters[:allowed_user][:description], description
106
-
107
- # delete created user
108
- delete :destroy, :id => id
109
- assert_equal 'User was successfully deleted', flash[:notice]
110
- assert_response :redirect
111
- # validate redirect path
112
- assert response_path.include?(expected_response_path), "#{response_path} is expected to contain #{expected_response_path}"
113
- end
114
-
115
- test 'should delete allowed user' do
116
- parameters = {
117
- :allowed_user => {:kb_username => 'Batman', :description => 'Everyone wants to be batman'},
118
- :password => 'Batman',
119
- :roles => nil
120
- }
121
- post :create, parameters
122
- assert_equal 'User was successfully configured', flash[:notice]
123
- assert_response :redirect
124
- id = get_allowed_id(@response.body)
125
- # validate redirect path
126
- assert response_path.include?(expected_response_path(id)), "#{response_path} is expected to contain #{expected_response_path(id)}"
127
-
128
- delete :destroy, :id => id
129
- assert_equal 'User was successfully deleted', flash[:notice]
130
- assert_response :redirect
131
- # validate redirect path
132
- assert response_path.include?(expected_response_path), "#{response_path} is expected to contain #{expected_response_path}"
133
-
134
- # should respond with an error if tried to delete again
135
- delete :destroy, :id => id
136
- assert_equal "Error: Couldn't find Kaui::AllowedUser with 'id'=#{id}", flash[:error]
137
- assert_response :redirect
138
- # validate redirect path
139
- assert response_path.include?('/kaui/home'), "#{response_path} is expected to contain '/kaui/home'"
140
- end
141
-
142
- test 'should add tenant' do
143
- allowed_user = {:kb_username => 'Mad Max', :description => 'My super hero'}
144
-
145
- au = Kaui::AllowedUser.new
146
- au.kb_username = allowed_user[:kb_username]
147
- au.description = allowed_user[:description]
148
- au.save!
149
-
150
- allowed_user[:id] = au.id
151
-
152
- put :add_tenant, :allowed_user => allowed_user, :tenant_1 => nil
153
- assert_equal 'Successfully set tenants for user', flash[:notice]
154
- assert_response :redirect
155
- # validate redirect path
156
- assert response_path.include?(expected_response_path(au.id)), "#{response_path} is expected to contain #{expected_response_path(au.id)}"
157
- end
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
-
212
- private
213
- def expected_response_path(id=nil)
214
- "/kaui/admin_allowed_users#{id.nil? ? '' : "/#{id}" }"
215
- end
216
-
217
- def get_allowed_username
218
- get_value_from_input_field('allowed_user_kb_username')
219
- end
220
-
221
- def get_allowed_description
222
- get_value_from_input_field('allowed_user_description')
223
- end
224
-
225
- def get_allowed_id(response_body)
226
- fields = /<form.*action="\/.*\/.*\/(?<id>.*?)".accept-charset=.*method="post">/.match(response_body)
227
- fields = /<a.href="http:\/.*\/.*\/(?<id>.*?)">/.match(response_body) if fields.nil?
228
-
229
- fields.nil? ? nil : fields[:id]
230
- end
231
-
232
-
233
- end
234
- end
@@ -1,45 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Kaui::AdminControllerTest < Kaui::FunctionalTestHelper
4
-
5
- test 'should get index' do
6
- get :index
7
- clock = get_date
8
- assert_not_nil clock
9
- date = DateTime.parse(clock.to_s.gsub('"','')).strftime('%F')
10
- assert_match(/\d{4}-\d{,2}-\d{,2}/, date)
11
- assert_response :success
12
- end
13
-
14
- test 'should set clock' do
15
-
16
- # retrieve current clock from killbill
17
- get :index
18
-
19
- clock = get_date
20
- assert_not_nil clock
21
- date = DateTime.parse(clock.to_s.gsub('"','')).strftime('%F')
22
- assert_match(/\d{4}-\d{,2}-\d{,2}/, date)
23
- assert_response :success
24
-
25
- # update killbill clock
26
- put :set_clock, :commit => 'Submit', :new_date => clock
27
- assert_response :redirect
28
-
29
- # reset killbill clock
30
- put :set_clock, :commit => nil
31
- assert_response :redirect
32
-
33
- end
34
-
35
- private
36
-
37
- def get_date
38
- return nil if @response.nil? || @response.body.nil?
39
-
40
- pattern = Regexp.new('<span.id="kb_clock">(?<clock>.+?)</span>')
41
- data = pattern.match(@response.body)
42
- data.nil? ? nil : data[:clock]
43
- end
44
-
45
- end