mx-platform-ruby 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +20 -0
  3. data/.gitignore +13 -0
  4. data/.rubocop.yml +44 -0
  5. data/Gemfile +5 -0
  6. data/LICENSE +21 -0
  7. data/README.md +60 -0
  8. data/Rakefile +11 -0
  9. data/lib/mx-platform-ruby.rb +44 -0
  10. data/lib/mx-platform-ruby/account.rb +107 -0
  11. data/lib/mx-platform-ruby/account_number.rb +57 -0
  12. data/lib/mx-platform-ruby/account_owner.rb +42 -0
  13. data/lib/mx-platform-ruby/category.rb +127 -0
  14. data/lib/mx-platform-ruby/challenge.rb +37 -0
  15. data/lib/mx-platform-ruby/client.rb +59 -0
  16. data/lib/mx-platform-ruby/connect_widget.rb +43 -0
  17. data/lib/mx-platform-ruby/credential.rb +54 -0
  18. data/lib/mx-platform-ruby/enhanced_transaction.rb +44 -0
  19. data/lib/mx-platform-ruby/error.rb +6 -0
  20. data/lib/mx-platform-ruby/holding.rb +87 -0
  21. data/lib/mx-platform-ruby/institution.rb +78 -0
  22. data/lib/mx-platform-ruby/member.rb +242 -0
  23. data/lib/mx-platform-ruby/member_status.rb +35 -0
  24. data/lib/mx-platform-ruby/merchant.rb +52 -0
  25. data/lib/mx-platform-ruby/oauth_window.rb +32 -0
  26. data/lib/mx-platform-ruby/pageable.rb +29 -0
  27. data/lib/mx-platform-ruby/statement.rb +70 -0
  28. data/lib/mx-platform-ruby/tag.rb +104 -0
  29. data/lib/mx-platform-ruby/tagging.rb +107 -0
  30. data/lib/mx-platform-ruby/transaction.rb +162 -0
  31. data/lib/mx-platform-ruby/transaction_rule.rb +112 -0
  32. data/lib/mx-platform-ruby/user.rb +112 -0
  33. data/lib/mx-platform-ruby/version.rb +5 -0
  34. data/lib/mx-platform-ruby/widget.rb +49 -0
  35. data/mx-platform-ruby.gemspec +31 -0
  36. data/spec/lib/mx-platform-ruby/account_number_spec.rb +100 -0
  37. data/spec/lib/mx-platform-ruby/account_owner_spec.rb +71 -0
  38. data/spec/lib/mx-platform-ruby/account_spec.rb +267 -0
  39. data/spec/lib/mx-platform-ruby/category_spec.rb +244 -0
  40. data/spec/lib/mx-platform-ruby/challenge_spec.rb +72 -0
  41. data/spec/lib/mx-platform-ruby/client_spec.rb +101 -0
  42. data/spec/lib/mx-platform-ruby/connect_widget_spec.rb +66 -0
  43. data/spec/lib/mx-platform-ruby/credential_spec.rb +90 -0
  44. data/spec/lib/mx-platform-ruby/enhanced_transaction_spec.rb +89 -0
  45. data/spec/lib/mx-platform-ruby/holding_spec.rb +178 -0
  46. data/spec/lib/mx-platform-ruby/institution_spec.rb +141 -0
  47. data/spec/lib/mx-platform-ruby/member_spec.rb +557 -0
  48. data/spec/lib/mx-platform-ruby/member_status_spec.rb +76 -0
  49. data/spec/lib/mx-platform-ruby/merchant_spec.rb +89 -0
  50. data/spec/lib/mx-platform-ruby/oauth_window_spec.rb +47 -0
  51. data/spec/lib/mx-platform-ruby/pageable_spec.rb +75 -0
  52. data/spec/lib/mx-platform-ruby/statement_spec.rb +130 -0
  53. data/spec/lib/mx-platform-ruby/tag_spec.rb +179 -0
  54. data/spec/lib/mx-platform-ruby/tagging_spec.rb +191 -0
  55. data/spec/lib/mx-platform-ruby/transaction_rule_spec.rb +207 -0
  56. data/spec/lib/mx-platform-ruby/transaction_spec.rb +449 -0
  57. data/spec/lib/mx-platform-ruby/user_spec.rb +196 -0
  58. data/spec/lib/mx-platform-ruby/widget_spec.rb +76 -0
  59. data/spec/lib/mx-platform-ruby_spec.rb +15 -0
  60. data/spec/sample.pdf +0 -0
  61. data/spec/spec_helper.rb +24 -0
  62. metadata +63 -3
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MXPlatformRuby
4
+ class User
5
+ extend ::MXPlatformRuby::Pageable
6
+ include ::ActiveAttr::Model
7
+
8
+ attribute :email
9
+ attribute :guid
10
+ attribute :id
11
+ attribute :is_disabled
12
+ attribute :metadata
13
+
14
+ def self.create_user(options = {})
15
+ create_user_options = create_user_options(options)
16
+ response = ::MXPlatformRuby.client.make_request(create_user_options)
17
+
18
+ user_params = response['user']
19
+ ::MXPlatformRuby::User.new(user_params)
20
+ end
21
+
22
+ def self.delete_user(options = {})
23
+ delete_user_options = delete_user_options(options)
24
+ ::MXPlatformRuby.client.make_request(delete_user_options)
25
+ end
26
+
27
+ def self.list_users(options = {})
28
+ options = list_users_options(options)
29
+
30
+ paginate(options)
31
+ end
32
+
33
+ def self.read_user(options = {})
34
+ read_user_options = read_user_options(options)
35
+ response = ::MXPlatformRuby.client.make_request(read_user_options)
36
+
37
+ user_params = response['user']
38
+ ::MXPlatformRuby::User.new(user_params)
39
+ end
40
+
41
+ def self.update_user(options = {})
42
+ update_user_options = update_user_options(options)
43
+ response = ::MXPlatformRuby.client.make_request(update_user_options)
44
+
45
+ user_params = response['user']
46
+ ::MXPlatformRuby::User.new(user_params)
47
+ end
48
+
49
+ # Private class methods
50
+
51
+ def self.create_user_options(options)
52
+ {
53
+ endpoint: '/users',
54
+ http_method: :post,
55
+ request_body: {
56
+ user: {
57
+ email: options[:email],
58
+ id: options[:id],
59
+ is_disabled: options[:is_disabled],
60
+ metadata: options[:metadata]
61
+ }.compact
62
+ }
63
+ }
64
+ end
65
+ private_class_method :create_user_options
66
+
67
+ def self.delete_user_options(options)
68
+ {
69
+ endpoint: "/users/#{options[:user_guid]}",
70
+ http_method: :delete
71
+ }
72
+ end
73
+ private_class_method :delete_user_options
74
+
75
+ def self.list_users_options(options)
76
+ {
77
+ endpoint: '/users',
78
+ http_method: :get,
79
+ query_params: {
80
+ page: options[:page],
81
+ records_per_page: options[:records_per_page]
82
+ }.compact,
83
+ resource: 'users'
84
+ }
85
+ end
86
+ private_class_method :list_users_options
87
+
88
+ def self.read_user_options(options)
89
+ {
90
+ endpoint: "/users/#{options[:user_guid]}",
91
+ http_method: :get
92
+ }
93
+ end
94
+ private_class_method :read_user_options
95
+
96
+ def self.update_user_options(options)
97
+ {
98
+ endpoint: "/users/#{options[:user_guid]}",
99
+ http_method: :put,
100
+ request_body: {
101
+ user: {
102
+ email: options[:email],
103
+ id: options[:id],
104
+ is_disabled: options[:is_disabled],
105
+ metadata: options[:metadata]
106
+ }.compact
107
+ }
108
+ }
109
+ end
110
+ private_class_method :update_user_options
111
+ end
112
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MXPlatformRuby
4
+ VERSION = '0.1.1'
5
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MXPlatformRuby
4
+ class Widget
5
+ include ::ActiveAttr::Model
6
+
7
+ attribute :type
8
+ attribute :url
9
+ attribute :user_id
10
+
11
+ def self.request_widget_url(options = {})
12
+ request_widget_url_options = request_widget_url_options(options)
13
+ response = ::MXPlatformRuby.client.make_request(request_widget_url_options)
14
+
15
+ widget_url_params = response['widget_url']
16
+ ::MXPlatformRuby::Widget.new(widget_url_params)
17
+ end
18
+
19
+ # Private class methods
20
+
21
+ def self.request_widget_url_options(options)
22
+ {
23
+ endpoint: "/users/#{options[:user_guid]}/widget_urls",
24
+ headers: {
25
+ 'Accept-Language': options[:accept_language]
26
+ }.compact,
27
+ http_method: :post,
28
+ request_body: {
29
+ widget_url: {
30
+ color_scheme: options[:color_scheme],
31
+ current_institution_code: options[:current_institution_code],
32
+ current_institution_guid: options[:current_institution_guid],
33
+ current_member_guid: options[:current_member_guid],
34
+ disable_institution_search: options[:disable_institution_search],
35
+ include_transactions: options[:include_transactions],
36
+ is_mobile_webview: options[:is_mobile_webview],
37
+ mode: options[:mode],
38
+ ui_message_version: options[:ui_message_version],
39
+ ui_message_webview_url_scheme: options[:ui_message_webview_url_scheme],
40
+ update_credentials: options[:update_credentials],
41
+ wait_for_full_aggregation: options[:wait_for_full_aggregation],
42
+ widget_type: options[:widget_type]
43
+ }.compact
44
+ }
45
+ }
46
+ end
47
+ private_class_method :request_widget_url_options
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+ require 'mx-platform-ruby/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'mx-platform-ruby'
8
+ s.version = MXPlatformRuby::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ['MX']
11
+ s.email = ['devexperience@mx.com']
12
+ s.files = `git ls-files`.split("\n")
13
+ s.homepage = 'https://www.mx.com/products/platform-api'
14
+ s.summary = 'MX Platform Ruby Gem'
15
+ s.description = 'A Ruby library for the MX Platform API.'
16
+ s.license = 'MIT'
17
+ s.required_ruby_version = '>= 2.6'
18
+ s.metadata = {
19
+ 'documentation_uri' => 'https://docs.mx.com/api'
20
+ }
21
+
22
+ s.add_runtime_dependency 'active_attr'
23
+ s.add_runtime_dependency 'httpclient'
24
+
25
+ s.add_development_dependency 'bundler'
26
+ s.add_development_dependency 'pry'
27
+ s.add_development_dependency 'rake'
28
+ s.add_development_dependency 'rspec'
29
+ s.add_development_dependency 'rubocop'
30
+ s.add_development_dependency 'simplecov'
31
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::MXPlatformRuby::AccountNumber do
6
+ let(:account_number_attributes) do
7
+ {
8
+ account_guid: 'ACT-06d7f44b-caae-0f6e-1384-01f52e75dcb1',
9
+ account_number: '10001',
10
+ guid: 'ACN-8899832e-e5b4-42cd-aa25-bbf1dc889a8f',
11
+ institution_number: '123',
12
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
13
+ routing_number: '68899990000000',
14
+ transit_number: '12345',
15
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
16
+ }
17
+ end
18
+ let(:list_account_numbers_by_account_options) do
19
+ {
20
+ account_guid: 'ACT-06d7f44b-caae-0f6e-1384-01f52e75dcb1',
21
+ page: 1,
22
+ records_per_page: 10,
23
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
24
+ }
25
+ end
26
+ let(:list_account_numbers_by_member_options) do
27
+ {
28
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
29
+ page: 1,
30
+ records_per_page: 10,
31
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
32
+ }
33
+ end
34
+ let(:pagination_attributes) do
35
+ {
36
+ 'current_page' => 1,
37
+ 'per_page' => 25,
38
+ 'total_pages' => 1,
39
+ 'total_entries' => 1
40
+ }
41
+ end
42
+
43
+ context 'list_account_numbers_by_account endpoints' do
44
+ let(:list_account_numbers_by_account_response) do
45
+ {
46
+ 'account_numbers' => [account_number_attributes],
47
+ 'pagination' => pagination_attributes
48
+ }
49
+ end
50
+
51
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(list_account_numbers_by_account_response) }
52
+
53
+ describe 'list_account_numbers_by_account' do
54
+ it 'returns a list of account_numbers' do
55
+ response = described_class.list_account_numbers_by_account
56
+
57
+ expect(response).to be_kind_of(::MXPlatformRuby::Page)
58
+ expect(response.first).to be_kind_of(::MXPlatformRuby::AccountNumber)
59
+ expect(response.first.account_guid).to eq(account_number_attributes[:account_guid])
60
+ expect(response.first.account_number).to eq(account_number_attributes[:account_number])
61
+ expect(response.first.guid).to eq(account_number_attributes[:guid])
62
+ expect(response.first.institution_number).to eq(account_number_attributes[:institution_number])
63
+ expect(response.first.member_guid).to eq(account_number_attributes[:member_guid])
64
+ expect(response.first.routing_number).to eq(account_number_attributes[:routing_number])
65
+ expect(response.first.transit_number).to eq(account_number_attributes[:transit_number])
66
+ expect(response.first.user_guid).to eq(account_number_attributes[:user_guid])
67
+ expect(response.length).to eq(1)
68
+ end
69
+ end
70
+ end
71
+
72
+ context 'list_account_numbers_by_member endpoints' do
73
+ let(:list_account_numbers_by_member_response) do
74
+ {
75
+ 'account_numbers' => [account_number_attributes],
76
+ 'pagination' => pagination_attributes
77
+ }
78
+ end
79
+
80
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(list_account_numbers_by_member_response) }
81
+
82
+ describe 'list_account_numbers_by_member' do
83
+ it 'returns a list of account_numbers' do
84
+ response = described_class.list_account_numbers_by_member
85
+
86
+ expect(response).to be_kind_of(::MXPlatformRuby::Page)
87
+ expect(response.first).to be_kind_of(::MXPlatformRuby::AccountNumber)
88
+ expect(response.first.account_guid).to eq(account_number_attributes[:account_guid])
89
+ expect(response.first.account_number).to eq(account_number_attributes[:account_number])
90
+ expect(response.first.guid).to eq(account_number_attributes[:guid])
91
+ expect(response.first.institution_number).to eq(account_number_attributes[:institution_number])
92
+ expect(response.first.member_guid).to eq(account_number_attributes[:member_guid])
93
+ expect(response.first.routing_number).to eq(account_number_attributes[:routing_number])
94
+ expect(response.first.transit_number).to eq(account_number_attributes[:transit_number])
95
+ expect(response.first.user_guid).to eq(account_number_attributes[:user_guid])
96
+ expect(response.length).to eq(1)
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::MXPlatformRuby::AccountOwner do
6
+ let(:account_owner_attributes) do
7
+ {
8
+ account_guid: 'ACT-06d7f44b-caae-0f6e-1384-01f52e75dcb1',
9
+ address: '123 This Way',
10
+ city: 'Middlesex',
11
+ country: 'US',
12
+ email: 'donnie@darko.co',
13
+ guid: 'ACO-63dc7714-6fc0-4aa2-a069-c06cdccd1af9',
14
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
15
+ owner_name: 'Donnie Darko',
16
+ phone: '555-555-5555',
17
+ postal_code: '00000-0000',
18
+ state: 'VA',
19
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
20
+ }
21
+ end
22
+ let(:list_account_owners_options) do
23
+ {
24
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
25
+ page: 1,
26
+ records_per_page: 10,
27
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
28
+ }
29
+ end
30
+ let(:pagination_attributes) do
31
+ {
32
+ 'current_page' => 1,
33
+ 'per_page' => 25,
34
+ 'total_pages' => 1,
35
+ 'total_entries' => 1
36
+ }
37
+ end
38
+
39
+ context 'list_account_owners endpoints' do
40
+ let(:list_account_owners_response) do
41
+ {
42
+ 'account_owners' => [account_owner_attributes],
43
+ 'pagination' => pagination_attributes
44
+ }
45
+ end
46
+
47
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(list_account_owners_response) }
48
+
49
+ describe 'list_account_owners' do
50
+ it 'returns a list of account_owners' do
51
+ response = described_class.list_account_owners
52
+
53
+ expect(response).to be_kind_of(::MXPlatformRuby::Page)
54
+ expect(response.first).to be_kind_of(::MXPlatformRuby::AccountOwner)
55
+ expect(response.first.account_guid).to eq(account_owner_attributes[:account_guid])
56
+ expect(response.first.address).to eq(account_owner_attributes[:address])
57
+ expect(response.first.city).to eq(account_owner_attributes[:city])
58
+ expect(response.first.country).to eq(account_owner_attributes[:country])
59
+ expect(response.first.email).to eq(account_owner_attributes[:email])
60
+ expect(response.first.guid).to eq(account_owner_attributes[:guid])
61
+ expect(response.first.member_guid).to eq(account_owner_attributes[:member_guid])
62
+ expect(response.first.owner_name).to eq(account_owner_attributes[:owner_name])
63
+ expect(response.first.phone).to eq(account_owner_attributes[:phone])
64
+ expect(response.first.postal_code).to eq(account_owner_attributes[:postal_code])
65
+ expect(response.first.state).to eq(account_owner_attributes[:state])
66
+ expect(response.first.user_guid).to eq(account_owner_attributes[:user_guid])
67
+ expect(response.length).to eq(1)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,267 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::MXPlatformRuby::Account do
6
+ let(:account_attributes) do
7
+ {
8
+ account_number: '5366',
9
+ apr: 1.0,
10
+ apy: 1.0,
11
+ available_balance: 1000.0,
12
+ available_credit: 1000.0,
13
+ balance: 1000.0,
14
+ cash_balance: 1000.0,
15
+ cash_surrender_value: 1000.0,
16
+ created_at: '2016-10-13T17:57:37.000Z',
17
+ credit_limit: 100.0,
18
+ currency_code: 'USD',
19
+ day_payment_is_due: 20,
20
+ death_benefit: 1000,
21
+ guid: 'ACT-06d7f44b-caae-0f6e-1384-01f52e75dcb1',
22
+ holdings_value: 1000.0,
23
+ id: '1040434698',
24
+ institution_code: 'chase',
25
+ insured_name: 'Frodo Baggins',
26
+ interest_rate: 1.0,
27
+ is_closed: false,
28
+ is_hidden: false,
29
+ last_payment: 100.0,
30
+ last_payment_at: '2015-10-13T17:57:37.000Z',
31
+ loan_amount: 1000.0,
32
+ matures_on: '2015-10-13T17:57:37.000Z',
33
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
34
+ minimum_balance: 100.0,
35
+ minimum_payment: 10.0,
36
+ name: 'Test account 2',
37
+ original_balance: 10.0,
38
+ pay_out_amount: 10.0,
39
+ payment_due_at: '2015-10-13T17:57:37.000Z',
40
+ payoff_balance: 10.0,
41
+ premium_amount: 1.0,
42
+ started_on: '2015-10-13T17:57:37.000Z',
43
+ subtype: 'NONE',
44
+ total_account_value: 1.0,
45
+ type: 'SAVINGS',
46
+ updated_at: '2016-10-13T18:08:00.000Z',
47
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
48
+ }
49
+ end
50
+ let(:list_user_accounts_options) do
51
+ {
52
+ page: 1,
53
+ records_per_page: 10,
54
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
55
+ }
56
+ end
57
+ let(:read_account_options) do
58
+ {
59
+ account_guid: 'ACT-06d7f44b-caae-0f6e-1384-01f52e75dcb1',
60
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
61
+ }
62
+ end
63
+ let(:update_account_options) do
64
+ {
65
+ account_guid: 'ACT-06d7f44b-caae-0f6e-1384-01f52e75dcb1',
66
+ is_hidden: false,
67
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
68
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
69
+ }
70
+ end
71
+ let(:pagination_attributes) do
72
+ {
73
+ 'current_page' => 1,
74
+ 'per_page' => 25,
75
+ 'total_pages' => 1,
76
+ 'total_entries' => 1
77
+ }
78
+ end
79
+
80
+ context 'list_user_accounts endpoints' do
81
+ let(:list_user_accounts_response) do
82
+ {
83
+ 'accounts' => [account_attributes],
84
+ 'pagination' => pagination_attributes
85
+ }
86
+ end
87
+
88
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(list_user_accounts_response) }
89
+
90
+ describe 'list_user_accounts' do
91
+ it 'returns a list of accounts' do
92
+ response = described_class.list_user_accounts
93
+
94
+ expect(response).to be_kind_of(::MXPlatformRuby::Page)
95
+ expect(response.first).to be_kind_of(::MXPlatformRuby::Account)
96
+ expect(response.first.account_number).to eq(account_attributes[:account_number])
97
+ expect(response.first.apr).to eq(account_attributes[:apr])
98
+ expect(response.first.apy).to eq(account_attributes[:apy])
99
+ expect(response.first.available_balance).to eq(account_attributes[:available_balance])
100
+ expect(response.first.available_credit).to eq(account_attributes[:available_credit])
101
+ expect(response.first.balance).to eq(account_attributes[:balance])
102
+ expect(response.first.cash_balance).to eq(account_attributes[:cash_balance])
103
+ expect(response.first.cash_surrender_value).to eq(account_attributes[:cash_surrender_value])
104
+ expect(response.first.created_at).to eq(account_attributes[:created_at])
105
+ expect(response.first.credit_limit).to eq(account_attributes[:credit_limit])
106
+ expect(response.first.currency_code).to eq(account_attributes[:currency_code])
107
+ expect(response.first.day_payment_is_due).to eq(account_attributes[:day_payment_is_due])
108
+ expect(response.first.death_benefit).to eq(account_attributes[:death_benefit])
109
+ expect(response.first.guid).to eq(account_attributes[:guid])
110
+ expect(response.first.holdings_value).to eq(account_attributes[:holdings_value])
111
+ expect(response.first.id).to eq(account_attributes[:id])
112
+ expect(response.first.institution_code).to eq(account_attributes[:institution_code])
113
+ expect(response.first.insured_name).to eq(account_attributes[:insured_name])
114
+ expect(response.first.interest_rate).to eq(account_attributes[:interest_rate])
115
+ expect(response.first.is_closed).to eq(account_attributes[:is_closed])
116
+ expect(response.first.is_hidden).to eq(account_attributes[:is_hidden])
117
+ expect(response.first.last_payment).to eq(account_attributes[:last_payment])
118
+ expect(response.first.last_payment_at).to eq(account_attributes[:last_payment_at])
119
+ expect(response.first.loan_amount).to eq(account_attributes[:loan_amount])
120
+ expect(response.first.matures_on).to eq(account_attributes[:matures_on])
121
+ expect(response.first.member_guid).to eq(account_attributes[:member_guid])
122
+ expect(response.first.minimum_balance).to eq(account_attributes[:minimum_balance])
123
+ expect(response.first.minimum_payment).to eq(account_attributes[:minimum_payment])
124
+ expect(response.first.name).to eq(account_attributes[:name])
125
+ expect(response.first.original_balance).to eq(account_attributes[:original_balance])
126
+ expect(response.first.pay_out_amount).to eq(account_attributes[:pay_out_amount])
127
+ expect(response.first.payment_due_at).to eq(account_attributes[:payment_due_at])
128
+ expect(response.first.payoff_balance).to eq(account_attributes[:payoff_balance])
129
+ expect(response.first.premium_amount).to eq(account_attributes[:premium_amount])
130
+ expect(response.first.started_on).to eq(account_attributes[:started_on])
131
+ expect(response.first.subtype).to eq(account_attributes[:subtype])
132
+ expect(response.first.total_account_value).to eq(account_attributes[:total_account_value])
133
+ expect(response.first.type).to eq(account_attributes[:type])
134
+ expect(response.first.updated_at).to eq(account_attributes[:updated_at])
135
+ expect(response.first.user_guid).to eq(account_attributes[:user_guid])
136
+ expect(response.length).to eq(1)
137
+ end
138
+ end
139
+ end
140
+
141
+ describe 'read_account' do
142
+ let(:read_account_response) { { 'account' => account_attributes } }
143
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(read_account_response) }
144
+
145
+ it 'returns account' do
146
+ response = described_class.read_account
147
+
148
+ expect(response).to be_kind_of(::MXPlatformRuby::Account)
149
+ expect(response.account_number).to eq(account_attributes[:account_number])
150
+ expect(response.apr).to eq(account_attributes[:apr])
151
+ expect(response.apy).to eq(account_attributes[:apy])
152
+ expect(response.available_balance).to eq(account_attributes[:available_balance])
153
+ expect(response.available_credit).to eq(account_attributes[:available_credit])
154
+ expect(response.balance).to eq(account_attributes[:balance])
155
+ expect(response.cash_balance).to eq(account_attributes[:cash_balance])
156
+ expect(response.cash_surrender_value).to eq(account_attributes[:cash_surrender_value])
157
+ expect(response.created_at).to eq(account_attributes[:created_at])
158
+ expect(response.credit_limit).to eq(account_attributes[:credit_limit])
159
+ expect(response.currency_code).to eq(account_attributes[:currency_code])
160
+ expect(response.day_payment_is_due).to eq(account_attributes[:day_payment_is_due])
161
+ expect(response.death_benefit).to eq(account_attributes[:death_benefit])
162
+ expect(response.guid).to eq(account_attributes[:guid])
163
+ expect(response.holdings_value).to eq(account_attributes[:holdings_value])
164
+ expect(response.id).to eq(account_attributes[:id])
165
+ expect(response.institution_code).to eq(account_attributes[:institution_code])
166
+ expect(response.insured_name).to eq(account_attributes[:insured_name])
167
+ expect(response.interest_rate).to eq(account_attributes[:interest_rate])
168
+ expect(response.is_closed).to eq(account_attributes[:is_closed])
169
+ expect(response.is_hidden).to eq(account_attributes[:is_hidden])
170
+ expect(response.last_payment).to eq(account_attributes[:last_payment])
171
+ expect(response.last_payment_at).to eq(account_attributes[:last_payment_at])
172
+ expect(response.loan_amount).to eq(account_attributes[:loan_amount])
173
+ expect(response.matures_on).to eq(account_attributes[:matures_on])
174
+ expect(response.member_guid).to eq(account_attributes[:member_guid])
175
+ expect(response.minimum_balance).to eq(account_attributes[:minimum_balance])
176
+ expect(response.minimum_payment).to eq(account_attributes[:minimum_payment])
177
+ expect(response.name).to eq(account_attributes[:name])
178
+ expect(response.original_balance).to eq(account_attributes[:original_balance])
179
+ expect(response.pay_out_amount).to eq(account_attributes[:pay_out_amount])
180
+ expect(response.payment_due_at).to eq(account_attributes[:payment_due_at])
181
+ expect(response.payoff_balance).to eq(account_attributes[:payoff_balance])
182
+ expect(response.premium_amount).to eq(account_attributes[:premium_amount])
183
+ expect(response.started_on).to eq(account_attributes[:started_on])
184
+ expect(response.subtype).to eq(account_attributes[:subtype])
185
+ expect(response.total_account_value).to eq(account_attributes[:total_account_value])
186
+ expect(response.type).to eq(account_attributes[:type])
187
+ expect(response.updated_at).to eq(account_attributes[:updated_at])
188
+ expect(response.user_guid).to eq(account_attributes[:user_guid])
189
+ end
190
+
191
+ it 'makes a client request with the expected params' do
192
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
193
+ {
194
+ endpoint: '/users/USR-fa7537f3-48aa-a683-a02a-b18940482f54/accounts/ACT-06d7f44b-caae-0f6e-1384-01f52e75dcb1',
195
+ http_method: :get
196
+ }
197
+ )
198
+ described_class.read_account(read_account_options)
199
+ end
200
+ end
201
+
202
+ describe 'update_account' do
203
+ let(:update_account_response) { { 'account' => account_attributes } }
204
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(update_account_response) }
205
+
206
+ it 'returns account' do
207
+ response = described_class.update_account
208
+
209
+ expect(response).to be_kind_of(::MXPlatformRuby::Account)
210
+ expect(response.account_number).to eq(account_attributes[:account_number])
211
+ expect(response.apr).to eq(account_attributes[:apr])
212
+ expect(response.apy).to eq(account_attributes[:apy])
213
+ expect(response.available_balance).to eq(account_attributes[:available_balance])
214
+ expect(response.available_credit).to eq(account_attributes[:available_credit])
215
+ expect(response.balance).to eq(account_attributes[:balance])
216
+ expect(response.cash_balance).to eq(account_attributes[:cash_balance])
217
+ expect(response.cash_surrender_value).to eq(account_attributes[:cash_surrender_value])
218
+ expect(response.created_at).to eq(account_attributes[:created_at])
219
+ expect(response.credit_limit).to eq(account_attributes[:credit_limit])
220
+ expect(response.currency_code).to eq(account_attributes[:currency_code])
221
+ expect(response.day_payment_is_due).to eq(account_attributes[:day_payment_is_due])
222
+ expect(response.death_benefit).to eq(account_attributes[:death_benefit])
223
+ expect(response.guid).to eq(account_attributes[:guid])
224
+ expect(response.holdings_value).to eq(account_attributes[:holdings_value])
225
+ expect(response.id).to eq(account_attributes[:id])
226
+ expect(response.institution_code).to eq(account_attributes[:institution_code])
227
+ expect(response.insured_name).to eq(account_attributes[:insured_name])
228
+ expect(response.interest_rate).to eq(account_attributes[:interest_rate])
229
+ expect(response.is_closed).to eq(account_attributes[:is_closed])
230
+ expect(response.is_hidden).to eq(account_attributes[:is_hidden])
231
+ expect(response.last_payment).to eq(account_attributes[:last_payment])
232
+ expect(response.last_payment_at).to eq(account_attributes[:last_payment_at])
233
+ expect(response.loan_amount).to eq(account_attributes[:loan_amount])
234
+ expect(response.matures_on).to eq(account_attributes[:matures_on])
235
+ expect(response.member_guid).to eq(account_attributes[:member_guid])
236
+ expect(response.minimum_balance).to eq(account_attributes[:minimum_balance])
237
+ expect(response.minimum_payment).to eq(account_attributes[:minimum_payment])
238
+ expect(response.name).to eq(account_attributes[:name])
239
+ expect(response.original_balance).to eq(account_attributes[:original_balance])
240
+ expect(response.pay_out_amount).to eq(account_attributes[:pay_out_amount])
241
+ expect(response.payment_due_at).to eq(account_attributes[:payment_due_at])
242
+ expect(response.payoff_balance).to eq(account_attributes[:payoff_balance])
243
+ expect(response.premium_amount).to eq(account_attributes[:premium_amount])
244
+ expect(response.started_on).to eq(account_attributes[:started_on])
245
+ expect(response.subtype).to eq(account_attributes[:subtype])
246
+ expect(response.total_account_value).to eq(account_attributes[:total_account_value])
247
+ expect(response.type).to eq(account_attributes[:type])
248
+ expect(response.updated_at).to eq(account_attributes[:updated_at])
249
+ expect(response.user_guid).to eq(account_attributes[:user_guid])
250
+ end
251
+
252
+ it 'makes a client request with the expected params' do
253
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
254
+ {
255
+ endpoint: '/users/USR-fa7537f3-48aa-a683-a02a-b18940482f54/members/MBR-7c6f361b-e582-15b6-60c0-358f12466b4b/accounts/ACT-06d7f44b-caae-0f6e-1384-01f52e75dcb1',
256
+ http_method: :put,
257
+ request_body: {
258
+ account: {
259
+ is_hidden: false
260
+ }
261
+ }
262
+ }
263
+ )
264
+ described_class.update_account(update_account_options)
265
+ end
266
+ end
267
+ end