kaui 0.15.5 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -37
  3. data/app/assets/javascripts/application.js +1 -2
  4. data/app/assets/javascripts/kaui/kaui.js +87 -0
  5. data/app/assets/stylesheets/{bootstrap_and_overrides.less → bootstrap_and_overrides.css.less} +6 -6
  6. data/app/assets/stylesheets/kaui/account.less +20 -0
  7. data/app/assets/stylesheets/kaui/kaui.less +3 -0
  8. data/app/assets/stylesheets/kaui/overdue.less +9 -0
  9. data/app/assets/stylesheets/kaui/payment.less +10 -0
  10. data/app/controllers/kaui/account_children_controller.rb +50 -0
  11. data/app/controllers/kaui/account_tags_controller.rb +4 -3
  12. data/app/controllers/kaui/account_timelines_controller.rb +1 -3
  13. data/app/controllers/kaui/accounts_controller.rb +160 -17
  14. data/app/controllers/kaui/admin_allowed_users_controller.rb +11 -5
  15. data/app/controllers/kaui/admin_controller.rb +16 -3
  16. data/app/controllers/kaui/admin_tenants_controller.rb +56 -8
  17. data/app/controllers/kaui/bundle_tags_controller.rb +4 -3
  18. data/app/controllers/kaui/bundles_controller.rb +12 -6
  19. data/app/controllers/kaui/charges_controller.rb +4 -1
  20. data/app/controllers/kaui/credits_controller.rb +1 -0
  21. data/app/controllers/kaui/engine_controller.rb +8 -11
  22. data/app/controllers/kaui/engine_controller_util.rb +30 -18
  23. data/app/controllers/kaui/invoices_controller.rb +19 -8
  24. data/app/controllers/kaui/payment_methods_controller.rb +20 -1
  25. data/app/controllers/kaui/payments_controller.rb +15 -9
  26. data/app/controllers/kaui/queues_controller.rb +8 -1
  27. data/app/controllers/kaui/refunds_controller.rb +7 -4
  28. data/app/controllers/kaui/registrations_controller.rb +15 -1
  29. data/app/controllers/kaui/sessions_controller.rb +2 -1
  30. data/app/controllers/kaui/subscriptions_controller.rb +27 -5
  31. data/app/controllers/kaui/tenants_controller.rb +1 -1
  32. data/app/controllers/kaui/transactions_controller.rb +11 -1
  33. data/app/helpers/kaui/account_helper.rb +7 -0
  34. data/app/helpers/kaui/date_helper.rb +30 -2
  35. data/app/helpers/kaui/locale_helper.rb +20 -0
  36. data/app/helpers/kaui/locale_helper.yml +581 -0
  37. data/app/helpers/kaui/payment_helper.rb +12 -0
  38. data/app/helpers/kaui/subscription_helper.rb +3 -3
  39. data/app/helpers/kaui/us_states_helper.rb +11 -0
  40. data/app/helpers/kaui/us_states_helper.yml +103 -0
  41. data/app/models/kaui/ability.rb +1 -1
  42. data/app/models/kaui/account.rb +1 -1
  43. data/app/models/kaui/admin.rb +11 -9
  44. data/app/models/kaui/allowed_user.rb +3 -4
  45. data/app/models/kaui/allowed_user_tenant.rb +2 -2
  46. data/app/models/kaui/application_record.rb +5 -0
  47. data/app/models/kaui/base.rb +1 -1
  48. data/app/models/kaui/bundle.rb +2 -2
  49. data/app/models/kaui/catalog.rb +4 -24
  50. data/app/models/kaui/chargeback.rb +0 -23
  51. data/app/models/kaui/credit.rb +0 -4
  52. data/app/models/kaui/invoice_item.rb +0 -4
  53. data/app/models/kaui/invoice_payment.rb +16 -21
  54. data/app/models/kaui/killbill_authenticatable.rb +2 -2
  55. data/app/models/kaui/overdue.rb +4 -0
  56. data/app/models/kaui/payment.rb +0 -3
  57. data/app/models/kaui/refund.rb +0 -5
  58. data/app/models/kaui/tenant.rb +1 -2
  59. data/app/models/kaui/user.rb +1 -3
  60. data/app/views/kaui/account_children/index.html.erb +47 -0
  61. data/app/views/kaui/accounts/_account_info.html.erb +16 -1
  62. data/app/views/kaui/accounts/_billing_info.html.erb +18 -9
  63. data/app/views/kaui/accounts/_form.html.erb +26 -18
  64. data/app/views/kaui/accounts/_link_parent_modal.html.erb +34 -0
  65. data/app/views/kaui/accounts/_parent.html.erb +16 -0
  66. data/app/views/kaui/accounts/_payment_methods.html.erb +3 -1
  67. data/app/views/kaui/accounts/index.html.erb +17 -2
  68. data/app/views/kaui/accounts/show.html.erb +6 -0
  69. data/app/views/kaui/admin/index.html.erb +1 -1
  70. data/app/views/kaui/admin_allowed_users/_form.html.erb +22 -0
  71. data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +12 -9
  72. data/app/views/kaui/admin_tenants/_show_catalog_xml.erb +1 -1
  73. data/app/views/kaui/admin_tenants/_show_overdue.erb +10 -0
  74. data/app/views/kaui/admin_tenants/new.html.erb +8 -4
  75. data/app/views/kaui/admin_tenants/new_catalog.html.erb +16 -4
  76. data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +25 -5
  77. data/app/views/kaui/bundles/index.html.erb +3 -0
  78. data/app/views/kaui/chargebacks/_form.html.erb +1 -1
  79. data/app/views/kaui/charges/_form.html.erb +11 -0
  80. data/app/views/kaui/credits/_form.html.erb +2 -2
  81. data/app/views/kaui/custom_fields/_list_bar.html.erb +12 -0
  82. data/app/views/kaui/invoice_items/_edit_form.html.erb +1 -1
  83. data/app/views/kaui/invoices/_invoice_table.html.erb +23 -18
  84. data/app/views/kaui/invoices/show.html.erb +9 -1
  85. data/app/views/kaui/layouts/kaui_navbar.html.erb +4 -1
  86. data/app/views/kaui/payment_methods/_form.html.erb +6 -0
  87. data/app/views/kaui/payment_methods/_payment_methods_table.html.erb +3 -1
  88. data/app/views/kaui/payment_methods/_plugin_properties.html.erb +77 -0
  89. data/app/views/kaui/payments/_form.html.erb +1 -1
  90. data/app/views/kaui/payments/_payment_table.html.erb +24 -15
  91. data/app/views/kaui/payments/show.html.erb +4 -1
  92. data/app/views/kaui/queues/index.html.erb +4 -4
  93. data/app/views/kaui/refunds/_form.html.erb +3 -2
  94. data/app/views/kaui/subscriptions/_edit_form.html.erb +3 -3
  95. data/app/views/kaui/subscriptions/_form.html.erb +3 -0
  96. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +1 -1
  97. data/app/views/kaui/transactions/_control_plugin_names.html.erb +66 -0
  98. data/app/views/kaui/transactions/_form.html.erb +7 -1
  99. data/config/initializers/asset.rb +1 -0
  100. data/config/initializers/devise.rb +13 -7
  101. data/config/initializers/killbill_authenticatable.rb +1 -1
  102. data/config/locales/devise.en.yml +1 -1
  103. data/config/routes.rb +19 -1
  104. data/config/symmetric-encryption.yml +1 -1
  105. data/db/ddl.sql +40 -40
  106. data/db/migrate/20130812155313_devise_create_kaui_users.rb +12 -0
  107. data/db/migrate/20150109214021_create_kaui_tenants.rb +12 -0
  108. data/db/migrate/20150112232813_create_kaui_allowed_users.rb +19 -0
  109. data/lib/core_ext.rb +191 -0
  110. data/lib/kaui.rb +68 -5
  111. data/lib/kaui/engine.rb +11 -4
  112. data/lib/kaui/version.rb +1 -1
  113. data/test/dummy/app/controllers/application_controller.rb +1 -1
  114. data/test/dummy/bin/bundle +3 -0
  115. data/test/dummy/bin/rails +4 -0
  116. data/test/dummy/bin/rake +4 -0
  117. data/test/dummy/bin/setup +38 -0
  118. data/test/dummy/bin/update +29 -0
  119. data/test/dummy/bin/yarn +11 -0
  120. data/test/dummy/config/application.rb +6 -53
  121. data/test/dummy/config/boot.rb +2 -9
  122. data/test/dummy/config/database.yml +15 -17
  123. data/test/dummy/config/environment.rb +4 -4
  124. data/test/dummy/config/environments/development.rb +42 -16
  125. data/test/dummy/config/environments/production.rb +62 -40
  126. data/test/dummy/config/environments/test.rb +26 -15
  127. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  128. data/test/dummy/config/initializers/assets.rb +14 -0
  129. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  130. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  131. data/test/dummy/config/initializers/inflections.rb +6 -5
  132. data/test/dummy/config/initializers/killbill_client.rb +1 -1
  133. data/test/dummy/config/initializers/mime_types.rb +0 -1
  134. data/test/dummy/config/initializers/new_framework_defaults_5_1.rb +14 -0
  135. data/test/dummy/config/initializers/wrap_parameters.rb +6 -6
  136. data/test/dummy/config/locales/en.yml +30 -2
  137. data/test/dummy/config/secrets.yml +32 -0
  138. data/test/dummy/config/symmetric-encryption.yml +1 -1
  139. data/test/dummy/db/schema.rb +1 -1
  140. data/{app/assets/images/kaui/.gitkeep → test/dummy/log/test.log} +0 -0
  141. data/test/functional/kaui/account_children_controller_test.rb +32 -0
  142. data/test/functional/kaui/account_tags_controller_test.rb +3 -3
  143. data/test/functional/kaui/accounts_controller_test.rb +127 -12
  144. data/test/functional/kaui/admin_allowed_users_controller_test.rb +151 -1
  145. data/test/functional/kaui/admin_controller_test.rb +45 -0
  146. data/test/functional/kaui/admin_tenants_controller_test.rb +127 -0
  147. data/test/functional/kaui/bundle_tags_controller_test.rb +3 -3
  148. data/test/functional/kaui/bundles_controller_test.rb +27 -0
  149. data/test/functional/kaui/chargebacks_controller_test.rb +1 -1
  150. data/test/functional/kaui/custom_fields_controller_test.rb +10 -3
  151. data/test/functional/kaui/functional_test_helper.rb +1 -1
  152. data/test/functional/kaui/functional_test_helper_nosetup.rb +66 -1
  153. data/test/functional/kaui/home_controller_test.rb +9 -0
  154. data/test/functional/kaui/invoices_controller_test.rb +8 -0
  155. data/test/functional/kaui/login_proxy_controller_test.rb +12 -0
  156. data/test/functional/kaui/payment_methods_controller_test.rb +23 -0
  157. data/test/functional/kaui/payments_controller_test.rb +15 -1
  158. data/test/functional/kaui/queues_controller_test.rb +17 -0
  159. data/test/functional/kaui/registrations_controller_test.rb +49 -0
  160. data/test/functional/kaui/role_definitions_controller_test.rb +47 -0
  161. data/test/functional/kaui/subscriptions_controller_test.rb +39 -0
  162. data/test/functional/kaui/tenants_controller_test.rb +6 -0
  163. data/test/functional/kaui/transactions_controller_test.rb +36 -3
  164. data/test/integration/kaui/date_helper_integration_test.rb +16 -0
  165. data/test/integration/kaui/navigation_test.rb +11 -5
  166. data/test/killbill_test_helper.rb +24 -3
  167. data/test/test_helper.rb +3 -0
  168. data/test/unit/kaui/account_email_test.rb +3 -3
  169. data/test/unit/kaui/date_helper_test.rb +14 -2
  170. data/test/unit/kaui/money_helper_test.rb +1 -1
  171. metadata +327 -147
  172. data/.gitignore +0 -18
  173. data/.travis.yml +0 -37
  174. data/Gemfile +0 -6
  175. data/bin/kaui +0 -4
  176. data/kaui.gemspec +0 -65
  177. data/script/rails +0 -8
  178. data/script/sandbox +0 -30
  179. data/test/dummy/.gitignore +0 -1
  180. data/test/dummy/app/mailers/.gitkeep +0 -0
  181. data/test/dummy/app/models/.gitkeep +0 -0
  182. data/test/dummy/lib/assets/.gitkeep +0 -0
  183. data/test/dummy/log/.gitkeep +0 -0
@@ -0,0 +1,6 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # ApplicationController.renderer.defaults.merge!(
4
+ # http_host: 'example.org',
5
+ # https: false
6
+ # )
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Version of your assets, change this if you want to expire all your assets.
4
+ Rails.application.config.assets.version = '1.0'
5
+
6
+ # Add additional assets to the asset load path.
7
+ # Rails.application.config.assets.paths << Emoji.images_path
8
+ # Add Yarn node_modules folder to the asset load path.
9
+ Rails.application.config.assets.paths << Rails.root.join('node_modules')
10
+
11
+ # Precompile additional assets.
12
+ # application.js, application.css, and all non-JS/CSS in the app/assets
13
+ # folder are already added.
14
+ # Rails.application.config.assets.precompile += %w( admin.js admin.css )
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Specify a serializer for the signed and encrypted cookie jars.
4
+ # Valid options are :json, :marshal, and :hybrid.
5
+ Rails.application.config.action_dispatch.cookies_serializer = :marshal
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -1,15 +1,16 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- # Add new inflection rules using the following format
4
- # (all these examples are active by default):
5
- # ActiveSupport::Inflector.inflections do |inflect|
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
6
7
  # inflect.plural /^(ox)$/i, '\1en'
7
8
  # inflect.singular /^(ox)en/i, '\1'
8
9
  # inflect.irregular 'person', 'people'
9
10
  # inflect.uncountable %w( fish sheep )
10
11
  # end
11
- #
12
+
12
13
  # These inflection rules are supported but not enabled by default:
13
- # ActiveSupport::Inflector.inflections do |inflect|
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
14
15
  # inflect.acronym 'RESTful'
15
16
  # end
@@ -1 +1 @@
1
- KillBillClient.url = 'http://127.0.0.1:8080'
1
+ KillBillClient.url = ENV['KILLBILL_URL'] || 'http://127.0.0.1:8080'
@@ -2,4 +2,3 @@
2
2
 
3
3
  # Add new mime types for use in respond_to blocks:
4
4
  # Mime::Type.register "text/richtext", :rtf
5
- # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains migration options to ease your Rails 5.1 upgrade.
4
+ #
5
+ # Once upgraded flip defaults one by one to migrate to the new default.
6
+ #
7
+ # Read the Guide for Upgrading Ruby on Rails for more info on each option.
8
+
9
+ # Make `form_with` generate non-remote forms.
10
+ Rails.application.config.action_view.form_with_generates_remote_forms = false
11
+
12
+ # Unknown asset fallback will return the path passed in when the given
13
+ # asset is not present in the asset pipeline.
14
+ # Rails.application.config.assets.unknown_asset_fallback = false
@@ -1,14 +1,14 @@
1
1
  # Be sure to restart your server when you modify this file.
2
- #
2
+
3
3
  # This file contains settings for ActionController::ParamsWrapper which
4
4
  # is enabled by default.
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters :format => [:json]
8
+ wrap_parameters format: [:json]
9
9
  end
10
10
 
11
- # Disable root element in JSON by default.
12
- ActiveSupport.on_load(:active_record) do
13
- self.include_root_in_json = false
14
- end
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -1,5 +1,33 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # The following keys must be escaped otherwise they will not be retrieved by
20
+ # the default I18n backend:
21
+ #
22
+ # true, false, on, off, yes, no
23
+ #
24
+ # Instead, surround them with single quotes.
25
+ #
26
+ # en:
27
+ # 'true': 'foo'
28
+ #
29
+ # To learn more, please read the Rails Internationalization guide
30
+ # available at http://guides.rubyonrails.org/i18n.html.
3
31
 
4
32
  en:
5
33
  hello: "Hello world"
@@ -0,0 +1,32 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rails secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ # Shared secrets are available across all environments.
14
+
15
+ # shared:
16
+ # api_key: a1B2c3D4e5F6
17
+
18
+ # Environmental secrets are only available for that specific environment.
19
+
20
+ development:
21
+ secret_key_base: ffcb8fd00355443c82052feb8cf5ae4747ab9130545d30db07d8c39fff937e2141bd47e7e260bdb8bca4e742c5b05b2be463e3af2d0322d46dde92a2501361d9
22
+
23
+ test:
24
+ secret_key_base: ae7f3106c2b1f63580bd20e60b92a692a30bab783867fb1a48b348acc79d9f68b5e1d9e3c8ddda44756edbe74dbcb0e486acd5bcb15b48466ae2647698e3a159
25
+
26
+ # Do not keep production secrets in the unencrypted secrets file.
27
+ # Instead, either read values from the environment.
28
+ # Or, use `bin/rails secrets:setup` to configure encrypted secrets
29
+ # and move the `production:` environment over there.
30
+
31
+ production:
32
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -6,7 +6,7 @@
6
6
  # can be placed directly in the source code.
7
7
  # And therefore no RSA private key is required
8
8
  development: &development_defaults
9
- key: 1234567890ABCDEF1234567890ABCDEF
9
+ key: 1234567890ABCDEF
10
10
  iv: 1234567890ABCDEF
11
11
  cipher_name: aes-128-cbc
12
12
  encoding: :base64strict
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20151010235259) do
14
+ ActiveRecord::Schema.define(version: 20150112232813) do
15
15
 
16
16
  create_table "kaui_allowed_user_tenants", force: :cascade do |t|
17
17
  t.integer "kaui_allowed_user_id", limit: 4
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class Kaui::AccountChildrenControllerTest < Kaui::FunctionalTestHelper
4
+
5
+ test 'should get index' do
6
+ get :index, :account_id => @account.account_id
7
+ assert_response :success
8
+ end
9
+
10
+ test 'should list account children' do
11
+ children_size = 3
12
+ # create children
13
+ for i in 1..children_size
14
+ create_account(@tenant,USERNAME,PASSWORD,'Kaui test',nil,nil,@account.account_id)
15
+ end
16
+
17
+ parameters = {
18
+ :search => { :value => @account.account_id},
19
+ :format => :json,
20
+ :account_id => @account.account_id
21
+ }
22
+ get :pagination, parameters
23
+ assert_response :success
24
+
25
+ body = MultiJson.decode(@response.body)
26
+
27
+ assert_instance_of Array, body['data']
28
+ assert_equal children_size, body['data'].size
29
+ assert_nil body['error']
30
+ end
31
+
32
+ end
@@ -20,9 +20,9 @@ class Kaui::AccountTagsControllerTest < Kaui::FunctionalTestHelper
20
20
  test 'should update tags' do
21
21
  post :update,
22
22
  :account_id => @account.account_id,
23
- 'tag_00000000-0000-0000-0000-000000000001' => 'AUTO_PAY_OFF',
24
- 'tag_00000000-0000-0000-0000-000000000005' => 'MANUAL_PAY',
25
- 'tag_00000000-0000-0000-0000-000000000003' => 'OVERDUE_ENFORCEMENT_OFF'
23
+ :'tag_00000000-0000-0000-0000-000000000001' => 'AUTO_PAY_OFF',
24
+ :'tag_00000000-0000-0000-0000-000000000005' => 'MANUAL_PAY',
25
+ :'tag_00000000-0000-0000-0000-000000000003' => 'OVERDUE_ENFORCEMENT_OFF'
26
26
  assert_redirected_to account_path(@account.account_id)
27
27
  assert_equal 'Account tags successfully set', flash[:notice]
28
28
  end
@@ -7,6 +7,26 @@ class Kaui::AccountsControllerTest < Kaui::FunctionalTestHelper
7
7
  assert_response 200
8
8
  end
9
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
+
10
30
  test 'should list accounts' do
11
31
  # Test pagination
12
32
  get :pagination, :format => :json
@@ -106,18 +126,6 @@ class Kaui::AccountsControllerTest < Kaui::FunctionalTestHelper
106
126
  assert_response 302
107
127
  end
108
128
 
109
- test 'should handle Kill Bill errors when toggling email notifications' do
110
- account_id = SecureRandom.uuid.to_s
111
- put :toggle_email_notifications, :account_id => account_id, :is_notified => true
112
- assert_redirected_to home_path
113
- assert_equal "Error while communicating with the Kill Bill server: Error 404: Object id=#{account_id} type=ACCOUNT doesn't exist!", flash[:error]
114
- end
115
-
116
- test 'should toggle email notifications' do
117
- put :toggle_email_notifications, :account_id => @account.account_id, :is_notified => true
118
- assert_response 302
119
- end
120
-
121
129
  test 'should handle Kill Bill errors when paying all invoices' do
122
130
  account_id = SecureRandom.uuid.to_s
123
131
  post :pay_all_invoices, :account_id => account_id
@@ -129,4 +137,111 @@ class Kaui::AccountsControllerTest < Kaui::FunctionalTestHelper
129
137
  post :pay_all_invoices, :account_id => @account.account_id, :is_external_payment => true
130
138
  assert_response 302
131
139
  end
140
+
141
+ test 'should trigger invoice' do
142
+ parameters = {
143
+ :account_id => @account2.account_id,
144
+ :dry_run => '0'
145
+ }
146
+
147
+ post :trigger_invoice, parameters
148
+ assert_equal 'Nothing to generate for target date today', flash[:notice]
149
+ assert_redirected_to account_path(@account2.account_id)
150
+
151
+ today_next_month = (Date.parse(@kb_clock['localDate']) >> 1).to_s
152
+ # generate a dry run invoice
153
+ parameters = {
154
+ :account_id => @account.account_id,
155
+ :dry_run => '1',
156
+ :target_date => today_next_month
157
+ }
158
+
159
+ post :trigger_invoice, parameters
160
+ assert_response :success
161
+
162
+ # persist it
163
+ parameters[:dry_run] = '0'
164
+ post :trigger_invoice, parameters
165
+ assert_response :redirect
166
+ assert_match /Generated invoice.*for target date.*/, flash[:notice]
167
+ a_tag = /<a.href="(?<href>.*?)">/.match(@response.body)
168
+ assert_redirected_to a_tag[:href]
169
+ end
170
+
171
+ test 'should get next_invoice_date' do
172
+ get :next_invoice_date, :account_id => @account.account_id
173
+ next_month = Date.parse(@kb_clock['localDate']) >> 1
174
+ assert_equal @response.body.to_s.gsub('"',''), Date.new(next_month.year, next_month.month, @bundle.subscriptions.first.bill_cycle_day_local).to_s
175
+ end
176
+
177
+ test 'should validate external key if found' do
178
+ get :validate_external_key, :external_key => 'foo'
179
+ assert_response :success
180
+ assert_equal JSON[@response.body]['is_found'], false
181
+
182
+ external_key = SecureRandom.uuid.to_s
183
+ post :create, :account => {:external_key => external_key}
184
+ assert_redirected_to account_path(get_redirected_account_id)
185
+
186
+ get :validate_external_key, :external_key => external_key
187
+ assert_response :success
188
+ assert_equal JSON[@response.body]['is_found'], true
189
+ end
190
+
191
+ test 'should link and un-link to parent' do
192
+ parent = create_account(@tenant)
193
+ child = create_account(@tenant)
194
+
195
+ # force an error linking a parent account
196
+ child.parent_account_id = SecureRandom.uuid.to_s
197
+ put :link_to_parent, {
198
+ :account => child.to_hash,
199
+ :account_id => child.account_id
200
+ }
201
+ assert_equal "Parent account id not found: #{child.parent_account_id}",flash[:error]
202
+ assert_redirected_to account_path(child.account_id)
203
+
204
+ # link parent account
205
+ child.parent_account_id = parent.account_id
206
+ put :link_to_parent, {
207
+ :account => child.to_hash,
208
+ :account_id => child.account_id
209
+ }
210
+ assert_equal 'Account successfully updated',flash[:notice]
211
+ assert_redirected_to account_path(child.account_id)
212
+
213
+ # un-link parent account
214
+ delete :link_to_parent, :account_id => child.account_id
215
+ assert_equal 'Account successfully updated',flash[:notice]
216
+ assert_redirected_to account_path(child.account_id)
217
+
218
+ end
219
+
220
+ test 'should set email notifications configuration if plugin is available' do
221
+
222
+ parameters = {
223
+ :configuration => {
224
+ :account_id => @account.account_id,
225
+ :event_types => ['INVOICE_NOTIFICATION']
226
+ }
227
+ }
228
+
229
+ post :set_email_notifications_configuration, parameters
230
+ assert_equal('Email notification plugin is not installed',flash[:error]) unless flash[:error].blank?
231
+ assert_equal("Email notifications for account #{@account.account_id} was successfully updated",flash[:notice]) if flash[:error].blank?
232
+ assert_redirected_to account_path(@account.account_id)
233
+
234
+ end
235
+
236
+ private
237
+
238
+ def get_redirected_account_id
239
+
240
+ fields = /<a.href="http:\/.*\/.*?\/(?<id>.*?)">/.match(@response.body) if fields.nil?
241
+
242
+ return nil if fields.nil?
243
+
244
+ fields.nil? ? nil : fields[:id]
245
+ end
246
+
132
247
  end
@@ -8,9 +8,40 @@ module Kaui
8
8
  assert_response :success
9
9
  end
10
10
 
11
+ test 'should get create local only' do
12
+ parameters = {
13
+ :allowed_user => {:kb_username => 'Albator', :description => 'My french super hero'},
14
+ :password => 'Albator',
15
+ :roles => nil,
16
+ :external => '1'
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
+
11
27
  test 'should get create' do
12
- post :create, :allowed_user => {:kb_username => 'Albator', :description => 'My french super hero'}
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]
13
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
14
45
  end
15
46
 
16
47
  test 'should get index' do
@@ -27,5 +58,124 @@ module Kaui
27
58
  get :show, :id => au.id
28
59
  assert_response :success
29
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
+ private
160
+ def expected_response_path(id=nil)
161
+ "/kaui/admin_allowed_users#{id.nil? ? '' : "/#{id}" }"
162
+ end
163
+
164
+ def get_allowed_username
165
+ get_value_from_input_field('allowed_user_kb_username')
166
+ end
167
+
168
+ def get_allowed_description
169
+ get_value_from_input_field('allowed_user_description')
170
+ end
171
+
172
+ def get_allowed_id(response_body)
173
+ fields = /<form.*action="\/.*\/.*\/(?<id>.*?)".accept-charset=.*method="post">/.match(response_body)
174
+ fields = /<a.href="http:\/.*\/.*\/(?<id>.*?)">/.match(response_body) if fields.nil?
175
+
176
+ fields.nil? ? nil : fields[:id]
177
+ end
178
+
179
+
30
180
  end
31
181
  end