bigid_bgcheck 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +21 -20
  5. data/Rakefile +1 -1
  6. data/lib/bigid/bgcheck/request.rb +8 -4
  7. data/lib/bigid/bgcheck/result.rb +14 -8
  8. data/lib/bigid/bgcheck/version.rb +1 -1
  9. data/lib/bigid_bgcheck.rb +20 -41
  10. data/lib/locales/en.yml +17 -0
  11. data/lib/locales/pt-BR.yml +17 -0
  12. data/spec/bigid/bgcheck/bad_request_error_spec.rb +7 -0
  13. data/spec/bigid/bgcheck/base_error_spec.rb +7 -0
  14. data/spec/{lib → bigid}/bgcheck/doc_type_spec.rb +0 -1
  15. data/spec/bigid/bgcheck/document_not_supported_error_spec.rb +7 -0
  16. data/spec/bigid/bgcheck/internal_error_spec.rb +7 -0
  17. data/spec/bigid/bgcheck/invalid_credentials_error_spec.rb +7 -0
  18. data/spec/bigid/bgcheck/invalid_document_value_error_spec.rb +7 -0
  19. data/spec/bigid/bgcheck/no_info_error_spec.rb +7 -0
  20. data/spec/bigid/bgcheck/request_spec.rb +99 -0
  21. data/spec/{lib → bigid}/bgcheck/result_code_spec.rb +0 -1
  22. data/spec/bigid/bgcheck/server_error_spec.rb +7 -0
  23. data/spec/bigid_bgcheck_spec.rb +4 -23
  24. data/spec/factories/result.rb +45 -0
  25. data/spec/spec_helper.rb +29 -7
  26. data/spec/support/shared_examples/errors_shared_examples.rb +53 -0
  27. metadata +83 -45
  28. data/lib/bigid/bgcheck/auth/authenticated_connection.rb +0 -45
  29. data/lib/bigid/bgcheck/auth/authenticated_resource.rb +0 -13
  30. data/lib/bigid/bgcheck/auth/authentication.rb +0 -38
  31. data/lib/bigid/bgcheck/auth/connection.rb +0 -20
  32. data/lib/bigid/bgcheck/integration/connection.rb +0 -120
  33. data/lib/bigid/bgcheck/integration/multipart_flat.rb +0 -28
  34. data/lib/bigid/bgcheck/integration/request.rb +0 -20
  35. data/lib/bigid/bgcheck/integration/response.rb +0 -27
  36. data/lib/bigid/bgcheck/not_permission_error.rb +0 -8
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "spec_helper"
4
- require "bigid/bgcheck/result_code"
5
4
 
6
5
  RSpec.describe Bigid::Bgcheck::ResultCode do
7
6
  describe ".valid?(code)" do
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Bigid::Bgcheck::ServerError do
6
+ include_examples "error"
7
+ end
@@ -1,44 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "spec_helper"
4
- require "bigid_bgcheck"
5
4
 
6
5
  RSpec.describe Bigid::Bgcheck do
7
- describe "BASE_URL" do
8
- subject { defined? Bigid::Bgcheck::BASE_URL }
9
-
10
- it { expect(subject).to be_truthy }
11
- end
12
-
13
- describe "AUTH_ENDPOINT" do
14
- subject { defined? Bigid::Bgcheck::AUTH_ENDPOINT }
15
-
16
- it { expect(subject).to be_truthy }
17
- end
18
-
19
6
  describe "SRV_ENDPOINT" do
20
7
  subject { defined? Bigid::Bgcheck::SRV_ENDPOINT }
21
8
 
22
9
  it { expect(subject).to be_truthy }
23
10
  end
24
11
 
25
- describe "TOKEN_EXPIRATION" do
26
- subject { defined? Bigid::Bgcheck::TOKEN_EXPIRATION }
27
-
28
- it { expect(subject).to be_truthy }
29
- end
30
-
31
12
  describe ".configure" do
32
13
  before do
33
- described_class.configuration = nil
14
+ Bigid.configuration = nil
34
15
  ENV.clear
35
16
  end
36
17
 
37
- subject { described_class.configuration }
18
+ subject { Bigid.configuration }
38
19
 
39
20
  context "when configuration is defined" do
40
21
  before do
41
- described_class.configure do |config|
22
+ Bigid.configure do |config|
42
23
  config.username = "username_value"
43
24
  config.password = "password_value"
44
25
  end
@@ -77,7 +58,7 @@ RSpec.describe Bigid::Bgcheck do
77
58
  ENV["BIGID_USERNAME"] = "username_value"
78
59
  ENV["BIGID_PASSWORD"] = "password_value"
79
60
 
80
- described_class.configure do |config|
61
+ Bigid.configure do |config|
81
62
  config.username = "username_value2"
82
63
  config.password = "password_value2"
83
64
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :result, class: "Bigid::Bgcheck::Result" do
5
+ trait :approved do
6
+ approved { true }
7
+ code { Bigid::Bgcheck::ResultCode::APPROVED }
8
+ score_details { {} }
9
+ limit_score { 10.0 }
10
+ message { "Approved" }
11
+ score { 10.0 }
12
+ ticket_id { SecureRandom.hex(8) }
13
+ raw_data { "{}" }
14
+ raw_response { "{\"ScoreDetails\":#{score_details},\"LimitScore\":#{limit_score},\"ResultCode\":#{code},\"ResultMessage\":\"#{message}\",\"Score\":#{score},\"TicketId\":\"#{ticket_id}\"}" }
15
+ related_score_details { "{}" }
16
+ end
17
+
18
+ trait :unapproved do
19
+ approved { false }
20
+ code { Bigid::Bgcheck::ResultCode::NOT_APPROVED }
21
+ score_details { }
22
+ limit_score { 10.0 }
23
+ message { "Not Approved" }
24
+ raw_response { "{\"ScoreDetails\":null,\"LimitScore\":10.0,\"ResultCode\":90,\"ResultMessage\":\"Approved\",\"Score\":10.0,\"TicketId\":\"d735711aeb909de9\"}" }
25
+ score { 1.0 }
26
+ ticket_id { SecureRandom.hex(8) }
27
+ end
28
+
29
+ initialize_with do
30
+ new(
31
+ approved: approved,
32
+ code: code,
33
+ score_details: score_details,
34
+ limit_score: limit_score,
35
+ message: message,
36
+ raw_data: raw_data,
37
+ raw_response: raw_response,
38
+ related_score_details: related_score_details,
39
+ score: score,
40
+ score_details: score_details,
41
+ ticket_id: ticket_id
42
+ )
43
+ end
44
+ end
45
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "simplecov"
4
+
5
+ SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter]
6
+ SimpleCov.minimum_coverage 70.0
7
+
8
+ SimpleCov.start do
9
+ add_filter "/spec/"
10
+ minimum_coverage 70
11
+ minimum_coverage_by_file 50
12
+ end
13
+
14
+ require "bigid_auth"
15
+ require "bigid/bgcheck/base_error"
16
+
17
+ Dir["./spec/support/**/*.rb"].each { |f| require f }
18
+ Dir["./spec/initializers/**/*.rb"].each { |f| require f }
19
+ Dir["./lib/**/*.rb"].sort.each { |file| require file }
20
+
3
21
  require "rubygems"
4
22
  require "bundler"
23
+ require "bigid_bgcheck"
24
+ require "factory_bot"
25
+ require "pry"
5
26
 
6
27
  begin
7
28
  Bundler.setup(:default, :development, :test)
@@ -12,14 +33,15 @@ rescue Bundler::BundlerError => e
12
33
  exit e.status_code
13
34
  end
14
35
 
15
- require "simplecov"
36
+ RSpec.configure do |config|
37
+ config.include FactoryBot::Syntax::Methods
16
38
 
17
- SimpleCov.start do
18
- add_filter "spec"
19
- end
39
+ # Enable flags like --only-failures and --next-failure
40
+ config.example_status_persistence_file_path = ".rspec_status"
20
41
 
21
- RSpec.configure do |config|
22
- # some (optional) config here
42
+ config.expect_with :rspec do |c|
43
+ c.syntax = :expect
44
+ end
23
45
  end
24
46
 
25
- # minitest/mock # Uncomment me to use minitest mocks
47
+ FactoryBot.find_definitions
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.shared_examples "error" do
6
+ describe ".initialize" do
7
+ context "when message parameter is null" do
8
+ subject { described_class.new.message }
9
+
10
+ it { expect(subject).to eq(described_class.default_message) }
11
+ end
12
+
13
+ context "when message parameter is not null" do
14
+ subject { described_class.new(message).message }
15
+
16
+ let(:message) { "message" }
17
+
18
+ it { expect(subject).to eq(message) }
19
+ end
20
+ end
21
+
22
+ describe ".default_message" do
23
+ let(:expected_result) { I18n.t("errors.#{described_class.name.underscore.tr("/", ".")}") }
24
+
25
+ subject { described_class.default_message }
26
+
27
+ it "searches the default message in I18n using the class name" do
28
+ expect(subject).to eq(expected_result)
29
+ end
30
+ end
31
+ end
32
+
33
+ RSpec.shared_examples "http_error" do
34
+ include_examples "error"
35
+
36
+ describe "#http_status" do
37
+ subject { described_class.new.http_status }
38
+
39
+ it { expect(subject).to eq(described_class::HTTP_STATUS) }
40
+ end
41
+
42
+ describe "#status" do
43
+ subject { described_class.new.status }
44
+
45
+ it { expect(subject).to eq(described_class::STATUS) }
46
+ end
47
+
48
+ describe "#status_code" do
49
+ subject { described_class.new.status_code }
50
+
51
+ it { expect(subject).to eq(described_class::STATUS_CODE) }
52
+ end
53
+ end
metadata CHANGED
@@ -1,42 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigid_bgcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Carolino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-18 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: faraday
14
+ name: bigid_auth
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.0
19
+ version: '0.2'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '1.0'
22
+ version: '0.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: 1.4.0
29
+ version: '0.2'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '1.0'
32
+ version: '0.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: i18n
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 1.8.0
39
+ version: '1.8'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '1.0'
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 1.8.0
49
+ version: '1.8'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: '1.0'
@@ -56,7 +56,7 @@ dependencies:
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: 2.5.0
59
+ version: '2.5'
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '2.0'
@@ -66,66 +66,86 @@ dependencies:
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 2.5.0
69
+ version: '2.5'
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: '2.0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: cpf_cnpj
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.5'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0.5'
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.5'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0.5'
73
93
  - !ruby/object:Gem::Dependency
74
94
  name: bundler
75
95
  requirement: !ruby/object:Gem::Requirement
76
96
  requirements:
77
97
  - - ">="
78
98
  - !ruby/object:Gem::Version
79
- version: 1.2.0
99
+ version: '1.2'
80
100
  type: :development
81
101
  prerelease: false
82
102
  version_requirements: !ruby/object:Gem::Requirement
83
103
  requirements:
84
104
  - - ">="
85
105
  - !ruby/object:Gem::Version
86
- version: 1.2.0
106
+ version: '1.2'
87
107
  - !ruby/object:Gem::Dependency
88
108
  name: factory_bot
89
109
  requirement: !ruby/object:Gem::Requirement
90
110
  requirements:
91
111
  - - "~>"
92
112
  - !ruby/object:Gem::Version
93
- version: 6.1.0
113
+ version: '6.2'
94
114
  type: :development
95
115
  prerelease: false
96
116
  version_requirements: !ruby/object:Gem::Requirement
97
117
  requirements:
98
118
  - - "~>"
99
119
  - !ruby/object:Gem::Version
100
- version: 6.1.0
120
+ version: '6.2'
101
121
  - !ruby/object:Gem::Dependency
102
- name: gemsurance
122
+ name: fuubar
103
123
  requirement: !ruby/object:Gem::Requirement
104
124
  requirements:
105
125
  - - "~>"
106
126
  - !ruby/object:Gem::Version
107
- version: '0.10'
127
+ version: '2.5'
108
128
  type: :development
109
129
  prerelease: false
110
130
  version_requirements: !ruby/object:Gem::Requirement
111
131
  requirements:
112
132
  - - "~>"
113
133
  - !ruby/object:Gem::Version
114
- version: '0.10'
134
+ version: '2.5'
115
135
  - !ruby/object:Gem::Dependency
116
136
  name: pry
117
137
  requirement: !ruby/object:Gem::Requirement
118
138
  requirements:
119
139
  - - "~>"
120
140
  - !ruby/object:Gem::Version
121
- version: 0.14.0
141
+ version: '0.14'
122
142
  type: :development
123
143
  prerelease: false
124
144
  version_requirements: !ruby/object:Gem::Requirement
125
145
  requirements:
126
146
  - - "~>"
127
147
  - !ruby/object:Gem::Version
128
- version: 0.14.0
148
+ version: '0.14'
129
149
  - !ruby/object:Gem::Dependency
130
150
  name: rake
131
151
  requirement: !ruby/object:Gem::Requirement
@@ -152,70 +172,70 @@ dependencies:
152
172
  requirements:
153
173
  - - "~>"
154
174
  - !ruby/object:Gem::Version
155
- version: 3.10.0
175
+ version: '3.10'
156
176
  type: :development
157
177
  prerelease: false
158
178
  version_requirements: !ruby/object:Gem::Requirement
159
179
  requirements:
160
180
  - - "~>"
161
181
  - !ruby/object:Gem::Version
162
- version: 3.10.0
182
+ version: '3.10'
163
183
  - !ruby/object:Gem::Dependency
164
184
  name: rubocop
165
185
  requirement: !ruby/object:Gem::Requirement
166
186
  requirements:
167
187
  - - "~>"
168
188
  - !ruby/object:Gem::Version
169
- version: 1.12.0
189
+ version: '1.17'
170
190
  type: :development
171
191
  prerelease: false
172
192
  version_requirements: !ruby/object:Gem::Requirement
173
193
  requirements:
174
194
  - - "~>"
175
195
  - !ruby/object:Gem::Version
176
- version: 1.12.0
196
+ version: '1.17'
177
197
  - !ruby/object:Gem::Dependency
178
198
  name: rubocop-packaging
179
199
  requirement: !ruby/object:Gem::Requirement
180
200
  requirements:
181
201
  - - "~>"
182
202
  - !ruby/object:Gem::Version
183
- version: 0.5.0
203
+ version: '0.5'
184
204
  type: :development
185
205
  prerelease: false
186
206
  version_requirements: !ruby/object:Gem::Requirement
187
207
  requirements:
188
208
  - - "~>"
189
209
  - !ruby/object:Gem::Version
190
- version: 0.5.0
210
+ version: '0.5'
191
211
  - !ruby/object:Gem::Dependency
192
212
  name: rubocop-performance
193
213
  requirement: !ruby/object:Gem::Requirement
194
214
  requirements:
195
215
  - - "~>"
196
216
  - !ruby/object:Gem::Version
197
- version: 1.10.0
217
+ version: '1.11'
198
218
  type: :development
199
219
  prerelease: false
200
220
  version_requirements: !ruby/object:Gem::Requirement
201
221
  requirements:
202
222
  - - "~>"
203
223
  - !ruby/object:Gem::Version
204
- version: 1.10.0
224
+ version: '1.11'
205
225
  - !ruby/object:Gem::Dependency
206
226
  name: simplecov
207
227
  requirement: !ruby/object:Gem::Requirement
208
228
  requirements:
209
229
  - - "~>"
210
230
  - !ruby/object:Gem::Version
211
- version: 0.21.0
231
+ version: 0.21.2
212
232
  type: :development
213
233
  prerelease: false
214
234
  version_requirements: !ruby/object:Gem::Requirement
215
235
  requirements:
216
236
  - - "~>"
217
237
  - !ruby/object:Gem::Version
218
- version: 0.21.0
238
+ version: 0.21.2
219
239
  description: A library to use BigData Corps background check features
220
240
  email:
221
241
  - danilo.carolino@qflash.com.br
@@ -227,37 +247,44 @@ files:
227
247
  - LICENSE.txt
228
248
  - README.md
229
249
  - Rakefile
230
- - lib/bigid/bgcheck/auth/authenticated_connection.rb
231
- - lib/bigid/bgcheck/auth/authenticated_resource.rb
232
- - lib/bigid/bgcheck/auth/authentication.rb
233
- - lib/bigid/bgcheck/auth/connection.rb
234
250
  - lib/bigid/bgcheck/bad_request_error.rb
235
251
  - lib/bigid/bgcheck/base_error.rb
236
252
  - lib/bigid/bgcheck/doc_type.rb
237
253
  - lib/bigid/bgcheck/document_not_supported_error.rb
238
- - lib/bigid/bgcheck/integration/connection.rb
239
- - lib/bigid/bgcheck/integration/multipart_flat.rb
240
- - lib/bigid/bgcheck/integration/request.rb
241
- - lib/bigid/bgcheck/integration/response.rb
242
254
  - lib/bigid/bgcheck/internal_error.rb
243
255
  - lib/bigid/bgcheck/invalid_credentials_error.rb
244
256
  - lib/bigid/bgcheck/invalid_document_value_error.rb
245
257
  - lib/bigid/bgcheck/no_info_error.rb
246
- - lib/bigid/bgcheck/not_permission_error.rb
247
258
  - lib/bigid/bgcheck/request.rb
248
259
  - lib/bigid/bgcheck/result.rb
249
260
  - lib/bigid/bgcheck/result_code.rb
250
261
  - lib/bigid/bgcheck/server_error.rb
251
262
  - lib/bigid/bgcheck/version.rb
252
263
  - lib/bigid_bgcheck.rb
264
+ - lib/locales/en.yml
265
+ - lib/locales/pt-BR.yml
266
+ - spec/bigid/bgcheck/bad_request_error_spec.rb
267
+ - spec/bigid/bgcheck/base_error_spec.rb
268
+ - spec/bigid/bgcheck/doc_type_spec.rb
269
+ - spec/bigid/bgcheck/document_not_supported_error_spec.rb
270
+ - spec/bigid/bgcheck/internal_error_spec.rb
271
+ - spec/bigid/bgcheck/invalid_credentials_error_spec.rb
272
+ - spec/bigid/bgcheck/invalid_document_value_error_spec.rb
273
+ - spec/bigid/bgcheck/no_info_error_spec.rb
274
+ - spec/bigid/bgcheck/request_spec.rb
275
+ - spec/bigid/bgcheck/result_code_spec.rb
276
+ - spec/bigid/bgcheck/server_error_spec.rb
253
277
  - spec/bigid_bgcheck_spec.rb
254
- - spec/lib/bgcheck/doc_type_spec.rb
255
- - spec/lib/bgcheck/result_code_spec.rb
278
+ - spec/factories/result.rb
256
279
  - spec/spec_helper.rb
280
+ - spec/support/shared_examples/errors_shared_examples.rb
257
281
  homepage: https://github.com/Quasar-Flash/bigid-bgcheck-ruby
258
282
  licenses:
259
283
  - MIT
260
- metadata: {}
284
+ metadata:
285
+ changelog_uri: https://github.com/Quasar-Flash/bigid-bgcheck-ruby/blob/master/CHANGELOG.md
286
+ source_code_uri: https://github.com/Quasar-Flash/bigid-bgcheck-ruby
287
+ bug_tracker_uri: https://github.com/Quasar-Flash/bigid-bgcheck-ruby/issues
261
288
  post_install_message:
262
289
  rdoc_options: []
263
290
  require_paths:
@@ -266,7 +293,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
293
  requirements:
267
294
  - - ">="
268
295
  - !ruby/object:Gem::Version
269
- version: '0'
296
+ version: '2.5'
270
297
  required_rubygems_version: !ruby/object:Gem::Requirement
271
298
  requirements:
272
299
  - - ">="
@@ -279,6 +306,17 @@ specification_version: 4
279
306
  summary: Bigid Background Check Library
280
307
  test_files:
281
308
  - spec/bigid_bgcheck_spec.rb
282
- - spec/lib/bgcheck/result_code_spec.rb
283
- - spec/lib/bgcheck/doc_type_spec.rb
309
+ - spec/support/shared_examples/errors_shared_examples.rb
310
+ - spec/factories/result.rb
284
311
  - spec/spec_helper.rb
312
+ - spec/bigid/bgcheck/invalid_document_value_error_spec.rb
313
+ - spec/bigid/bgcheck/bad_request_error_spec.rb
314
+ - spec/bigid/bgcheck/no_info_error_spec.rb
315
+ - spec/bigid/bgcheck/internal_error_spec.rb
316
+ - spec/bigid/bgcheck/result_code_spec.rb
317
+ - spec/bigid/bgcheck/server_error_spec.rb
318
+ - spec/bigid/bgcheck/request_spec.rb
319
+ - spec/bigid/bgcheck/invalid_credentials_error_spec.rb
320
+ - spec/bigid/bgcheck/document_not_supported_error_spec.rb
321
+ - spec/bigid/bgcheck/doc_type_spec.rb
322
+ - spec/bigid/bgcheck/base_error_spec.rb