finapps 5.0.34 → 5.0.35

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,308 +1,309 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helpers/client'
4
- RSpec.describe FinApps::REST::Consumers,
5
- 'initialized with valid FinApps::Client object' do
6
- include SpecHelpers::Client
7
- subject(:users) { described_class.new(client) }
8
-
9
- missing_public_id = ': public_id'
10
-
11
- describe '#create' do
12
- let(:results) { create[0] }
13
- let(:error_messages) { create[1] }
14
-
15
- context 'when missing params' do
16
- it do
17
- expect { subject.create(nil) }.to raise_error(
18
- FinAppsCore::MissingArgumentsError
19
- )
20
- end
21
- end
4
+ RSpec.describe FinApps::REST::Consumers do
5
+ context 'when initialized with valid FinApps::Client object' do
6
+ include SpecHelpers::Client
7
+ subject(:users) { described_class.new(client) }
22
8
 
23
- context 'for valid params' do
24
- let(:create) { subject.create(email: 'email', password: 'password') }
9
+ missing_public_id = ': public_id'
25
10
 
26
- it { expect { create }.not_to raise_error }
27
- it('results is a Hash') { expect(results).to be_a(Hash) }
11
+ describe '#create' do
12
+ let(:results) { create[0] }
13
+ let(:error_messages) { create[1] }
28
14
 
29
- it('performs a post and returns the response') do
30
- expect(results).to have_key(:public_id)
15
+ context 'when missing params' do
16
+ it do
17
+ expect { users.create(nil) }.to raise_error(
18
+ FinAppsCore::MissingArgumentsError
19
+ )
20
+ end
31
21
  end
32
22
 
33
- it('error_messages array is empty') { expect(error_messages).to eq([]) }
34
- end
23
+ context 'with valid params' do
24
+ let(:create) { subject.create(email: 'email', password: 'password') }
35
25
 
36
- context 'for invalid params' do
37
- let(:create) { subject.create(email: 'email') }
26
+ it { expect { create }.not_to raise_error }
27
+ it('results is a Hash') { expect(results).to be_a(Hash) }
38
28
 
39
- it { expect { create }.not_to raise_error }
40
- it('results is nil') { expect(results).to be_nil }
29
+ it('performs a post and returns the response') do
30
+ expect(results).to have_key(:public_id)
31
+ end
41
32
 
42
- it('error messages array is populated') do
43
- expect(error_messages.first.downcase).to eq('invalid request body')
33
+ it('error_messages array is empty') { expect(error_messages).to eq([]) }
44
34
  end
45
- end
46
- end
47
35
 
48
- describe '#list' do
49
- let(:list) { subject.list(params) }
50
- let(:results) { list[0] }
51
- let(:error_messages) { list[1] }
36
+ context 'with invalid params' do
37
+ let(:create) { subject.create(email: 'email') }
52
38
 
53
- context 'when missing params' do
54
- let(:params) { nil }
55
-
56
- it { expect { list }.not_to raise_error }
39
+ it { expect { create }.not_to raise_error }
40
+ it('results is nil') { expect(results).to be_nil }
57
41
 
58
- it('performs a get and returns the response') do
59
- expect(results).to have_key(:records)
42
+ it('error messages array is populated') do
43
+ expect(error_messages.first.downcase).to eq('invalid request body')
44
+ end
60
45
  end
61
-
62
- it('returns an array of records') { expect(results[:records]).to be_a(Array) }
63
- it('returns no error messages') { expect(error_messages).to be_empty }
64
46
  end
65
47
 
66
- context 'when invalid params are provided' do
67
- let(:params) { ['invalid array'] }
48
+ describe '#list' do
49
+ let(:list) { subject.list(params) }
50
+ let(:results) { list[0] }
51
+ let(:error_messages) { list[1] }
68
52
 
69
- it { expect { list }.to raise_error(FinAppsCore::InvalidArgumentsError) }
70
- end
53
+ context 'when missing params' do
54
+ let(:params) { nil }
71
55
 
72
- context 'when including valid params without searchTerm' do
73
- let(:params) do
74
- {
75
- page: 3,
76
- requested: 19
77
- }
78
- end
56
+ it { expect { list }.not_to raise_error }
79
57
 
80
- it { expect { list }.not_to raise_error }
81
- it('returns an array') { expect(list).to be_a(Array) }
58
+ it('performs a get and returns the response') do
59
+ expect(results).to have_key(:records)
60
+ end
82
61
 
83
- it('performs a get and returns the response') do
84
- expect(results).to have_key(:records)
62
+ it('returns an array of records') { expect(results[:records]).to be_a(Array) }
63
+ it('returns no error messages') { expect(error_messages).to be_empty }
85
64
  end
86
65
 
87
- it('returns no error messages') do
88
- expect(error_messages).to be_empty
89
- end
66
+ context 'when invalid params are provided' do
67
+ let(:params) { ['invalid array'] }
90
68
 
91
- it 'builds query and sends proper request' do
92
- list
93
- url = "#{versioned_api_path}/consumers?page=3&requested=19"
94
- expect(WebMock).to have_requested(:get, url)
69
+ it { expect { list }.to raise_error(FinAppsCore::InvalidArgumentsError) }
95
70
  end
96
- end
97
71
 
98
- context 'when including valid params with searchTerm' do
99
- let(:params) do
100
- {
101
- page: 2,
102
- sort: 'date_created',
103
- requested: 25,
104
- searchTerm: 'term'
105
- }
106
- end
72
+ context 'when including valid params without searchTerm' do
73
+ let(:params) do
74
+ {
75
+ page: 3,
76
+ requested: 19
77
+ }
78
+ end
107
79
 
108
- it { expect { list }.not_to raise_error }
109
- it('returns an array') { expect(list).to be_a(Array) }
80
+ it { expect { list }.not_to raise_error }
81
+ it('returns an array') { expect(list).to be_a(Array) }
110
82
 
111
- it('performs a get and returns the response') do
112
- expect(results).to have_key(:records)
113
- end
83
+ it('performs a get and returns the response') do
84
+ expect(results).to have_key(:records)
85
+ end
114
86
 
115
- it('returns no error messages') do
116
- expect(error_messages).to be_empty
117
- end
87
+ it('returns no error messages') do
88
+ expect(error_messages).to be_empty
89
+ end
118
90
 
119
- it 'builds query and sends proper request' do
120
- list
121
- url = "#{versioned_api_path}/consumers?"\
122
- 'filter=%7B%22$or%22:%5B%7B%22email%22:%22term%22%7D,' \
123
- '%7B%22first_name%22:%22term%22%7D,'\
124
- '%7B%22last_name%22:%22term%22%7D%5D%7D&page=2&requested=25' \
125
- '&sort=date_created'
126
- expect(WebMock).to have_requested(:get, url)
91
+ it 'builds query and sends proper request' do
92
+ list
93
+ url = "#{versioned_api_path}/consumers?page=3&requested=19"
94
+ expect(WebMock).to have_requested(:get, url)
95
+ end
127
96
  end
128
97
 
129
- context 'when search term contains a space' do
98
+ context 'when including valid params with searchTerm' do
130
99
  let(:params) do
131
100
  {
132
101
  page: 2,
133
102
  sort: 'date_created',
134
103
  requested: 25,
135
- searchTerm: 'Two terms'
104
+ searchTerm: 'term'
136
105
  }
137
106
  end
138
107
 
139
- it 'treats space as start of a new query for first and last name' do
108
+ it { expect { list }.not_to raise_error }
109
+ it('returns an array') { expect(list).to be_a(Array) }
110
+
111
+ it('performs a get and returns the response') do
112
+ expect(results).to have_key(:records)
113
+ end
114
+
115
+ it('returns no error messages') do
116
+ expect(error_messages).to be_empty
117
+ end
118
+
119
+ it 'builds query and sends proper request' do
140
120
  list
141
121
  url = "#{versioned_api_path}/consumers?"\
142
- 'filter=%7B%22$or%22:%5B%7B%22email%22:%22Two%20terms%22%7D,'\
143
- '%7B%22first_name%22:%22Two%20terms%22%7D,'\
144
- '%7B%22last_name%22:%22Two%20terms%22%7D,%7B%22first_name%22:'\
145
- '%22Two%22%7D,%7B%22last_name%22:%22Two%22%7D,'\
146
- '%7B%22first_name%22:%22terms%22%7D,%7B%22last_name%22:'\
147
- '%22terms%22%7D%5D%7D&page=2&requested=25&sort=date_created'
122
+ 'filter=%7B%22$or%22:%5B%7B%22email%22:%22term%22%7D,' \
123
+ '%7B%22first_name%22:%22term%22%7D,'\
124
+ '%7B%22last_name%22:%22term%22%7D%5D%7D&page=2&requested=25' \
125
+ '&sort=date_created'
148
126
  expect(WebMock).to have_requested(:get, url)
149
127
  end
150
- end
151
- end
152
- end
153
128
 
154
- describe '#show' do
155
- context 'when missing public_id' do
156
- it do
157
- expect { subject.show(nil) }.to raise_error(
158
- FinAppsCore::MissingArgumentsError,
159
- missing_public_id
160
- )
129
+ context 'when search term contains a space' do
130
+ let(:params) do
131
+ {
132
+ page: 2,
133
+ sort: 'date_created',
134
+ requested: 25,
135
+ searchTerm: 'Two terms'
136
+ }
137
+ end
138
+
139
+ it 'treats space as start of a new query for first and last name' do
140
+ list
141
+ url = "#{versioned_api_path}/consumers?"\
142
+ 'filter=%7B%22$or%22:%5B%7B%22email%22:%22Two%20terms%22%7D,'\
143
+ '%7B%22first_name%22:%22Two%20terms%22%7D,'\
144
+ '%7B%22last_name%22:%22Two%20terms%22%7D,%7B%22first_name%22:'\
145
+ '%22Two%22%7D,%7B%22last_name%22:%22Two%22%7D,'\
146
+ '%7B%22first_name%22:%22terms%22%7D,%7B%22last_name%22:'\
147
+ '%22terms%22%7D%5D%7D&page=2&requested=25&sort=date_created'
148
+ expect(WebMock).to have_requested(:get, url)
149
+ end
150
+ end
161
151
  end
162
152
  end
163
153
 
164
- context 'for valid public_id' do
165
- let(:show) { subject.show(:valid_public_id) }
166
- let(:results) { show[0] }
167
- let(:error_messages) { show[1] }
168
-
169
- it { expect { show }.not_to raise_error }
170
- it('results is a Hash') { expect(results).to be_a(Hash) }
171
-
172
- it('performs a get and returns the response') do
173
- expect(results).to have_key(:public_id)
154
+ describe '#show' do
155
+ context 'when missing public_id' do
156
+ it do
157
+ expect { users.show(nil) }.to raise_error(
158
+ FinAppsCore::MissingArgumentsError,
159
+ missing_public_id
160
+ )
161
+ end
174
162
  end
175
163
 
176
- it('error_messages array is empty') { expect(error_messages).to eq([]) }
177
- end
178
-
179
- context 'for invalid token' do
180
- let(:show) { subject.show(:invalid_public_id) }
181
- let(:results) { show[0] }
182
- let(:error_messages) { show[1] }
183
-
184
- it { expect { show }.not_to raise_error }
185
- it('results is nil') { expect(results).to be_nil }
164
+ context 'with valid public_id' do
165
+ let(:show) { users.show(:valid_public_id) }
166
+ let(:results) { show[0] }
167
+ let(:error_messages) { show[1] }
186
168
 
187
- it('error messages array is populated') do
188
- expect(error_messages.first.downcase).to eq('resource not found')
189
- end
190
- end
191
- end
192
-
193
- describe '#update' do
194
- context 'when missing public_id' do
195
- it do
196
- expect { subject.update(nil, {}) }.to raise_error(
197
- FinAppsCore::MissingArgumentsError,
198
- missing_public_id
199
- )
200
- end
201
- end
169
+ it { expect { show }.not_to raise_error }
170
+ it('results is a Hash') { expect(results).to be_a(Hash) }
202
171
 
203
- context 'when updating user details' do
204
- context 'for valid public_id' do
205
- let(:update) { subject.update(:valid_public_id, postal_code: '33021') }
206
- let(:results) { update[0] }
207
- let(:error_messages) { update[1] }
172
+ it('performs a get and returns the response') do
173
+ expect(results).to have_key(:public_id)
174
+ end
208
175
 
209
- it { expect { update }.not_to raise_error }
210
- it('results is nil') { expect(results).to be_nil }
211
176
  it('error_messages array is empty') { expect(error_messages).to eq([]) }
212
177
  end
213
178
 
214
- context 'for invalid public_id' do
215
- let(:update) do
216
- subject.update(:invalid_public_id, postal_code: '33021')
217
- end
218
- let(:results) { update[0] }
219
- let(:error_messages) { update[1] }
179
+ context 'with invalid token' do
180
+ let(:show) { users.show(:invalid_public_id) }
181
+ let(:results) { show[0] }
182
+ let(:error_messages) { show[1] }
220
183
 
221
- it { expect { update }.not_to raise_error }
184
+ it { expect { show }.not_to raise_error }
222
185
  it('results is nil') { expect(results).to be_nil }
223
186
 
224
187
  it('error messages array is populated') do
225
- expect(error_messages.first.downcase).to eq(
226
- 'invalid user id specified.'
227
- )
188
+ expect(error_messages.first.downcase).to eq('resource not found')
228
189
  end
229
190
  end
230
191
  end
231
192
 
232
- context 'when updating password' do
233
- context 'for valid public_id' do
234
- let(:update) do
235
- subject.update(
236
- :valid_public_id,
237
- password: 'Aa123456!', password_confirm: 'Aa123456!'
193
+ describe '#update' do
194
+ context 'when missing public_id' do
195
+ it do
196
+ expect { users.update(nil, {}) }.to raise_error(
197
+ FinAppsCore::MissingArgumentsError,
198
+ missing_public_id
238
199
  )
239
200
  end
240
- let(:results) { update[0] }
241
- let(:error_messages) { update[1] }
201
+ end
242
202
 
243
- it { expect { update }.not_to raise_error }
244
- it('results is a Hash') { expect(results).to be_a(Hash) }
203
+ context 'when updating user details' do
204
+ context 'with valid public_id' do
205
+ let(:update) { users.update(:valid_public_id, postal_code: '33021') }
206
+ let(:results) { update[0] }
207
+ let(:error_messages) { update[1] }
245
208
 
246
- it('the public_id is on the results') do
247
- expect(results).to have_key(:public_id)
209
+ it { expect { update }.not_to raise_error }
210
+ it('results is nil') { expect(results).to be_nil }
211
+ it('error_messages array is empty') { expect(error_messages).to eq([]) }
248
212
  end
249
213
 
250
- it('the new token is on the results') do
251
- expect(results).to have_key(:token)
214
+ context 'with invalid public_id' do
215
+ let(:update) do
216
+ subject.update(:invalid_public_id, postal_code: '33021')
217
+ end
218
+ let(:results) { update[0] }
219
+ let(:error_messages) { update[1] }
220
+
221
+ it { expect { update }.not_to raise_error }
222
+ it('results is nil') { expect(results).to be_nil }
223
+
224
+ it('error messages array is populated') do
225
+ expect(error_messages.first.downcase).to eq(
226
+ 'invalid user id specified.'
227
+ )
228
+ end
252
229
  end
253
-
254
- it('error_messages array is empty') { expect(error_messages).to eq([]) }
255
230
  end
256
231
 
257
- context 'for invalid public_id' do
258
- let(:update) do
259
- subject.update(
260
- :invalid_public_id,
261
- password: 'Aa123456!', password_confirm: 'Aa123456!'
262
- )
232
+ context 'when updating password' do
233
+ context 'with valid public_id' do
234
+ let(:update) do
235
+ subject.update(
236
+ :valid_public_id,
237
+ password: 'Aa123456!', password_confirm: 'Aa123456!'
238
+ )
239
+ end
240
+ let(:results) { update[0] }
241
+ let(:error_messages) { update[1] }
242
+
243
+ it { expect { update }.not_to raise_error }
244
+ it('results is a Hash') { expect(results).to be_a(Hash) }
245
+
246
+ it('the public_id is on the results') do
247
+ expect(results).to have_key(:public_id)
248
+ end
249
+
250
+ it('the new token is on the results') do
251
+ expect(results).to have_key(:token)
252
+ end
253
+
254
+ it('error_messages array is empty') { expect(error_messages).to eq([]) }
263
255
  end
264
- let(:results) { update[0] }
265
- let(:error_messages) { update[1] }
266
-
267
- it { expect { update }.not_to raise_error }
268
- it('results is nil') { expect(results).to be_nil }
269
256
 
270
- it('error messages array is populated') do
271
- expect(error_messages.first.downcase).to eq('resource not found')
257
+ context 'with invalid public_id' do
258
+ let(:update) do
259
+ subject.update(
260
+ :invalid_public_id,
261
+ password: 'Aa123456!', password_confirm: 'Aa123456!'
262
+ )
263
+ end
264
+ let(:results) { update[0] }
265
+ let(:error_messages) { update[1] }
266
+
267
+ it { expect { update }.not_to raise_error }
268
+ it('results is nil') { expect(results).to be_nil }
269
+
270
+ it('error messages array is populated') do
271
+ expect(error_messages.first.downcase).to eq('resource not found')
272
+ end
272
273
  end
273
274
  end
274
- end
275
275
 
276
- describe '#destroy' do
277
- context 'when missing public_id' do
278
- it do
279
- expect { subject.destroy(nil) }.to raise_error(
280
- FinAppsCore::MissingArgumentsError,
281
- missing_public_id
282
- )
276
+ describe '#destroy' do
277
+ context 'when missing public_id' do
278
+ it do
279
+ expect { users.destroy(nil) }.to raise_error(
280
+ FinAppsCore::MissingArgumentsError,
281
+ missing_public_id
282
+ )
283
+ end
283
284
  end
284
- end
285
285
 
286
- context 'for valid public_id' do
287
- let(:destroy) { subject.destroy(:valid_public_id) }
288
- let(:results) { destroy[0] }
289
- let(:error_messages) { destroy[1] }
286
+ context 'with valid public_id' do
287
+ let(:destroy) { users.destroy(:valid_public_id) }
288
+ let(:results) { destroy[0] }
289
+ let(:error_messages) { destroy[1] }
290
290
 
291
- it { expect { destroy }.not_to raise_error }
292
- it('results is nil') { expect(results).to be_nil }
293
- it('error_messages array is empty') { expect(error_messages).to eq([]) }
294
- end
291
+ it { expect { destroy }.not_to raise_error }
292
+ it('results is nil') { expect(results).to be_nil }
293
+ it('error_messages array is empty') { expect(error_messages).to eq([]) }
294
+ end
295
295
 
296
- context 'for invalid token' do
297
- let(:destroy) { subject.destroy(:invalid_public_id) }
298
- let(:results) { destroy[0] }
299
- let(:error_messages) { destroy[1] }
296
+ context 'with invalid token' do
297
+ let(:destroy) { subject.destroy(:invalid_public_id) }
298
+ let(:results) { destroy[0] }
299
+ let(:error_messages) { destroy[1] }
300
300
 
301
- it { expect { destroy }.not_to raise_error }
302
- it('results is nil') { expect(results).to be_nil }
301
+ it { expect { destroy }.not_to raise_error }
302
+ it('results is nil') { expect(results).to be_nil }
303
303
 
304
- it('error messages array is populated') do
305
- expect(error_messages.first.downcase).to eq('resource not found')
304
+ it('error messages array is populated') do
305
+ expect(error_messages.first.downcase).to eq('resource not found')
306
+ end
306
307
  end
307
308
  end
308
309
  end