finapps 5.0.24 → 5.0.25

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f21200338d07c1ab7882266ee53bb695bcd2214fd54c3dd8bd1e4f54f07003fd
4
- data.tar.gz: 95168dfe1ade82536cd5ccb0a967a451cfabc6c3323796955e97f821c81c03ac
3
+ metadata.gz: 4ce0fc688800cfa247a62642d55c679edbe52a0a10556e359bf290b8f202351a
4
+ data.tar.gz: 0b5a307b87e1b704c8fa684a98f6fcb804538d3ac6326a08ac8285f462f23556
5
5
  SHA512:
6
- metadata.gz: bd3183fe7bad50f52717109c80b14766a642d895d8d3fc30bce7171428324cb372258b31d5d70f14fe0f492875109b6b415dbf2008d6fe3c05e59e93e98ee2b3
7
- data.tar.gz: c3a257358611b37562c7d34559bd69b574fdd590a7576c82cb8fa569b298bc2b907bee86a447c052f15c59480c74df81663e033c9833601be018f196fac387c2
6
+ metadata.gz: 3bbddba45806a7df005d72934aff45b43a3f574bf054e63622e2e7acc39ec06bd210742cd5dc8b9684cb9d179e8b4e882cb04fa9d1d278bea81dd002f4dd89f9
7
+ data.tar.gz: 2d8ac6a59586af1c7eaa3d7e3b8bcf78b7fcaca9ea7d440e07c639d7e8cc728439579eb45ff0cc78a399349b00cf6f8f4655cdc7d1834c82b95886881ab515d3
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../utils/query_builder'
4
+
3
5
  module FinApps
4
6
  module REST
5
7
  class Consumers < FinAppsCore::REST::Resources # :nodoc:
8
+ include FinApps::Utils::QueryBuilder
6
9
  # @param [String] public_id
7
10
  # @return [FinApps::REST::User, Array<String>]
8
11
  def create(params)
@@ -10,6 +13,13 @@ module FinApps
10
13
  super params
11
14
  end
12
15
 
16
+ def list(params = nil)
17
+ return super if params.nil?
18
+ raise FinAppsCore::InvalidArgumentsError, 'Invalid argument: params' unless params.is_a? Hash
19
+
20
+ super build_query_path(end_point, params)
21
+ end
22
+
13
23
  def show(public_id)
14
24
  not_blank(public_id, :public_id)
15
25
  super public_id
@@ -36,6 +46,20 @@ module FinApps
36
46
  def password_update?(params)
37
47
  params.key?(:password) && params.key?(:password_confirm)
38
48
  end
49
+
50
+ def build_filter(params)
51
+ search_query(params[:searchTerm]) if params[:searchTerm]
52
+ end
53
+
54
+ def search_query(term)
55
+ {
56
+ "$or": [
57
+ { "email": term },
58
+ { "first_name": term },
59
+ { "last_name": term }
60
+ ]
61
+ }
62
+ end
39
63
  end
40
64
  end
41
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FinApps
4
- VERSION = '5.0.24'
4
+ VERSION = '5.0.25'
5
5
  end
@@ -41,6 +41,55 @@ RSpec.describe FinApps::REST::Consumers,
41
41
  end
42
42
  end
43
43
 
44
+ describe '#list' do
45
+ let(:list) { subject.list(params) }
46
+ let(:results) { list[0] }
47
+ let(:error_messages) { list[1] }
48
+
49
+ context 'when missing params' do
50
+ let(:params) { nil }
51
+ it { expect { list }.to_not raise_error }
52
+ it('performs a get and returns the response') do
53
+ expect(results).to have_key(:records)
54
+ end
55
+ it('returns an array of records') { expect(results[:records]).to be_a(Array) }
56
+ it('returns no error messages') { expect(error_messages).to be_empty }
57
+ end
58
+
59
+ context 'when invalid params are provided' do
60
+ let(:params) { ['invalid array'] }
61
+
62
+ it { expect { list }.to raise_error(FinAppsCore::InvalidArgumentsError) }
63
+ end
64
+
65
+ context 'when including valid params' do
66
+ let(:params) do
67
+ {
68
+ page: 2,
69
+ sort: 'date_created',
70
+ requested: 25,
71
+ searchTerm: 'term'
72
+ }
73
+ end
74
+
75
+ it { expect { list }.to_not raise_error }
76
+ it('returns an array') { expect(list).to be_a(Array) }
77
+ it('performs a get and returns the response') do
78
+ expect(results).to have_key(:records)
79
+ end
80
+ it('returns no error messages') do
81
+ expect(error_messages).to be_empty
82
+ end
83
+ it 'builds query and sends proper request' do
84
+ list
85
+ url = "#{versioned_api_path}/consumers?filter=%7B%22$or%22:%5B%7B%22email%22:%22term%22%7D," \
86
+ '%7B%22first_name%22:%22term%22%7D,%7B%22last_name%22:%22term%22%7D%5D%7D&page=2&requested=25' \
87
+ '&sort=date_created'
88
+ expect(WebMock).to have_requested(:get, url)
89
+ end
90
+ end
91
+ end
92
+
44
93
  describe '#show' do
45
94
  context 'when missing public_id' do
46
95
  it do
@@ -190,6 +190,9 @@ class FakeApi < Sinatra::Base
190
190
  end
191
191
 
192
192
  # consumers
193
+ get("/#{version}/consumers") do
194
+ json_response 200, 'users.json'
195
+ end
193
196
  get("/#{version}/consumers/valid_public_id") do
194
197
  json_response 200, 'user.json'
195
198
  end
@@ -0,0 +1,18 @@
1
+ {
2
+ "total_records": 1,
3
+ "page": 1,
4
+ "total_pages": 1,
5
+ "records": [
6
+ {
7
+ "public_id": "b090a422-b62f-4210-7526-f9513df0c3a5",
8
+ "email": "test.1578406657576@postman.com",
9
+ "first_name": "API",
10
+ "last_name": "Test",
11
+ "memo": "memo goes here",
12
+ "tenant_id": "988a0c8f-8a17-4bfd-6ac5-9df8ba91c095",
13
+ "date_modified": "2020-01-07T14:17:37.643Z",
14
+ "date_created": "2020-01-07T14:17:37.643Z",
15
+ "postal_code": "33136"
16
+ }
17
+ ]
18
+ }
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: 5.0.24
4
+ version: 5.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Quintero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-30 00:00:00.000000000 Z
11
+ date: 2020-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: finapps_core
@@ -418,6 +418,7 @@ files:
418
418
  - spec/support/fixtures/tenant_settings.json
419
419
  - spec/support/fixtures/unauthorized.json
420
420
  - spec/support/fixtures/user.json
421
+ - spec/support/fixtures/users.json
421
422
  - spec/support/fixtures/verix/metadata.json
422
423
  - spec/support/fixtures/verix/record/create.json
423
424
  - spec/support/fixtures/verix/record/list.json