kaui 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/README.rdoc +27 -1
  2. data/app/controllers/kaui/account_tags_controller.rb +24 -9
  3. data/app/controllers/kaui/account_timelines_controller.rb +1 -1
  4. data/app/controllers/kaui/accounts_controller.rb +7 -5
  5. data/app/controllers/kaui/bundles_controller.rb +2 -2
  6. data/app/controllers/kaui/chargebacks_controller.rb +3 -2
  7. data/app/controllers/kaui/charges_controller.rb +32 -0
  8. data/app/controllers/kaui/credits_controller.rb +3 -4
  9. data/app/controllers/kaui/external_payments_controller.rb +0 -2
  10. data/app/controllers/kaui/invoice_items_controller.rb +44 -0
  11. data/app/controllers/kaui/invoices_controller.rb +4 -3
  12. data/app/controllers/kaui/payments_controller.rb +10 -13
  13. data/app/controllers/kaui/refunds_controller.rb +19 -8
  14. data/app/controllers/kaui/subscriptions_controller.rb +5 -1
  15. data/app/controllers/kaui/tag_definitions_controller.rb +85 -0
  16. data/app/helpers/kaui/date_helper.rb +1 -1
  17. data/app/helpers/kaui/killbill_helper.rb +160 -59
  18. data/app/models/kaui/account.rb +7 -1
  19. data/app/models/kaui/account_timeline.rb +0 -4
  20. data/app/models/kaui/audit_log.rb +9 -7
  21. data/app/models/kaui/base.rb +80 -1
  22. data/app/models/kaui/charge.rb +14 -0
  23. data/app/models/kaui/chargeback.rb +2 -10
  24. data/app/models/kaui/event.rb +2 -13
  25. data/app/models/kaui/invoice.rb +6 -7
  26. data/app/models/kaui/invoice_item.rb +9 -17
  27. data/app/models/kaui/payment.rb +6 -21
  28. data/app/models/kaui/payment_method.rb +1 -8
  29. data/app/models/kaui/plugin_info.rb +1 -5
  30. data/app/models/kaui/plugin_info_property.rb +0 -6
  31. data/app/models/kaui/refund.rb +5 -13
  32. data/app/models/kaui/tag.rb +10 -3
  33. data/app/models/kaui/tag_definition.rb +46 -0
  34. data/app/views/kaui/account_tags/edit.html.erb +17 -17
  35. data/app/views/kaui/account_timelines/show.html.erb +61 -39
  36. data/app/views/kaui/accounts/index.html.erb +1 -1
  37. data/app/views/kaui/accounts/show.html.erb +16 -2
  38. data/app/views/kaui/bundles/show.html.erb +2 -1
  39. data/app/views/kaui/chargebacks/new.html.erb +18 -2
  40. data/app/views/kaui/charges/new.html.erb +87 -0
  41. data/app/views/kaui/credits/new.html.erb +1 -1
  42. data/app/views/kaui/invoice_items/edit.html.erb +92 -0
  43. data/app/views/kaui/invoice_items/index.html.erb +20 -0
  44. data/app/views/kaui/invoice_items/show.html.erb +31 -0
  45. data/app/views/kaui/invoices/index.html.erb +1 -1
  46. data/app/views/kaui/invoices/show.html.erb +42 -24
  47. data/app/views/kaui/payments/_payments_table.html.erb +7 -5
  48. data/app/views/kaui/payments/new.html.erb +32 -12
  49. data/app/views/kaui/refunds/index.html.erb +3 -3
  50. data/app/views/kaui/refunds/new.html.erb +3 -3
  51. data/app/views/kaui/refunds/show.html.erb +27 -13
  52. data/app/views/kaui/subscriptions/edit.html.erb +8 -0
  53. data/app/views/kaui/tag_definitions/_form.html.erb +45 -0
  54. data/app/views/kaui/tag_definitions/edit.html.erb +3 -0
  55. data/app/views/kaui/tag_definitions/index.html.erb +34 -0
  56. data/app/views/kaui/tag_definitions/new.html.erb +3 -0
  57. data/app/views/kaui/tag_definitions/show.html.erb +12 -0
  58. data/app/views/kaui/tags/_tags_table.html.erb +3 -3
  59. data/config/locales/en.yml +3 -0
  60. data/config/locales/fr.yml +3 -0
  61. data/config/routes.rb +11 -1
  62. data/lib/kaui/version.rb +1 -1
  63. data/test/dummy/app/controllers/application_controller.rb +10 -0
  64. data/test/dummy/app/views/layouts/application.html.erb +44 -11
  65. data/test/dummy/config/application.rb +1 -0
  66. data/test/dummy/config/database.yml +5 -4
  67. data/test/dummy/config/environments/development.rb +2 -0
  68. data/test/dummy/config/routes.rb +1 -2
  69. data/test/dummy/log/development.log +2419 -0
  70. data/test/dummy/log/test.log +3265 -131
  71. data/test/dummy/test/fixtures/accounts.yml +32 -0
  72. data/test/dummy/test/fixtures/bundles.yml +4 -0
  73. data/test/dummy/test/fixtures/invoice_items.yml +13 -0
  74. data/test/dummy/test/fixtures/invoices.yml +11 -0
  75. data/test/dummy/test/fixtures/payment_methods.yml +5 -0
  76. data/test/dummy/test/fixtures/plugin_info_properties.yml +59 -0
  77. data/test/dummy/test/fixtures/plugin_infos.yml +2 -0
  78. data/test/dummy/test/fixtures/refunds.yml +8 -0
  79. data/test/dummy/test/fixtures/tag_definitions.yml +9 -0
  80. data/test/dummy/tmp/cache/assets/C8D/6D0/sprockets%2F0ce756f49d61795508c543a702955fc2 +0 -0
  81. data/test/dummy/tmp/cache/assets/C94/4E0/sprockets%2Fea1476dc10a3348303f74d111f70441a +0 -0
  82. data/test/dummy/tmp/cache/assets/CD0/9D0/sprockets%2F5c9508c21501c73fbe00473a09b1f5f4 +0 -0
  83. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  84. data/test/dummy/tmp/cache/assets/CEA/300/sprockets%2Fdf2ad5c9d0990441c2bf59883383d652 +0 -0
  85. data/test/dummy/tmp/cache/assets/D0E/370/sprockets%2F27630db2080819f67c8a0ed5e491b7cb +0 -0
  86. data/test/dummy/tmp/cache/assets/D32/200/sprockets%2Ffa467106e01bda5d6246baea72159d64 +0 -0
  87. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  88. data/test/dummy/tmp/cache/assets/D39/5E0/sprockets%2F59fd338be48a81a17a2a785cbd1612b4 +0 -0
  89. data/test/dummy/tmp/cache/assets/D44/170/sprockets%2Fac15571bce3f926a498da7cd09322d97 +0 -0
  90. data/test/dummy/tmp/cache/assets/D4A/DD0/sprockets%2F0f813582283b7f56fd83fe3d52be7e2c +0 -0
  91. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  92. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  93. data/test/dummy/tmp/cache/assets/D6C/710/sprockets%2F1765773caead06c0a6a19ea9de2453f7 +0 -0
  94. data/test/dummy/tmp/cache/assets/D76/910/sprockets%2Ff99b4bdc434e11e8634e6af62fe805e0 +0 -0
  95. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  96. data/test/dummy/tmp/cache/assets/DF1/1A0/sprockets%2F7f6b7bfea83401d3106b7fadac81ea4b +0 -0
  97. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  98. data/test/dummy/tmp/cache/assets/E20/230/sprockets%2F7d3b1348fdf74cf1b6ba2107fbbac5af +0 -0
  99. data/test/dummy/vendor/assets/images/img/glyphicons-halflings-white.png +0 -0
  100. data/test/dummy/vendor/assets/images/img/glyphicons-halflings.png +0 -0
  101. data/test/dummy/vendor/assets/javascripts/bootstrap.v2.0.4.min.js +6 -0
  102. data/test/dummy/vendor/assets/javascripts/jquery.dataTables.v1.9.3.min.js +156 -0
  103. data/test/dummy/vendor/assets/stylesheets/bootstrap.v2.0.4.min.css +9 -0
  104. data/test/functional/kaui/accounts_controller_test.rb +63 -0
  105. data/test/functional/kaui/bundles_controller_test.rb +18 -6
  106. data/test/functional/kaui/invoice_items_controller_test.rb +18 -0
  107. data/test/functional/kaui/invoices_controller_test.rb +18 -6
  108. data/test/functional/kaui/tag_definitions_controller_test.rb +60 -0
  109. data/test/test_helper.rb +143 -0
  110. data/test/unit/helpers/kaui/plugin_infos_helper_test.rb +20 -0
  111. data/test/unit/kaui/account_test.rb +42 -0
  112. data/test/unit/kaui/base_test.rb +39 -0
  113. data/test/unit/kaui/date_helper_test.rb +13 -0
  114. data/test/unit/kaui/invoice_item_test.rb +23 -0
  115. data/test/unit/kaui/invoice_test.rb +20 -0
  116. data/test/unit/kaui/payment_method_test.rb +26 -0
  117. data/test/unit/kaui/plugin_info_property_test.rb +20 -0
  118. data/test/unit/kaui/plugin_info_test.rb +19 -0
  119. data/test/unit/kaui/refund_test.rb +19 -0
  120. data/test/unit/kaui/tag_definition_test.rb +23 -0
  121. data/test/unit/model_test.rb +23 -23
  122. metadata +330 -226
@@ -1,9 +1,21 @@
1
1
  require 'test_helper'
2
2
 
3
- module Kaui
4
- class BundlesControllerTest < ActionController::TestCase
5
- # test "the truth" do
6
- # assert true
7
- # end
3
+ class Kaui::BundlesControllerTest < ActionController::TestCase
4
+ fixtures :accounts, :bundles
5
+
6
+ test "should get index" do
7
+ get :index
8
+ assert_response :success
9
+ end
10
+
11
+ test "should find bundle by id" do
12
+ pierre = accounts(:pierre)
13
+ bundle = bundles(:bundle_for_pierre)
14
+
15
+ get :show, :id => bundle["bundleId"]
16
+ assert_response :success
17
+ assert_equal assigns(:account).account_id, pierre["accountId"]
18
+ assert_equal assigns(:bundle).bundle_id, bundle["bundleId"]
19
+ assert_equal assigns(:bundle).account_id, pierre["accountId"]
8
20
  end
9
- end
21
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class Kaui::InvoiceItemsControllerTest < ActionController::TestCase
4
+ fixtures :invoice_items
5
+
6
+ test "should get index" do
7
+ get :index
8
+ assert_response :success
9
+ end
10
+
11
+ test "should find invoice item by id" do
12
+ item = invoice_items(:recurring_item_for_pierre)
13
+
14
+ get :show, :id => item["invoiceItemId"], :invoice_id => item["invoiceId"]
15
+ assert_response :success
16
+ assert_equal assigns(:invoice_item).invoice_item_id, item["invoiceItemId"]
17
+ end
18
+ end
@@ -1,9 +1,21 @@
1
1
  require 'test_helper'
2
2
 
3
- module Kaui
4
- class InvoicesControllerTest < ActionController::TestCase
5
- # test "the truth" do
6
- # assert true
7
- # end
3
+ class Kaui::InvoicesControllerTest < ActionController::TestCase
4
+ fixtures :accounts, :invoices
5
+
6
+ test "should get index" do
7
+ get :index
8
+ assert_response :success
9
+ end
10
+
11
+ test "should find invoice by id" do
12
+ pierre = accounts(:pierre)
13
+ invoice = invoices(:invoice_for_pierre)
14
+
15
+ get :show, :id => invoice["invoiceId"]
16
+ assert_response :success
17
+ assert_equal assigns(:account).account_id, pierre["accountId"]
18
+ assert_equal assigns(:invoice).invoice_id, invoice["invoiceId"]
19
+ assert_equal assigns(:invoice).account_id, pierre["accountId"]
8
20
  end
9
- end
21
+ end
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ module Kaui
4
+ class TagDefinitionsControllerTest < ActionController::TestCase
5
+ fixtures :tag_definitions
6
+
7
+ setup do
8
+ @tag_definition = TagDefinition.new(tag_definitions(:payment_plan))
9
+ @routes = Kaui::Engine.routes
10
+ end
11
+
12
+ test "should get index" do
13
+ get :index
14
+ assert_response :success
15
+ assert_not_nil assigns(:tag_definitions)
16
+ end
17
+
18
+ test "should get new" do
19
+ get :new
20
+ assert_response :success
21
+ end
22
+
23
+ test "should create tag_definition" do
24
+ assert_difference('TagDefinition.count') do
25
+ post :create, tag_definition: { description: @tag_definition.description, name: @tag_definition.name }
26
+ end
27
+
28
+ # TODO - for now, we redirect to the main page as we don't get the id back
29
+ assert_redirected_to tag_definitions_path
30
+ # assert_redirected_to tag_definition_path(assigns(:tag_definition))
31
+ end
32
+
33
+ test "should show tag_definition" do
34
+ get :show, id: @tag_definition
35
+ assert_response :success
36
+ end
37
+
38
+ test "should get edit" do
39
+ get :edit, id: @tag_definition
40
+ assert_response :success
41
+ end
42
+
43
+ # TODO - not supported yet
44
+ # test "should update tag_definition" do
45
+ # put :update, id: @tag_definition, tag_definition: { description: @tag_definition.description, id: @tag_definition.id, name: @tag_definition.name }
46
+ # assert_redirected_to tag_definition_path(assigns(:tag_definition))
47
+ # end
48
+
49
+ test "should destroy tag_definition" do
50
+ post :create, tag_definition: { description: @tag_definition.description, name: @tag_definition.name }
51
+ new_id = assigns(:tag_definition).id
52
+
53
+ assert_difference('TagDefinition.count', -1) do
54
+ delete :destroy, id: new_id
55
+ end
56
+
57
+ assert_redirected_to tag_definitions_path
58
+ end
59
+ end
60
+ end
data/test/test_helper.rb CHANGED
@@ -3,8 +3,151 @@ ENV["RAILS_ENV"] = "test"
3
3
 
4
4
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
5
  require "rails/test_help"
6
+ require 'securerandom'
6
7
 
7
8
  Rails.backtrace_cleaner.remove_silencers!
8
9
 
9
10
  # Load support files
10
11
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+
13
+ # Mock killbill-server and serve data from the fixtures
14
+ module Kaui::KillbillHelper
15
+ @@fixtures ||= {}
16
+
17
+ def self.get_account(account_id, with_account_id=false)
18
+ find_among_fixtures(Kaui::Account, account_id)
19
+ end
20
+
21
+ def self.get_account_by_external_key(account_id, with_account_id=false)
22
+ find_among_fixtures(Kaui::Account, account_id)
23
+ end
24
+
25
+ def self.get_invoice(invoice_id)
26
+ find_among_fixtures(Kaui::Invoice, invoice_id)
27
+ end
28
+
29
+ def self.get_invoice_item(invoice_id, invoice_item_id)
30
+ find_among_fixtures(Kaui::InvoiceItem, invoice_item_id)
31
+ end
32
+
33
+ def self.get_bundle(bundle_id)
34
+ find_among_fixtures(Kaui::Bundle, bundle_id)
35
+ end
36
+
37
+ def self.get_payments(invoice_id)
38
+ []
39
+ end
40
+
41
+ def self.get_payment_methods(account_id)
42
+ []
43
+ end
44
+
45
+ def self.get_bundles(account_id)
46
+ []
47
+ end
48
+
49
+ def self.get_subscriptions_for_bundle(bundle_id)
50
+ []
51
+ end
52
+
53
+ def self.get_tags_for_account(account_id)
54
+ []
55
+ end
56
+
57
+ def self.get_tag_definitions
58
+ find_all_among_fixtures(Kaui::TagDefinition)
59
+ end
60
+
61
+ def self.get_tag_definition(tag_definition_id)
62
+ find_among_fixtures(Kaui::TagDefinition, tag_definition_id, 'id')
63
+ end
64
+
65
+ def self.create_tag_definition(tag_definition)
66
+ tag_definition.id = SecureRandom.uuid
67
+ add_fixture(tag_definition, Kaui::TagDefinition)
68
+ end
69
+
70
+ def self.delete_tag_definition(tag_definition_id)
71
+ delete_fixture(Kaui::TagDefinition, tag_definition_id, 'id')
72
+ end
73
+
74
+ def self.find_among_fixtures(clazz, id, type_id=nil)
75
+ results = find_all_among_fixtures(clazz, id, type_id)
76
+ results.length > 0 ? results[0] : nil
77
+ end
78
+
79
+ def self.find_all_among_fixtures(clazz, id=nil, type_id=nil)
80
+ results = []
81
+ type = clazz.name.demodulize.underscore
82
+ type_id = "#{clazz.name.demodulize.camelize}Id".uncapitalize unless type_id
83
+ @@fixtures.each do |k,v|
84
+ next unless k == "#{type}s"
85
+ v.each do |w,u|
86
+ results << clazz.new(u.fixture) if u.fixture[type_id] == id or !id.present?
87
+ end
88
+ end
89
+
90
+ return results
91
+ end
92
+
93
+ def self.add_fixture(fixture, clazz)
94
+ type = clazz.name.demodulize.underscore
95
+ @@fixtures["#{type}s"].fixtures ||= {}
96
+ @@fixtures["#{type}s"].fixtures["auto_generated_fixture_#{rand(100)}"] = ActiveRecord::Fixture.new(fixture.to_hash, clazz)
97
+ fixture
98
+ end
99
+
100
+ def self.delete_fixture(clazz, id, type_id=nil)
101
+ type = clazz.name.demodulize.underscore
102
+ type_id = "#{clazz.name.demodulize.camelize}Id".uncapitalize unless type_id
103
+ @@fixtures.each do |k,v|
104
+ next unless k == "#{type}s"
105
+ v.each do |w,u|
106
+ v.fixtures.delete(w) if u.fixture[type_id] == id
107
+ end
108
+ end
109
+ end
110
+
111
+ def self.set_fixtures(f)
112
+ @@fixtures = f
113
+ end
114
+ end
115
+
116
+ class ActiveRecord::Fixtures
117
+ # Monkey-patch the create_fixtures method not to rely on a database
118
+ def self.create_fixtures(fixtures_directory, table_names, class_names = {})
119
+ table_names = [table_names].flatten.map { |n| n.to_s }
120
+ table_names.each { |n|
121
+ class_names[n.tr('/', '_').to_sym] = n.classify if n.include?('/')
122
+ }
123
+
124
+ unless table_names.empty?
125
+ fixtures_map = {}
126
+ table_names.map do |path|
127
+ table_name = path.tr '/', '_'
128
+ fixtures_map[path] = ActiveRecord::Fixtures.new(nil,
129
+ table_name,
130
+ class_names[table_name.to_sym] || table_name.classify,
131
+ ::File.join(fixtures_directory, path))
132
+ end
133
+
134
+ all_loaded_fixtures.update(fixtures_map)
135
+ cache_fixtures(nil, fixtures_map)
136
+
137
+ Kaui::KillbillHelper.set_fixtures fixtures_map
138
+ end
139
+ cached_fixtures(nil, table_names)
140
+ end
141
+ end
142
+
143
+ class ActiveRecord::Fixture
144
+ def find
145
+ @fixture
146
+ end
147
+ end
148
+
149
+ class String
150
+ def uncapitalize
151
+ self[0, 1].downcase + self[1..-1]
152
+ end
153
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ module Kaui::PluginInfosHelperTest
4
+ @@plugin_info_keys = [:accountId, :type, :cardHolderName, :cardType, :expirationDate, :maskNumber,
5
+ :address1, :address2, :city, :postalCode, :state, :country]
6
+
7
+ def plugin_info_properies
8
+ properties = []
9
+ @@plugin_info_keys.each do |key|
10
+ as_json = plugin_info_properties("plugin_info_property_#{key.to_s}".to_sym)
11
+ properties << Kaui::PluginInfoProperty.new(as_json).to_hash
12
+ end
13
+ properties
14
+ end
15
+
16
+ def create_plugin_info(plugin_info_json)
17
+ plugin_info_json["properties"] = plugin_info_properies
18
+ Kaui::PluginInfo.new(plugin_info_json)
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ class Kaui::AccountTest < ActiveSupport::TestCase
4
+ fixtures :accounts
5
+
6
+ test "can serialize from json" do
7
+ as_json = accounts(:pierre)
8
+ pierre = Kaui::Account.new(as_json)
9
+
10
+ assert_equal as_json["accountId"], pierre.account_id
11
+ assert_equal as_json["address1"], pierre.address1
12
+ assert_equal as_json["address2"], pierre.address2
13
+ assert_equal as_json["company"], pierre.company
14
+ assert_equal as_json["country"], pierre.country
15
+ assert_equal as_json["currency"], pierre.currency
16
+ assert_equal as_json["email"], pierre.email
17
+ assert_equal as_json["externalKey"], pierre.external_key
18
+ assert_equal as_json["name"], pierre.name
19
+ assert_equal as_json["paymentMethodId"], pierre.payment_method_id
20
+ assert_equal as_json["phone"], pierre.phone
21
+ assert_equal as_json["state"], pierre.state
22
+ assert_equal as_json["timeZone"], pierre.timezone
23
+ end
24
+
25
+ test "can read correct positive balance" do
26
+ as_json = accounts(:account_with_positive_balance)
27
+ t = Kaui::Account.new(as_json)
28
+ assert(t.balance > 0)
29
+ end
30
+
31
+ test "can read correct negative balance" do
32
+ as_json = accounts(:account_with_negative_balance)
33
+ t = Kaui::Account.new(as_json)
34
+ assert(t.balance < 0)
35
+ end
36
+
37
+ test "can read correct zero balance" do
38
+ as_json = accounts(:account_with_zero_balance)
39
+ t = Kaui::Account.new(as_json)
40
+ assert(t.balance == 0)
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class Kaui::BaseTest < ActiveSupport::TestCase
4
+
5
+ class Kaui::SomeKlass < Kaui::Base
6
+ define_attr :attribute_id
7
+
8
+ has_many :klasses, Kaui::SomeKlass
9
+ end
10
+
11
+ test "has_many association should return [] by default" do
12
+ klass = Kaui::SomeKlass.new
13
+ assert_equal [], klass.klasses
14
+ end
15
+
16
+ test "can serialize from hash" do
17
+ klass = Kaui::SomeKlass.new(:attribute_id => 12)
18
+ assert_equal 12, klass.attribute_id
19
+ end
20
+
21
+ test "can serialize from json" do
22
+ klass = Kaui::SomeKlass.new(:attributeId => 12)
23
+ assert_equal 12, klass.attribute_id
24
+ end
25
+
26
+ test "convert camelcase hash into snake case hash" do
27
+ # Happy path
28
+ new_hash = Kaui::Base.convert_hash_keys({:accountId=>12, :data_id=>14})
29
+ assert_equal 12, new_hash[:account_id]
30
+ assert_equal 14, new_hash[:data_id]
31
+ assert_nil new_hash[:accountId]
32
+
33
+ # Edge cases
34
+ assert_nil Kaui::Base.convert_hash_keys(nil)
35
+ assert_equal [], Kaui::Base.convert_hash_keys([])
36
+ assert_equal Hash.new, Kaui::Base.convert_hash_keys({})
37
+ assert_equal 1, Kaui::Base.convert_hash_keys(1)
38
+ end
39
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class Kaui::DateHelperTest < ActiveSupport::TestCase
4
+ include Kaui::DateHelper
5
+
6
+ test "can parse from string" do
7
+ assert_equal "2012-07-01", format_date("2012-07-01T12:55:44Z")
8
+ end
9
+
10
+ test "can parse from date" do
11
+ assert_equal "2012-06-30", format_date(Date.new(2012, 7, 1))
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class Kaui::InvoiceItemTest < ActiveSupport::TestCase
4
+ fixtures :invoice_items
5
+
6
+ test "can serialize from json" do
7
+ as_json = invoice_items(:recurring_item_for_pierre)
8
+ invoice = Kaui::InvoiceItem.new(as_json)
9
+
10
+ assert_equal as_json["invoiceItemId"], invoice.invoice_item_id
11
+ assert_equal as_json["invoiceId"], invoice.invoice_id
12
+ assert_equal as_json["accountId"], invoice.account_id
13
+ assert_equal as_json["bundleId"], invoice.bundle_id
14
+ assert_equal as_json["subscriptionId"], invoice.subscription_id
15
+ assert_equal as_json["planName"], invoice.plan_name
16
+ assert_equal as_json["phaseName"], invoice.phase_name
17
+ assert_equal as_json["description"], invoice.description
18
+ assert_equal as_json["startDate"], invoice.start_date
19
+ assert_equal as_json["endDate"], invoice.end_date
20
+ assert_equal as_json["amount"], invoice.amount
21
+ assert_equal as_json["currency"], invoice.currency
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class Kaui::InvoiceTest < ActiveSupport::TestCase
4
+ fixtures :invoices
5
+
6
+ test "can serialize from json" do
7
+ as_json = invoices(:invoice_for_pierre)
8
+ invoice = Kaui::Invoice.new(as_json)
9
+
10
+ assert_equal as_json["amount"], invoice.amount
11
+ assert_equal as_json["cba"], invoice.credit_balance_adjustment
12
+ assert_equal as_json["creditAdj"], invoice.credit_adjustment
13
+ assert_equal as_json["refundAdj"], invoice.refund_adjustment
14
+ assert_equal as_json["invoiceId"], invoice.invoice_id
15
+ assert_equal as_json["invoiceDate"], invoice.invoice_date
16
+ assert_equal as_json["targetDate"], invoice.target_date
17
+ assert_equal as_json["invoiceNumber"], invoice.invoice_number
18
+ assert_equal as_json["accountId"], invoice.account_id
19
+ end
20
+ end