finapps 2.3.3 → 2.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b3837e4ad6513b4ede27e48ff7b674fe7cbce17
4
- data.tar.gz: b8f1e7f1cf52de4cf611507c330ae6365f474309
3
+ metadata.gz: 466bc237a6a77b4f9021545c74a398c3665a18b3
4
+ data.tar.gz: 42e49b85f895de09e7892a59e0aad5320ffcd63c
5
5
  SHA512:
6
- metadata.gz: c1cece3db388c511a7ade9210a19a003263b810db2bdcf5699752d41c74e55a3cd25317efddc272f0a29a90b9b72833a422e34d1c9bbd4aeccf3876c735d36f3
7
- data.tar.gz: bf7d8267bf6622511325fa9c39ccd8cd02018480357362abd2a8d79f05c399d3247efedf8b684e4ba122dc1a6fb1eea88fd5592334b0bc40983ebc83ed1f5e31
6
+ metadata.gz: 9cd1afd63950ac89df8c4110494809b1816812c8a4191d410efc93fb9e0c8f0a562ca89b184118d00c8ecf0afe61a3ee41e5cc23861ae6295aa8467c5728640d
7
+ data.tar.gz: f37cadd33797e2c95e76ccfc628891e4560232ea304712b0ef26c393b410caab57b563dd6b81b8413d617c17c89c301ba735014c8881d004cab434f41b8e8adb
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  Rails:
2
- Enabled: true
2
+ Enabled: false
3
3
 
4
4
  AllCops:
5
5
  DisplayCopNames: true
@@ -51,6 +51,21 @@ module FinApps
51
51
  def validates(params)
52
52
  params.key?(:password) && params[:password] && params.key?(:password_confirm) && params[:password_confirm]
53
53
  end
54
+
55
+ def build_filter(params)
56
+ filter = {}
57
+ filter.merge!(search_query(params[:searchTerm])) if params[:searchTerm]
58
+ filter.merge!(role_query(params[:role])) if params[:role]
59
+ filter
60
+ end
61
+
62
+ def search_query(term)
63
+ {"last_name": {"$regex": term, "$options": 'i'}}
64
+ end
65
+
66
+ def role_query(role)
67
+ role.is_a?(Array) ? {"role": {"$in": role.map(&:to_i)}} : {"role": role.to_i}
68
+ end
54
69
  end
55
70
  end
56
71
  end
@@ -48,6 +48,50 @@ module FinApps
48
48
  path = "#{end_point}/#{ERB::Util.url_encode(id)}/cancel"
49
49
  update nil, nil, path
50
50
  end
51
+
52
+ private
53
+
54
+ def build_filter(params)
55
+ filter = {}
56
+ filter.merge!(search_query(params[:searchTerm])) if params[:searchTerm]
57
+ filter.merge!(status_query(params[:status])) if params[:status]
58
+ filter.merge!(assignment_query(params[:assignment])) if params.key?(:assignment) # assignment can be nil
59
+ filter
60
+ end
61
+
62
+ def search_query(term)
63
+ {
64
+ "$or": [{
65
+ "public_id": {
66
+ "$regex": "^#{term}",
67
+ "$options": 'i'
68
+ }
69
+ }, {
70
+ "applicant.last_name": {
71
+ "$regex": term,
72
+ "$options": 'i'
73
+ }
74
+ }, {
75
+ "assignment.last_name": {
76
+ "$regex": term,
77
+ "$options": 'i'
78
+ }
79
+ }, {
80
+ "requestor.reference_no": {
81
+ "$regex": "^#{term}",
82
+ "$options": 'i'
83
+ }
84
+ }]
85
+ }
86
+ end
87
+
88
+ def status_query(status)
89
+ status.is_a?(Array) ? {"status": {"$in": status.map(&:to_i)}} : {"status": status.to_i}
90
+ end
91
+
92
+ def assignment_query(assignment)
93
+ {"assignment.operator_id": assignment}
94
+ end
51
95
  end
52
96
  end
53
97
  end
@@ -4,11 +4,19 @@ module FinApps
4
4
  module Utils
5
5
  module QueryBuilder
6
6
  def build_query_path(root_url, params)
7
- page = params[:page] ? "page=#{params[:page]}" : ''
8
- requested = params[:requested] ? "&requested=#{params[:requested]}" : ''
9
- sort = params[:sort] ? "&sort=#{ERB::Util.url_encode(params[:sort])}" : ''
10
- filter = params[:filter] ? "&filter=#{ERB::Util.url_encode(params[:filter])}" : ''
11
- "#{root_url}?#{page}#{requested}#{sort}#{filter}"
7
+ filter_obj = build_filter(params)
8
+ page = "page=#{params[:page]}" if params[:page]
9
+ requested = "requested=#{params[:requested]}" if params[:requested]
10
+ sort = "sort=#{ERB::Util.url_encode(params[:sort])}" if params[:sort]
11
+ filter = "filter=#{ERB::Util.url_encode(filter_obj.to_json)}" if filter_obj && !filter_obj.empty?
12
+ query_join(root_url, [page, requested, sort, filter])
13
+ end
14
+
15
+ private
16
+
17
+ def query_join(root_url, params_array)
18
+ query_string = params_array.compact.join('&')
19
+ !query_string.empty? ? [root_url, query_string].join('?') : nil
12
20
  end
13
21
  end
14
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FinApps
4
- VERSION = '2.3.3'
4
+ VERSION = '2.3.5'
5
5
  end
@@ -7,16 +7,37 @@ RSpec.describe FinApps::REST::Operators, 'initialized with valid FinApps::Client
7
7
  subject(:operators) { FinApps::REST::Operators.new(client) }
8
8
 
9
9
  describe '#list' do
10
+ let(:list) { subject.list(params) }
11
+ let(:results) { list[0] }
12
+ let(:error_messages) { list[1] }
13
+
10
14
  context 'when missing params' do
11
- # use defaults
12
- let(:list) { subject.list }
13
- let(:results) { list[0] }
14
- let(:error_messages) { list[1] }
15
+ let(:params) { nil }
16
+ it { expect { list }.not_to raise_error }
17
+ it('performs a get and returns the response') { expect(results).to respond_to(:records) }
18
+ it('returns an array of records') { expect(results.records).to be_a(Array) }
19
+ it('returns no error messages') { expect(error_messages).to be_empty }
20
+ end
21
+
22
+ context 'when invalid params are provided' do
23
+ let(:params) { ['invalid array'] }
24
+
25
+ it { expect { list }.to raise_error(FinAppsCore::InvalidArgumentsError) }
26
+ end
27
+
28
+ context 'when including valid params' do
29
+ let(:params) { {page: 2, sort: 'date_created', requested: 25, searchTerm: 'term', role: 2} }
15
30
 
16
31
  it { expect { list }.not_to raise_error }
17
32
  it('performs a get and returns the response') { expect(results).to respond_to(:records) }
18
33
  it('returns an array of records') { expect(results.records).to be_a(Array) }
19
34
  it('returns no error messages') { expect(error_messages).to be_empty }
35
+ it 'builds query and sends proper request' do
36
+ list
37
+ url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v2/operators?filter=%7B%22last_name%22:%7B%22$regex" \
38
+ '%22:%22term%22,%22$options%22:%22i%22%7D,%22role%22:2%7D&page=2&requested=25&sort=date_created'
39
+ expect(WebMock).to have_requested(:get, url)
40
+ end
20
41
  end
21
42
  end
22
43
 
@@ -76,16 +76,24 @@ RSpec.describe FinApps::REST::Orders do
76
76
 
77
77
  context 'when including valid params' do
78
78
  subject { FinApps::REST::Orders.new(client).list(params) }
79
- let(:params) { {page: 2, sort: 'status'} }
79
+ let(:params) do
80
+ {page: 2, sort: 'status', requested: 25, searchTerm: 'term', status: %w(1 7),
81
+ assignment: 'valid_operator'}
82
+ end
80
83
 
81
84
  it { expect { subject }.not_to raise_error }
82
85
  it('returns an array') { expect(subject).to be_a(Array) }
83
86
  it('performs a get and returns the response') { expect(subject[RESULTS]).to respond_to(:orders) }
84
87
  it('each order contains a consumer_id') { expect(subject[RESULTS].orders).to all(have_key('consumer_id')) }
85
88
  it('returns no error messages') { expect(subject[ERROR_MESSAGES]).to be_empty }
86
- it 'sends proper request' do
89
+ it 'builds query and sends proper request' do
87
90
  subject
88
- url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v2/orders?page=2&sort=status"
91
+ url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v2/orders?filter=%7B%22$or%22:%5B%7B%22public_id%22:" \
92
+ '%7B%22$regex%22:%22%5Eterm%22,%22$options%22:%22i%22%7D%7D,%7B%22applicant.last_name%22:%7B%22$regex' \
93
+ '%22:%22term%22,%22$options%22:%22i%22%7D%7D,%7B%22assignment.last_name%22:%7B%22$regex%22:%22term%22,' \
94
+ '%22$options%22:%22i%22%7D%7D,%7B%22requestor.reference_no%22:%7B%22$regex%22:%22%5Eterm%22,%22$options' \
95
+ '%22:%22i%22%7D%7D%5D,%22status%22:%7B%22$in%22:%5B1,7%5D%7D,%22assignment.operator_id%22:%22' \
96
+ 'valid_operator%22%7D&page=2&requested=25&sort=status'
89
97
  expect(WebMock).to have_requested(:get, url)
90
98
  end
91
99
  end
@@ -2,25 +2,32 @@
2
2
 
3
3
  class FakeClass
4
4
  include FinApps::Utils::QueryBuilder
5
+
6
+ def build_filter(p); end
5
7
  end
6
8
 
7
9
  RSpec.describe FinApps::Utils::QueryBuilder do
10
+ subject { FakeClass.new }
11
+
8
12
  describe '#build_query_path' do
9
- subject { FakeClass.new }
10
13
  let(:end_point) { 'orders' }
11
14
 
12
15
  context 'with full params' do
13
- let(:params) { {page: '1', requested: '20', sort: '-date', filter: '{"role": "1"}'} }
14
- it 'returns correct string' do
15
- correct_string = 'orders?page=1&requested=20&sort=-date&filter=%7B%22role%22%3A%20%221%22%7D'
16
+ let(:params) { {page: '1', requested: '20', sort: '-date', random: 'random'} }
17
+ it 'calls #build_filter and returns correct string' do
18
+ allow(subject).to receive(:build_filter) { {role: 2} }
19
+ expect(subject).to receive(:build_filter).with(params)
20
+ correct_string = 'orders?page=1&requested=20&sort=-date&filter=%7B%22role%22%3A2%7D'
16
21
  expect(subject.build_query_path(end_point, params)).to eq(correct_string)
17
22
  end
18
23
  end
19
24
 
20
- context 'with partial params' do
21
- let(:params) { {page: '1', filter: '{"role": "1"}'} }
22
- it 'returns correct string' do
23
- expect(subject.build_query_path(end_point, params)).to eq('orders?page=1&filter=%7B%22role%22%3A%20%221%22%7D')
25
+ context 'with no params' do
26
+ let(:params) { {} }
27
+ it 'returns returns' do
28
+ allow(subject).to receive(:build_filter) { {} }
29
+ expect(subject).to receive(:build_filter).with(params)
30
+ expect(subject.build_query_path(end_point, params)).to be_nil
24
31
  end
25
32
  end
26
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finapps
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.3
4
+ version: 2.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Quintero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2018-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: finapps_core
@@ -315,34 +315,34 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
315
  version: '0'
316
316
  requirements: []
317
317
  rubyforge_project:
318
- rubygems_version: 2.6.13
318
+ rubygems_version: 2.6.14
319
319
  signing_key:
320
320
  specification_version: 4
321
321
  summary: FinApps REST API ruby client.
322
322
  test_files:
323
- - spec/rest/operators_password_resets_spec.rb
324
- - spec/rest/products_spec.rb
325
- - spec/rest/statements_spec.rb
326
- - spec/rest/version_spec.rb
327
- - spec/rest/user_institutions_forms_spec.rb
328
- - spec/rest/consumers_spec.rb
329
- - spec/rest/orders_spec.rb
330
- - spec/rest/order_tokens_spec.rb
331
- - spec/rest/institutions_forms_spec.rb
332
- - spec/rest/operators_spec.rb
333
- - spec/rest/user_institutions_statuses_spec.rb
323
+ - spec/spec_helper.rb
324
+ - spec/spec_helpers/client.rb
325
+ - spec/utils/query_builder_spec.rb
326
+ - spec/support/fake_api.rb
327
+ - spec/rest/order_reports_spec.rb
334
328
  - spec/rest/client_spec.rb
335
329
  - spec/rest/user_institutions_spec.rb
336
- - spec/rest/consumer_institution_refreshes_spec.rb
337
- - spec/rest/password_resets_spec.rb
338
- - spec/rest/order_reports_spec.rb
339
- - spec/rest/institutions_spec.rb
330
+ - spec/rest/consumers_spec.rb
340
331
  - spec/rest/order_statuses_spec.rb
341
- - spec/rest/order_refreshes_spec.rb
342
332
  - spec/rest/order_notifications_spec.rb
333
+ - spec/rest/operators_password_resets_spec.rb
334
+ - spec/rest/institutions_forms_spec.rb
335
+ - spec/rest/operators_spec.rb
336
+ - spec/rest/version_spec.rb
337
+ - spec/rest/statements_spec.rb
343
338
  - spec/rest/order_assignments_spec.rb
339
+ - spec/rest/order_refreshes_spec.rb
340
+ - spec/rest/user_institutions_statuses_spec.rb
341
+ - spec/rest/order_tokens_spec.rb
342
+ - spec/rest/products_spec.rb
344
343
  - spec/rest/sessions_spec.rb
345
- - spec/support/fake_api.rb
346
- - spec/utils/query_builder_spec.rb
347
- - spec/spec_helpers/client.rb
348
- - spec/spec_helper.rb
344
+ - spec/rest/password_resets_spec.rb
345
+ - spec/rest/consumer_institution_refreshes_spec.rb
346
+ - spec/rest/user_institutions_forms_spec.rb
347
+ - spec/rest/institutions_spec.rb
348
+ - spec/rest/orders_spec.rb