finapps 4.0.6 → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/lib/finapps.rb +8 -0
  4. data/lib/finapps/rest/alert_definitions.rb +24 -0
  5. data/lib/finapps/rest/alert_occurrences.rb +25 -0
  6. data/lib/finapps/rest/client.rb +8 -0
  7. data/lib/finapps/rest/consumers_portfolios.rb +20 -0
  8. data/lib/finapps/rest/portfolio_reports.rb +18 -0
  9. data/lib/finapps/rest/portfolios.rb +43 -0
  10. data/lib/finapps/rest/portfolios_alerts.rb +34 -0
  11. data/lib/finapps/rest/portfolios_available_consumers.rb +20 -0
  12. data/lib/finapps/rest/portfolios_consumers.rb +45 -0
  13. data/lib/finapps/utils/query_builder.rb +5 -0
  14. data/lib/finapps/version.rb +1 -1
  15. data/spec/rest/alert_definitions_spec.rb +78 -0
  16. data/spec/rest/alert_occurrences_spec.rb +44 -0
  17. data/spec/rest/client_spec.rb +34 -0
  18. data/spec/rest/consumers_portfolios_spec.rb +54 -0
  19. data/spec/rest/portfolio_reports_spec.rb +44 -0
  20. data/spec/rest/portfolios_alerts_spec.rb +125 -0
  21. data/spec/rest/portfolios_available_consumers_spec.rb +54 -0
  22. data/spec/rest/portfolios_consumers_spec.rb +183 -0
  23. data/spec/rest/portfolios_spec.rb +181 -0
  24. data/spec/support/fake_api.rb +54 -0
  25. data/spec/support/fixtures/alert_definition.json +17 -0
  26. data/spec/support/fixtures/alert_definitions.json +24 -0
  27. data/spec/support/fixtures/alert_occurrences.json +32 -0
  28. data/spec/support/fixtures/multiple_consumer_subscribe_error.json +7 -0
  29. data/spec/support/fixtures/portfolio.json +9 -0
  30. data/spec/support/fixtures/portfolio_reports.json +38 -0
  31. data/spec/support/fixtures/portfolios.json +16 -0
  32. data/spec/support/fixtures/portfolios_alerts.json +19 -0
  33. data/spec/support/fixtures/portfolios_available_consumers.json +20 -0
  34. data/spec/support/fixtures/portfolios_consumers.json +14 -0
  35. data/spec/support/fixtures/single_consumer_subscribe_error.json +5 -0
  36. metadata +58 -23
@@ -16,6 +16,14 @@ RSpec.describe FinApps::REST::Client do
16
16
  end
17
17
  end
18
18
 
19
+ describe '#alert_definitions' do
20
+ it { expect(subject.alert_definitions).to be_an_instance_of(FinApps::REST::AlertDefinitions) }
21
+ end
22
+
23
+ describe '#alert_occurrences' do
24
+ it { expect(subject.alert_occurrences).to be_an_instance_of(FinApps::REST::AlertOccurrences) }
25
+ end
26
+
19
27
  describe '#version' do
20
28
  it { expect(subject.version).to be_an_instance_of(FinApps::REST::Version) }
21
29
  end
@@ -98,6 +106,32 @@ RSpec.describe FinApps::REST::Client do
98
106
  it { expect(subject.products).to be_an_instance_of(FinApps::REST::Products) }
99
107
  end
100
108
 
109
+ describe '#portfolios' do
110
+ it { expect(subject.portfolios).to be_an_instance_of(FinApps::REST::Portfolios) }
111
+ end
112
+
113
+ describe '#portfolios_alerts' do
114
+ it { expect(subject.portfolios_alerts).to be_an_instance_of(FinApps::REST::PortfoliosAlerts) }
115
+ end
116
+
117
+ describe '#portfolios_available_consumers' do
118
+ it {
119
+ expect(subject.portfolios_available_consumers).to be_an_instance_of(FinApps::REST::PortfoliosAvailableConsumers)
120
+ }
121
+ end
122
+
123
+ describe '#portfolios_consumers' do
124
+ it { expect(subject.portfolios_consumers).to be_an_instance_of(FinApps::REST::PortfoliosConsumers) }
125
+ end
126
+
127
+ describe '#consumers_portfolios' do
128
+ it { expect(subject.consumers_portfolios).to be_an_instance_of(FinApps::REST::ConsumersPortfolios) }
129
+ end
130
+
131
+ describe '#portfolio_reports' do
132
+ it { expect(subject.portfolio_reports).to be_an_instance_of(FinApps::REST::PortfolioReports) }
133
+ end
134
+
101
135
  describe '#statements' do
102
136
  it { expect(subject.statements).to be_an_instance_of(FinApps::REST::Statements) }
103
137
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helpers/client'
4
+
5
+ RSpec.describe FinApps::REST::ConsumersPortfolios do
6
+ include SpecHelpers::Client
7
+ subject { FinApps::REST::ConsumersPortfolios.new(client) }
8
+
9
+ describe '#list' do
10
+ let(:list) { subject.list(id, params) }
11
+ let(:results) { list[RESULTS] }
12
+ let(:errors) { list[ERROR_MESSAGES] }
13
+
14
+ context 'when missing id' do
15
+ let(:id) { nil }
16
+ let(:params) { nil }
17
+
18
+ it { expect { list }.to raise_error(FinAppsCore::MissingArgumentsError) }
19
+ end
20
+
21
+ context 'when missing params' do
22
+ let(:id) { 'valid_id' }
23
+ let(:params) { nil }
24
+
25
+ it { expect { list }.not_to raise_error }
26
+ it('returns an array') { expect(list).to be_a(Array) }
27
+ it('performs a get and returns the response') { expect(results).to respond_to(:records) }
28
+ it('returns no error messages') { expect(errors).to be_empty }
29
+ end
30
+
31
+ context 'when invalid params are provided' do
32
+ let(:id) { 'valid_id' }
33
+ let(:params) { %w[this is an array] }
34
+
35
+ it { expect { list }.to raise_error(FinAppsCore::InvalidArgumentsError) }
36
+ end
37
+
38
+ context 'when including valid params' do
39
+ let(:id) { 'valid_id' }
40
+ let(:params) { { page: 2, sort: '-created_date', requested: 25 } }
41
+
42
+ it { expect { list }.not_to raise_error }
43
+ it('returns an array') { expect(list).to be_a(Array) }
44
+ it('performs a get and returns the response') { expect(results).to respond_to(:records) }
45
+ it('returns no error messages') { expect(errors).to be_empty }
46
+ it 'builds query and sends proper request' do
47
+ list
48
+ url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v3/consumers/#{id}/portfolios?page=2&" \
49
+ 'requested=25&sort=-created_date'
50
+ expect(WebMock).to have_requested(:get, url)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helpers/client'
4
+
5
+ RSpec.describe FinApps::REST::PortfolioReports do
6
+ include SpecHelpers::Client
7
+ subject { FinApps::REST::PortfolioReports.new(client) }
8
+
9
+ describe '#list' do
10
+ let(:list) { subject.list(params) }
11
+ let(:results) { list[RESULTS] }
12
+ let(:errors) { list[ERROR_MESSAGES] }
13
+
14
+ context 'when missing params' do
15
+ let(:params) { nil }
16
+
17
+ it { expect { list }.not_to raise_error }
18
+ it('returns an array') { expect(list).to be_a(Array) }
19
+ it('performs a get and returns the response') { expect(results).to respond_to(:records) }
20
+ it('returns no error messages') { expect(errors).to be_empty }
21
+ end
22
+
23
+ context 'when invalid params are provided' do
24
+ let(:params) { %w[this is an array] }
25
+
26
+ it { expect { list }.to raise_error(FinAppsCore::InvalidArgumentsError) }
27
+ end
28
+
29
+ context 'when including valid params' do
30
+ let(:params) { { page: 2, sort: '-created_date', requested: 25 } }
31
+
32
+ it { expect { list }.not_to raise_error }
33
+ it('returns an array') { expect(list).to be_a(Array) }
34
+ it('performs a get and returns the response') { expect(results).to respond_to(:records) }
35
+ it('returns no error messages') { expect(errors).to be_empty }
36
+ it 'builds query and sends proper request' do
37
+ list
38
+ url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v3/portfolio/reports?page=2&requested=25&" \
39
+ 'sort=-created_date'
40
+ expect(WebMock).to have_requested(:get, url)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helpers/client'
4
+
5
+ RSpec.describe FinApps::REST::PortfoliosAlerts do
6
+ include SpecHelpers::Client
7
+ subject { FinApps::REST::PortfoliosAlerts.new(client) }
8
+
9
+ describe '#list' do
10
+ let(:list) { subject.list(id) }
11
+ let(:results) { list[RESULTS] }
12
+ let(:errors) { list[ERROR_MESSAGES] }
13
+
14
+ context 'when missing id' do
15
+ let(:id) { nil }
16
+
17
+ it { expect { list }.to raise_error(FinAppsCore::MissingArgumentsError) }
18
+ end
19
+
20
+ context 'when valid id is provided' do
21
+ let(:id) { 'valid_id' }
22
+
23
+ it { expect { list }.not_to raise_error }
24
+ it('returns an array') { expect(list).to be_a(Array) }
25
+ it('performs a get and returns array of alert definitions') do
26
+ expect(results).to be_a(Array)
27
+ expect(results.first).to respond_to(:_id)
28
+ expect(results.first).to respond_to(:rule_name)
29
+ end
30
+ it('returns no error messages') { expect(errors).to be_empty }
31
+ end
32
+
33
+ context 'when invalid id is provided' do
34
+ let(:id) { 'invalid_id' }
35
+
36
+ it { expect { list }.not_to raise_error }
37
+ it('results is nil') { expect(results).to be_nil }
38
+ it('error messages array is populated') do
39
+ expect(errors.first.downcase).to eq('resource not found')
40
+ end
41
+ end
42
+ end
43
+
44
+ describe '#create' do
45
+ let(:create) { subject.create(portfolio_id, alert_id) }
46
+ let(:results) { create[RESULTS] }
47
+ let(:errors) { create[ERROR_MESSAGES] }
48
+
49
+ context 'when missing portfolio_id' do
50
+ let(:portfolio_id) { nil }
51
+ let(:alert_id) { 'valid_id' }
52
+
53
+ it { expect { create }.to raise_error(FinAppsCore::MissingArgumentsError) }
54
+ end
55
+
56
+ context 'when missing alert_id' do
57
+ let(:portfolio_id) { 'valid_id' }
58
+ let(:alert_id) { nil }
59
+
60
+ it { expect { create }.to raise_error(FinAppsCore::MissingArgumentsError) }
61
+ end
62
+
63
+ context 'when valid ids are provided' do
64
+ let(:portfolio_id) { 'valid_id' }
65
+ let(:alert_id) { portfolio_id }
66
+
67
+ it { expect { create }.not_to raise_error(FinAppsCore::MissingArgumentsError) }
68
+ it('returns an array') { expect(create).to be_a(Array) }
69
+ it('results is nil') { expect(results).to be_nil }
70
+ it('returns no error messages') { expect(errors).to be_empty }
71
+ end
72
+
73
+ context 'when invalid ids are provided' do
74
+ let(:portfolio_id) { 'invalid_id' }
75
+ let(:alert_id) { portfolio_id }
76
+
77
+ it { expect { create }.not_to raise_error(FinAppsCore::MissingArgumentsError) }
78
+ it('results is nil') { expect(results).to be_nil }
79
+ it('error messages array is populated') do
80
+ expect(errors.first.downcase).to eq('resource not found')
81
+ end
82
+ end
83
+ end
84
+
85
+ describe '#destroy' do
86
+ let(:destroy) { subject.destroy(portfolio_id, alert_id) }
87
+ let(:results) { destroy[RESULTS] }
88
+ let(:errors) { destroy[ERROR_MESSAGES] }
89
+
90
+ context 'when missing portfolio_id' do
91
+ let(:portfolio_id) { nil }
92
+ let(:alert_id) { 'valid_id' }
93
+
94
+ it { expect { destroy }.to raise_error(FinAppsCore::MissingArgumentsError) }
95
+ end
96
+
97
+ context 'when missing alert_id' do
98
+ let(:portfolio_id) { 'valid_id' }
99
+ let(:alert_id) { nil }
100
+
101
+ it { expect { destroy }.to raise_error(FinAppsCore::MissingArgumentsError) }
102
+ end
103
+
104
+ context 'when valid ids are provided' do
105
+ let(:portfolio_id) { 'valid_id' }
106
+ let(:alert_id) { portfolio_id }
107
+
108
+ it { expect { destroy }.not_to raise_error(FinAppsCore::MissingArgumentsError) }
109
+ it('returns an array') { expect(destroy).to be_a(Array) }
110
+ it('results is nil') { expect(results).to be_nil }
111
+ it('returns no error messages') { expect(errors).to be_empty }
112
+ end
113
+
114
+ context 'when invalid ids are provided' do
115
+ let(:portfolio_id) { 'invalid_id' }
116
+ let(:alert_id) { portfolio_id }
117
+
118
+ it { expect { destroy }.not_to raise_error(FinAppsCore::MissingArgumentsError) }
119
+ it('results is nil') { expect(results).to be_nil }
120
+ it('error messages array is populated') do
121
+ expect(errors.first.downcase).to eq('resource not found')
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helpers/client'
4
+
5
+ RSpec.describe FinApps::REST::PortfoliosAvailableConsumers do
6
+ include SpecHelpers::Client
7
+ subject { FinApps::REST::PortfoliosAvailableConsumers.new(client) }
8
+
9
+ describe '#list' do
10
+ let(:list) { subject.list(id, params) }
11
+ let(:results) { list[RESULTS] }
12
+ let(:errors) { list[ERROR_MESSAGES] }
13
+
14
+ context 'when missing id' do
15
+ let(:id) { nil }
16
+ let(:params) { nil }
17
+
18
+ it { expect { list }.to raise_error(FinAppsCore::MissingArgumentsError) }
19
+ end
20
+
21
+ context 'when missing params' do
22
+ let(:id) { 'valid_id' }
23
+ let(:params) { nil }
24
+
25
+ it { expect { list }.not_to raise_error }
26
+ it('returns an array') { expect(list).to be_a(Array) }
27
+ it('performs a get and returns the response') { expect(results).to respond_to(:records) }
28
+ it('returns no error messages') { expect(errors).to be_empty }
29
+ end
30
+
31
+ context 'when invalid params are provided' do
32
+ let(:id) { 'valid_id' }
33
+ let(:params) { %w[this is an array] }
34
+
35
+ it { expect { list }.to raise_error(FinAppsCore::InvalidArgumentsError) }
36
+ end
37
+
38
+ context 'when including valid params' do
39
+ let(:id) { 'valid_id' }
40
+ let(:params) { { page: 2, sort: '-created_date', requested: 25 } }
41
+
42
+ it { expect { list }.not_to raise_error }
43
+ it('returns an array') { expect(list).to be_a(Array) }
44
+ it('performs a get and returns the response') { expect(results).to respond_to(:records) }
45
+ it('returns no error messages') { expect(errors).to be_empty }
46
+ it 'builds query and sends proper request' do
47
+ list
48
+ url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v3/portfolios/#{id}/consumers/available?page=2&" \
49
+ 'requested=25&sort=-created_date'
50
+ expect(WebMock).to have_requested(:get, url)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,183 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helpers/client'
4
+
5
+ RSpec.describe FinApps::REST::PortfoliosConsumers do
6
+ include SpecHelpers::Client
7
+ subject { FinApps::REST::PortfoliosConsumers.new(client) }
8
+
9
+ describe '#list' do
10
+ let(:list) { subject.list(portfolio_id, params) }
11
+ let(:results) { list[RESULTS] }
12
+ let(:errors) { list[ERROR_MESSAGES] }
13
+
14
+ context 'when missing id' do
15
+ let(:portfolio_id) { nil }
16
+ let(:params) { nil }
17
+
18
+ it { expect { list }.to raise_error(FinAppsCore::MissingArgumentsError) }
19
+ end
20
+
21
+ context 'when invalid params are provided' do
22
+ let(:portfolio_id) { 'valid_id' }
23
+ let(:params) { %w[this is an array] }
24
+
25
+ it { expect { list }.to raise_error(FinAppsCore::InvalidArgumentsError) }
26
+ end
27
+
28
+ context 'when valid id is provided w/o params' do
29
+ let(:portfolio_id) { 'valid_id' }
30
+ let(:params) { nil }
31
+
32
+ it { expect { list }.not_to raise_error }
33
+ it('returns an array') { expect(list).to be_a(Array) }
34
+ it('performs a get and returns the response') { expect(results).to respond_to(:records) }
35
+ it('returns no error messages') { expect(errors).to be_empty }
36
+ end
37
+
38
+ context 'when valid id is provided w/ valid params' do
39
+ let(:portfolio_id) { 'valid_id' }
40
+ let(:params) { { page: 2, sort: '-created_date', requested: 25 } }
41
+
42
+ it { expect { list }.not_to raise_error }
43
+ it('returns an array') { expect(list).to be_a(Array) }
44
+ it('performs a get and returns the response') { expect(results).to respond_to(:records) }
45
+ it('returns no error messages') { expect(errors).to be_empty }
46
+ it 'builds query and sends proper request' do
47
+ list
48
+ url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v3/portfolios/#{portfolio_id}/consumers?page=2&" \
49
+ 'requested=25&sort=-created_date'
50
+ expect(WebMock).to have_requested(:get, url)
51
+ end
52
+ end
53
+
54
+ context 'when invalid id is provided' do
55
+ let(:portfolio_id) { 'invalid_id' }
56
+ let(:params) { nil }
57
+
58
+ it { expect { list }.not_to raise_error }
59
+ it('results is nil') { expect(results).to be_nil }
60
+ it('error messages array is populated') do
61
+ expect(errors.first.downcase).to eq('resource not found')
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#create' do
67
+ let(:create) { subject.create(portfolio_id, params) }
68
+ let(:results) { create[RESULTS] }
69
+ let(:errors) { create[ERROR_MESSAGES] }
70
+
71
+ context 'when missing portfolio_id' do
72
+ let(:portfolio_id) { nil }
73
+ let(:params) { 'valid_id' }
74
+
75
+ it { expect { create }.to raise_error(FinAppsCore::MissingArgumentsError) }
76
+ end
77
+
78
+ context 'when missing params' do
79
+ let(:portfolio_id) { 'valid_id' }
80
+ let(:params) { nil }
81
+
82
+ it { expect { create }.to raise_error(FinAppsCore::MissingArgumentsError) }
83
+ end
84
+
85
+ context 'for bulk subscribe' do
86
+ context 'when valid id and params are provided' do
87
+ let(:portfolio_id) { 'valid_id' }
88
+ let(:params) { %w[id1 id2 id3] }
89
+
90
+ it { expect { create }.not_to raise_error }
91
+ it('returns an array') { expect(create).to be_a(Array) }
92
+ it('results is nil') { expect(results).to be_nil }
93
+ it('returns no error messages') { expect(errors).to be_empty }
94
+ it('builds correct url') do
95
+ create
96
+ url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v3/portfolios/#{portfolio_id}/consumers"
97
+ expect(WebMock).to have_requested(:post, url)
98
+ end
99
+ end
100
+
101
+ context 'when invalid id and params are provided' do
102
+ let(:portfolio_id) { 'invalid_id' }
103
+ let(:params) { %w[id1 id2 id3] }
104
+
105
+ it { expect { create }.not_to raise_error }
106
+ it('results is nil') { expect(results).to be_nil }
107
+ it('error messages array is populated') do
108
+ # this will break when client is fixed to expect new array error response
109
+ expect(errors.first.downcase).to eq('the server responded with status 400')
110
+ end
111
+ end
112
+ end
113
+
114
+ context 'for single subscribe' do
115
+ context 'when valid ids are provided' do
116
+ let(:portfolio_id) { 'valid_id' }
117
+ let(:params) { portfolio_id }
118
+
119
+ it { expect { create }.not_to raise_error }
120
+ it('returns an array') { expect(create).to be_a(Array) }
121
+ it('results is nil') { expect(results).to be_nil }
122
+ it('returns no error messages') { expect(errors).to be_empty }
123
+ it('builds correct url') do
124
+ create
125
+ url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v3/portfolios/#{portfolio_id}/consumers/#{params}"
126
+ expect(WebMock).to have_requested(:post, url)
127
+ end
128
+ end
129
+
130
+ context 'when invalid ids are provided' do
131
+ let(:portfolio_id) { 'invalid_id' }
132
+ let(:params) { portfolio_id }
133
+
134
+ it { expect { create }.not_to raise_error }
135
+ it('results is nil') { expect(results).to be_nil }
136
+ it('error messages array is populated') do
137
+ expect(errors.first.downcase).to eq('consumer not eligible, no completed orders.')
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ describe '#destroy' do
144
+ let(:destroy) { subject.destroy(portfolio_id, consumer_id) }
145
+ let(:results) { destroy[RESULTS] }
146
+ let(:errors) { destroy[ERROR_MESSAGES] }
147
+
148
+ context 'when missing portfolio_id' do
149
+ let(:portfolio_id) { nil }
150
+ let(:consumer_id) { 'valid_id' }
151
+
152
+ it { expect { destroy }.to raise_error(FinAppsCore::MissingArgumentsError) }
153
+ end
154
+
155
+ context 'when missing consumer_id' do
156
+ let(:portfolio_id) { 'valid_id' }
157
+ let(:consumer_id) { nil }
158
+
159
+ it { expect { destroy }.to raise_error(FinAppsCore::MissingArgumentsError) }
160
+ end
161
+
162
+ context 'when valid ids are provided' do
163
+ let(:portfolio_id) { 'valid_id' }
164
+ let(:consumer_id) { portfolio_id }
165
+
166
+ it { expect { destroy }.not_to raise_error }
167
+ it('returns an array') { expect(destroy).to be_a(Array) }
168
+ it('results is nil') { expect(results).to be_nil }
169
+ it('returns no error messages') { expect(errors).to be_empty }
170
+ end
171
+
172
+ context 'when invalid ids are provided' do
173
+ let(:portfolio_id) { 'invalid_id' }
174
+ let(:consumer_id) { portfolio_id }
175
+
176
+ it { expect { destroy }.not_to raise_error }
177
+ it('results is nil') { expect(results).to be_nil }
178
+ it('error messages array is populated') do
179
+ expect(errors.first.downcase).to eq('resource not found')
180
+ end
181
+ end
182
+ end
183
+ end