bigid_bgcheck 0.1.3 → 0.3.1

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
  SHA256:
3
- metadata.gz: fe1ebc273c327323e346cd5f95acdf0f416fe43b9df2b63af7a26f74125397ce
4
- data.tar.gz: 0a89cf40a825ad278c2ca22ca441e1cd7f2cb8e77c0884a17507cc207d3680dd
3
+ metadata.gz: be95a78ca1f565303461532c086f52e0fdc83dcfac235fed73c995f9f81493e1
4
+ data.tar.gz: 5fdeb2b9f0a5aeb97282cd55289030cd85584ab6da1879cc480c46590128e0a2
5
5
  SHA512:
6
- metadata.gz: 67a17203419ba2e66edbfdced0ddcb9d6affa3a12742bf55432ec0c30d60bd22abacda6b0ff656d755e340ab05a63bbd5f1b8984e0ef3c1ea1713b19d6305573
7
- data.tar.gz: 62b1d4edec6dde17d86342dcb06a4b01748b2bcb298a1776a81209bb2118ff8f514e859b9209703df49efff7519e94ea198d61ed7a1e3a21c5fda573259e2d73
6
+ metadata.gz: 9facd77ce7d71802b439c4e8cd074f8729f0d7de4492430f0de893e0712aecad2d7dcd2296845601477848670508b1423b90f077dceeb483993951207b47967b
7
+ data.tar.gz: c55c18f21e057426a1e634a731106a13a85028c2f2327d00b969b98917e047cfadd646eaa372ef97524aa34160acc4af2681d8cd25467ba24f2ce20c64647873
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # CHANGELOG for bigid_bgcheck
2
2
 
3
+ ## v0.3.1-20220202 - Danilo Carolino
4
+
5
+ * [QC-79](https://qflash.atlassian.net/jira/software/projects/QC/boards/31?selectedIssue=QC-79)
6
+ Reduzir uso de pipelines em projetos Ruby [Dependabot]
7
+ * Bump Ruby version to v3.1.0
8
+
9
+ ## v0.3.0
10
+
11
+ * Bump "bigid_auth" version from v0.1.0 to v0.2.0
12
+
13
+ ## v0.2.0
14
+
15
+ Features
16
+
17
+ * Add fields to service return: "raw_data", "score_details", "related_score_details" and "raw_response" (the complete json file)
18
+
3
19
  ## v0.1.3
4
20
 
5
21
  * Fix a problem with the locale initialization in Rails projects
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2021 Danilo Carolino
1
+ Copyright (c) 2021 Quasar Flash
2
2
 
3
3
  MIT LICENSE
4
4
 
data/README.md CHANGED
@@ -1,8 +1,26 @@
1
1
  BigId Background Check's Library for Ruby
2
2
  ==============
3
3
 
4
+ Build Status
5
+ -----------------
6
+
4
7
  [![Gem Version](https://badge.fury.io/rb/bigid_bgcheck.svg)](https://badge.fury.io/rb/bigid_bgcheck)
5
- [![Build Status](https://travis-ci.com/Quasar-Flash/bigid-bgcheck-ruby.svg?branch=master)](https://travis-ci.com/Quasar-Flash/bigid-bgcheck-ruby)
8
+ [![bigid_bgcheck](https://github.com/Quasar-Flash/bigid_bgcheck/actions/workflows/ruby.yml/badge.svg)](https://github.com/Quasar-Flash/bigid_bgcheck/actions/workflows/ruby.yml)
9
+ [![Quality Gate Status](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=alert_status&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
10
+ [![Coverage](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=coverage&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
11
+ [![Maintainability Rating](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=sqale_rating&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
12
+
13
+ Project Scores
14
+ -----------------
15
+
16
+ [![Bugs](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=bugs&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
17
+ [![Code Smells](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=code_smells&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
18
+ [![Duplicated Lines (%)](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=duplicated_lines_density&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
19
+ [![Lines of Code](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=ncloc&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
20
+ [![Reliability Rating](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=reliability_rating&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
21
+ [![Security Rating](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=security_rating&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
22
+ [![Technical Debt](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=sqale_index&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
23
+ [![Vulnerabilities](https://sonarqube.eks.qflash.com.br/api/project_badges/measure?project=Quasar-Flash_bigid_bgcheck&metric=vulnerabilities&token=23b79ee0eebe63611e370ffb911d9be245c99154)](https://sonarqube.eks.qflash.com.br/dashboard?id=Quasar-Flash_bigid_bgcheck)
6
24
 
7
25
  Requirements
8
26
  -----------------
@@ -18,66 +36,79 @@ Included Modules
18
36
  Global Installation
19
37
  -----------------
20
38
 
21
- gem install bigid_bgcheck
39
+ ```sh
40
+ gem install bigid_bgcheck
41
+ ```
22
42
 
23
43
  Installation for Rails
24
44
  -----------------
25
45
 
26
- # Add to the Gemfile
27
- gem 'bigid_bgcheck', '~> 0.1.0'
46
+ ```ruby
47
+ # Add to the Gemfile
48
+ gem "bigid_bgcheck", "~> 0.3"
49
+ gem "bigid_bgcheck", github: "Quasar-Flash/bigid_bgcheck"
50
+ ```
28
51
 
29
52
  Setting the BigID credentials
30
53
  -----------------
31
54
 
32
- # Set the env variables
33
- ENV['BIGID_USERNAME'] = 'your_username'
34
- ENV['BIGID_PASSWORD'] = 'your_password'
55
+ ```ruby
56
+ # Set the env variables
57
+ ENV["BIGID_USERNAME"] = "your_username"
58
+ ENV["BIGID_PASSWORD"] = "your_password"
59
+ ```
35
60
 
36
61
  Setting the BigID credentials - Rails Project
37
62
  -----------------
38
63
 
39
64
  Create the config/initializers/bigid.rb file and define:
40
65
 
41
- # Set the env variables
42
- Bigid.configure do |config|
43
- config.username = 'your_username'
44
- config.password = 'your_password'
45
- end
66
+ ```ruby
67
+ # Set the env variables
68
+ Bigid.configure do |config|
69
+ config.username = "your_username"
70
+ config.password = "your_password"
71
+ end
72
+ ```
46
73
 
47
74
  Applying a background check
48
75
  -----------------
49
76
 
50
- require 'bigid_bgcheck'
77
+ ```ruby
78
+ require "bigid_bgcheck"
51
79
 
52
- Bigid::Bgcheck::Request.new.call(
53
- document: '000.000.000-00',
54
- document_type: 'CPF',
55
- group: 'Default'
56
- )
80
+ Bigid::Bgcheck::Request.new.call(
81
+ document: "000.000.000-00",
82
+ document_type: "CPF",
83
+ group: "Default"
84
+ )
85
+ ```
57
86
 
58
87
  Result Example
59
88
  -----------------
60
89
 
61
- #<Bigid::Bgcheck::Result:0x0000560fef3c1068
62
- @approved=false,
63
- @ticket_id="00000000000000000",
64
- @code=-1100,
65
- @message="Not Approved",
66
- @score=0,
67
- @limit_score=0.0>
90
+ ```ruby
91
+ #<Bigid::Bgcheck::Result:0x0000560fef3c1068
92
+ @approved=false,
93
+ @ticket_id="00000000000000000",
94
+ @code=-1100,
95
+ @message="Not Approved",
96
+ @score=0,
97
+ @limit_score=0.0>
98
+ ```
68
99
 
69
100
  Problems?
70
101
  -----------------
71
102
 
72
103
  **Please do not directly email any committers with questions or problems.** A community is best served when discussions are held in public.
73
104
 
74
- Searching the [issues](https://github.com/Quasar-Flash/bigid-bgcheck-ruby/issues) for your problem is also a good idea.
105
+ Searching the [issues](https://github.com/Quasar-Flash/bigid_bgcheck/issues) for your problem is also a good idea.
75
106
 
76
107
  Contributing
77
108
  -----------------
78
109
 
79
- - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet;
80
- - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it;
110
+ - Check out the latest master to make sure the feature hasn"t been implemented or the bug hasn't been fixed yet;
111
+ - Check out the issue tracker to make sure someone already hasn"t requested it and/or contributed it;
81
112
  - Fork the project;
82
113
  - Start a feature/bugfix branch;
83
114
  - Commit and push until you are happy with your contribution;
@@ -87,7 +118,7 @@ Contributing
87
118
  License
88
119
  -----------------
89
120
 
90
- Please see [LICENSE](https://github.com/Quasar-Flash/bigid-bgcheck-ruby/blob/master/LICENSE.txt) for licensing details.
121
+ Please see [LICENSE](https://github.com/Quasar-Flash/bigid_bgcheck/blob/master/LICENSE.txt) for licensing details.
91
122
 
92
123
  Authors
93
124
  -----------------
data/Rakefile CHANGED
@@ -45,4 +45,4 @@ rescue LoadError
45
45
  # no rspec available
46
46
  end
47
47
 
48
- task default: %i[rubocop ]
48
+ task default: %i[rubocop spec]
@@ -47,11 +47,15 @@ module Bigid
47
47
 
48
48
  Bigid::Bgcheck::Result.new(
49
49
  approved: ResultCode.approved?(body["ResultCode"]),
50
- ticket_id: body["TicketId"],
51
50
  code: body["ResultCode"],
51
+ score_details: body["ScoreDetails"],
52
+ limit_score: body["LimitScore"],
52
53
  message: body["ResultMessage"],
54
+ raw_data: body["RawData"],
55
+ raw_response: body.to_json,
56
+ related_score_details: body["RelatedScoreDetails"],
53
57
  score: body["Score"],
54
- limit_score: body["LimitScore"]
58
+ ticket_id: body["TicketId"]
55
59
  )
56
60
  end
57
61
  end
@@ -3,15 +3,21 @@
3
3
  module Bigid
4
4
  module Bgcheck
5
5
  class Result
6
- attr_accessor :approved, :ticket_id, :code, :message, :score, :limit_score
6
+ attr_accessor :approved, :code, :score_details, :limit_score, :message, :raw_data,
7
+ :raw_response, :related_score_details, :score, :ticket_id
7
8
 
8
- def initialize(approved:, ticket_id:, code:, message:, score:, limit_score:)
9
- @approved = approved
10
- @ticket_id = ticket_id
11
- @code = code
12
- @message = message
13
- @score = score
14
- @limit_score = limit_score
9
+ def initialize(approved:, code:, score_details:, limit_score:, message:, raw_data:, raw_response:,
10
+ related_score_details:, score:, ticket_id:)
11
+ @approved = approved
12
+ @code = code
13
+ @score_details = score_details
14
+ @limit_score = limit_score
15
+ @message = message
16
+ @raw_data = raw_data
17
+ @raw_response = raw_response
18
+ @related_score_details = related_score_details
19
+ @score = score
20
+ @ticket_id = ticket_id
15
21
  end
16
22
  end
17
23
  end
@@ -9,6 +9,6 @@ module Bigid
9
9
  # Major - Incremented for incompatible changes with previous release (or big enough new features)
10
10
  # Minor - Incremented for new backwards-compatible features + deprecations
11
11
  # Patch - Incremented for backwards-compatible bug fixes
12
- VERSION = "0.1.3"
12
+ VERSION = "0.3.1"
13
13
  end
14
14
  end
data/lib/bigid_bgcheck.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "faraday"
4
3
  require "i18n"
5
4
  require "json"
5
+ require "cpf_cnpj"
6
6
 
7
7
  require "bigid_auth"
8
8
 
@@ -26,24 +26,24 @@ I18n.load_path += Dir[File.join(__dir__, "locales", "**/*.yml")]
26
26
  I18n.reload! if I18n.backend.initialized?
27
27
 
28
28
  module Bigid
29
- module Bgcheck
30
- SRV_ENDPOINT = "backgroundcheck"
31
-
32
- class << self
33
- attr_writer :configuration
29
+ class << self
30
+ attr_writer :configuration
34
31
 
35
- def configuration
36
- @configuration ||= Configuration.new
37
- end
32
+ def configuration
33
+ @configuration ||= Configuration.new
38
34
  end
35
+ end
39
36
 
40
- def self.configure
41
- self.configuration ||= Configuration.new
37
+ def self.configure
38
+ self.configuration ||= Configuration.new
42
39
 
43
- yield(configuration)
44
- end
40
+ yield(configuration)
41
+ end
45
42
 
46
- class Configuration
47
- end
43
+ class Configuration
44
+ end
45
+
46
+ module Bgcheck
47
+ SRV_ENDPOINT = "backgroundcheck"
48
48
  end
49
49
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bigid::Bgcheck::BadRequestError do
4
+ include_examples "error"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bigid::Bgcheck::BaseError do
4
+ include_examples "error"
5
+ end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "spec_helper"
4
- require "bigid/bgcheck/doc_type"
5
-
6
3
  RSpec.describe Bigid::Bgcheck::DocType do
7
4
  describe ".valid?(document_type)" do
8
5
  subject { described_class.valid?(document_type) }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bigid::Bgcheck::DocumentNotSupportedError do
4
+ include_examples "error"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bigid::Bgcheck::InternalError do
4
+ include_examples "http_error"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bigid::Bgcheck::InvalidCredentialsError do
4
+ include_examples "error"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bigid::Bgcheck::InvalidDocumentValueError do
4
+ include_examples "error"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bigid::Bgcheck::NoInfoError do
4
+ include_examples "http_error"
5
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bigid::Bgcheck::Request do
4
+ describe "#call" do
5
+ let(:connection) { instance_double(Bigid::Auth::AuthenticatedConnection) }
6
+ let(:body) {
7
+ {
8
+ Login: "username_value",
9
+ parameters: { CNPJ: document },
10
+ Group: group
11
+ }.to_json
12
+ }
13
+ let(:success_result) { build(:result, :approved) }
14
+ let(:success_result_response) {
15
+ JSON.parse({
16
+ body: {
17
+ RawData: success_result.raw_data,
18
+ ScoreDetails: success_result.score_details,
19
+ RelatedScoreDetails: success_result.related_score_details,
20
+ LimitScore: success_result.limit_score,
21
+ ResultCode: success_result.code,
22
+ ResultMessage: success_result.message,
23
+ Score: success_result.score,
24
+ TicketId: success_result.ticket_id
25
+ }.to_json,
26
+ status: request_status
27
+ }.to_json, object_class: OpenStruct)
28
+ }
29
+ let(:document) { CNPJ.generate }
30
+ let(:document_type) { "CNPJ" }
31
+ let(:group) { "Default" }
32
+ let(:request_status) { 200 }
33
+
34
+ subject { described_class.new.call(document: document, document_type: document_type, group: group) }
35
+
36
+ before do
37
+ allow(Bigid::Auth::AuthenticatedConnection).to receive(:new).and_return(connection)
38
+ allow(connection).to receive(:post).and_return(success_result_response)
39
+ end
40
+
41
+ describe ".call" do
42
+ subject { described_class.call(document: document, document_type: document_type, group: group) }
43
+
44
+ it { expect(subject).to be_kind_of(Bigid::Bgcheck::Result) }
45
+
46
+ it { subject; expect(connection).to have_received(:post) }
47
+ end
48
+
49
+ context "when all parameters are valid" do
50
+ it { expect(subject).to be_kind_of(Bigid::Bgcheck::Result) }
51
+
52
+ it { subject; expect(connection).to have_received(:post) }
53
+ end
54
+
55
+ context "when document type is invalid" do
56
+ let(:document_type) { "CNP" }
57
+
58
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::DocumentNotSupportedError) }
59
+ end
60
+
61
+ context "when request status is null" do
62
+ let(:request_status) { nil }
63
+
64
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::InternalError) }
65
+ end
66
+
67
+ context "when request status is server error" do
68
+ let(:request_status) { 500 }
69
+
70
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::ServerError) }
71
+ end
72
+
73
+ context "when request status is auth error" do
74
+ let(:request_status) { 401 }
75
+
76
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::InvalidCredentialsError) }
77
+ end
78
+
79
+ context "when request status is bad request" do
80
+ let(:request_status) { 400 }
81
+
82
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::BadRequestError) }
83
+ end
84
+
85
+ context "when the result code is empty" do
86
+ let(:success_result) { build(:result, :approved, code: nil) }
87
+
88
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::InvalidDocumentValueError) }
89
+ end
90
+
91
+ context "when the result code is empty" do
92
+ let(:success_result) { build(:result, :approved, code: Bigid::Bgcheck::ResultCode::NO_INFO) }
93
+
94
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::NoInfoError) }
95
+ end
96
+ end
97
+ end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "spec_helper"
4
- require "bigid/bgcheck/result_code"
5
-
6
3
  RSpec.describe Bigid::Bgcheck::ResultCode do
7
4
  describe ".valid?(code)" do
8
5
  subject { described_class.valid?(code) }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bigid::Bgcheck::ServerError do
4
+ include_examples "error"
5
+ end
@@ -1,44 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "spec_helper"
4
- require "bigid_bgcheck"
5
-
6
3
  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
4
  describe "SRV_ENDPOINT" do
20
5
  subject { defined? Bigid::Bgcheck::SRV_ENDPOINT }
21
6
 
22
7
  it { expect(subject).to be_truthy }
23
8
  end
24
9
 
25
- describe "TOKEN_EXPIRATION" do
26
- subject { defined? Bigid::Bgcheck::TOKEN_EXPIRATION }
27
-
28
- it { expect(subject).to be_truthy }
29
- end
30
-
31
10
  describe ".configure" do
32
11
  before do
33
- described_class.configuration = nil
12
+ Bigid.configuration = nil
34
13
  ENV.clear
35
14
  end
36
15
 
37
- subject { described_class.configuration }
16
+ subject { Bigid.configuration }
38
17
 
39
18
  context "when configuration is defined" do
40
19
  before do
41
- described_class.configure do |config|
20
+ Bigid.configure do |config|
42
21
  config.username = "username_value"
43
22
  config.password = "password_value"
44
23
  end
@@ -77,7 +56,7 @@ RSpec.describe Bigid::Bgcheck do
77
56
  ENV["BIGID_USERNAME"] = "username_value"
78
57
  ENV["BIGID_PASSWORD"] = "password_value"
79
58
 
80
- described_class.configure do |config|
59
+ Bigid.configure do |config|
81
60
  config.username = "username_value2"
82
61
  config.password = "password_value2"
83
62
  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,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples "error" do
4
+ describe ".initialize" do
5
+ context "when message parameter is null" do
6
+ subject { described_class.new.message }
7
+
8
+ it { expect(subject).to eq(described_class.default_message) }
9
+ end
10
+
11
+ context "when message parameter is not null" do
12
+ subject { described_class.new(message).message }
13
+
14
+ let(:message) { "message" }
15
+
16
+ it { expect(subject).to eq(message) }
17
+ end
18
+ end
19
+
20
+ describe ".default_message" do
21
+ let(:expected_result) { I18n.t("errors.#{described_class.name.underscore.tr("/", ".")}") }
22
+
23
+ subject { described_class.default_message }
24
+
25
+ it "searches the default message in I18n using the class name" do
26
+ expect(subject).to eq(expected_result)
27
+ end
28
+ end
29
+ end
30
+
31
+ RSpec.shared_examples "http_error" do
32
+ include_examples "error"
33
+
34
+ describe "#http_status" do
35
+ subject { described_class.new.http_status }
36
+
37
+ it { expect(subject).to eq(described_class::HTTP_STATUS) }
38
+ end
39
+
40
+ describe "#status" do
41
+ subject { described_class.new.status }
42
+
43
+ it { expect(subject).to eq(described_class::STATUS) }
44
+ end
45
+
46
+ describe "#status_code" do
47
+ subject { described_class.new.status_code }
48
+
49
+ it { expect(subject).to eq(described_class::STATUS_CODE) }
50
+ end
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigid_bgcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Carolino
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-19 00:00:00.000000000 Z
11
+ date: 2022-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigid_auth
@@ -16,27 +16,21 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.1
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: '0.1'
19
+ version: '0.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 0.1.1
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: '0.1'
26
+ version: '0.2'
33
27
  - !ruby/object:Gem::Dependency
34
- name: faraday
28
+ name: i18n
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: 1.4.1
33
+ version: '1.8'
40
34
  - - ">="
41
35
  - !ruby/object:Gem::Version
42
36
  version: '1.0'
@@ -46,106 +40,92 @@ dependencies:
46
40
  requirements:
47
41
  - - "~>"
48
42
  - !ruby/object:Gem::Version
49
- version: 1.4.1
43
+ version: '1.8'
50
44
  - - ">="
51
45
  - !ruby/object:Gem::Version
52
46
  version: '1.0'
53
47
  - !ruby/object:Gem::Dependency
54
- name: i18n
48
+ name: json
55
49
  requirement: !ruby/object:Gem::Requirement
56
50
  requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: 1.8.0
60
51
  - - ">="
61
52
  - !ruby/object:Gem::Version
62
- version: '1.0'
53
+ version: '2.5'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '2.7'
63
57
  type: :runtime
64
58
  prerelease: false
65
59
  version_requirements: !ruby/object:Gem::Requirement
66
60
  requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: 1.8.0
70
61
  - - ">="
71
62
  - !ruby/object:Gem::Version
72
- version: '1.0'
63
+ version: '2.5'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '2.7'
73
67
  - !ruby/object:Gem::Dependency
74
- name: json
68
+ name: cpf_cnpj
75
69
  requirement: !ruby/object:Gem::Requirement
76
70
  requirements:
77
71
  - - "~>"
78
72
  - !ruby/object:Gem::Version
79
- version: 2.5.0
73
+ version: '0.5'
80
74
  - - ">="
81
75
  - !ruby/object:Gem::Version
82
- version: '2.0'
76
+ version: '0.5'
83
77
  type: :runtime
84
78
  prerelease: false
85
79
  version_requirements: !ruby/object:Gem::Requirement
86
80
  requirements:
87
81
  - - "~>"
88
82
  - !ruby/object:Gem::Version
89
- version: 2.5.0
83
+ version: '0.5'
90
84
  - - ">="
91
85
  - !ruby/object:Gem::Version
92
- version: '2.0'
86
+ version: '0.5'
93
87
  - !ruby/object:Gem::Dependency
94
88
  name: bundler
95
89
  requirement: !ruby/object:Gem::Requirement
96
90
  requirements:
97
91
  - - ">="
98
92
  - !ruby/object:Gem::Version
99
- version: 1.2.0
93
+ version: '1.2'
100
94
  type: :development
101
95
  prerelease: false
102
96
  version_requirements: !ruby/object:Gem::Requirement
103
97
  requirements:
104
98
  - - ">="
105
99
  - !ruby/object:Gem::Version
106
- version: 1.2.0
100
+ version: '1.2'
107
101
  - !ruby/object:Gem::Dependency
108
102
  name: factory_bot
109
103
  requirement: !ruby/object:Gem::Requirement
110
104
  requirements:
111
105
  - - "~>"
112
106
  - !ruby/object:Gem::Version
113
- version: 6.1.0
114
- type: :development
115
- prerelease: false
116
- version_requirements: !ruby/object:Gem::Requirement
117
- requirements:
118
- - - "~>"
119
- - !ruby/object:Gem::Version
120
- version: 6.1.0
121
- - !ruby/object:Gem::Dependency
122
- name: gemsurance
123
- requirement: !ruby/object:Gem::Requirement
124
- requirements:
125
- - - "~>"
126
- - !ruby/object:Gem::Version
127
- version: '0.10'
107
+ version: '6.2'
128
108
  type: :development
129
109
  prerelease: false
130
110
  version_requirements: !ruby/object:Gem::Requirement
131
111
  requirements:
132
112
  - - "~>"
133
113
  - !ruby/object:Gem::Version
134
- version: '0.10'
114
+ version: '6.2'
135
115
  - !ruby/object:Gem::Dependency
136
116
  name: pry
137
117
  requirement: !ruby/object:Gem::Requirement
138
118
  requirements:
139
119
  - - "~>"
140
120
  - !ruby/object:Gem::Version
141
- version: 0.14.0
121
+ version: '0.14'
142
122
  type: :development
143
123
  prerelease: false
144
124
  version_requirements: !ruby/object:Gem::Requirement
145
125
  requirements:
146
126
  - - "~>"
147
127
  - !ruby/object:Gem::Version
148
- version: 0.14.0
128
+ version: '0.14'
149
129
  - !ruby/object:Gem::Dependency
150
130
  name: rake
151
131
  requirement: !ruby/object:Gem::Requirement
@@ -172,70 +152,84 @@ dependencies:
172
152
  requirements:
173
153
  - - "~>"
174
154
  - !ruby/object:Gem::Version
175
- version: 3.10.0
155
+ version: '3.10'
176
156
  type: :development
177
157
  prerelease: false
178
158
  version_requirements: !ruby/object:Gem::Requirement
179
159
  requirements:
180
160
  - - "~>"
181
161
  - !ruby/object:Gem::Version
182
- version: 3.10.0
162
+ version: '3.10'
183
163
  - !ruby/object:Gem::Dependency
184
164
  name: rubocop
185
165
  requirement: !ruby/object:Gem::Requirement
186
166
  requirements:
187
167
  - - "~>"
188
168
  - !ruby/object:Gem::Version
189
- version: 1.12.0
169
+ version: '1.25'
190
170
  type: :development
191
171
  prerelease: false
192
172
  version_requirements: !ruby/object:Gem::Requirement
193
173
  requirements:
194
174
  - - "~>"
195
175
  - !ruby/object:Gem::Version
196
- version: 1.12.0
176
+ version: '1.25'
197
177
  - !ruby/object:Gem::Dependency
198
178
  name: rubocop-packaging
199
179
  requirement: !ruby/object:Gem::Requirement
200
180
  requirements:
201
181
  - - "~>"
202
182
  - !ruby/object:Gem::Version
203
- version: 0.5.0
183
+ version: '0.5'
204
184
  type: :development
205
185
  prerelease: false
206
186
  version_requirements: !ruby/object:Gem::Requirement
207
187
  requirements:
208
188
  - - "~>"
209
189
  - !ruby/object:Gem::Version
210
- version: 0.5.0
190
+ version: '0.5'
211
191
  - !ruby/object:Gem::Dependency
212
192
  name: rubocop-performance
213
193
  requirement: !ruby/object:Gem::Requirement
214
194
  requirements:
215
195
  - - "~>"
216
196
  - !ruby/object:Gem::Version
217
- version: 1.10.0
197
+ version: '1.13'
218
198
  type: :development
219
199
  prerelease: false
220
200
  version_requirements: !ruby/object:Gem::Requirement
221
201
  requirements:
222
202
  - - "~>"
223
203
  - !ruby/object:Gem::Version
224
- version: 1.10.0
204
+ version: '1.13'
225
205
  - !ruby/object:Gem::Dependency
226
206
  name: simplecov
227
207
  requirement: !ruby/object:Gem::Requirement
228
208
  requirements:
229
209
  - - "~>"
230
210
  - !ruby/object:Gem::Version
231
- version: 0.21.0
211
+ version: '0.21'
212
+ type: :development
213
+ prerelease: false
214
+ version_requirements: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - "~>"
217
+ - !ruby/object:Gem::Version
218
+ version: '0.21'
219
+ - !ruby/object:Gem::Dependency
220
+ name: simplecov-json
221
+ requirement: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - "~>"
224
+ - !ruby/object:Gem::Version
225
+ version: '0.2'
232
226
  type: :development
233
227
  prerelease: false
234
228
  version_requirements: !ruby/object:Gem::Requirement
235
229
  requirements:
236
230
  - - "~>"
237
231
  - !ruby/object:Gem::Version
238
- version: 0.21.0
232
+ version: '0.2'
239
233
  description: A library to use BigData Corps background check features
240
234
  email:
241
235
  - danilo.carolino@qflash.com.br
@@ -263,18 +257,29 @@ files:
263
257
  - lib/bigid_bgcheck.rb
264
258
  - lib/locales/en.yml
265
259
  - lib/locales/pt-BR.yml
260
+ - spec/bigid/bgcheck/bad_request_error_spec.rb
261
+ - spec/bigid/bgcheck/base_error_spec.rb
262
+ - spec/bigid/bgcheck/doc_type_spec.rb
263
+ - spec/bigid/bgcheck/document_not_supported_error_spec.rb
264
+ - spec/bigid/bgcheck/internal_error_spec.rb
265
+ - spec/bigid/bgcheck/invalid_credentials_error_spec.rb
266
+ - spec/bigid/bgcheck/invalid_document_value_error_spec.rb
267
+ - spec/bigid/bgcheck/no_info_error_spec.rb
268
+ - spec/bigid/bgcheck/request_spec.rb
269
+ - spec/bigid/bgcheck/result_code_spec.rb
270
+ - spec/bigid/bgcheck/server_error_spec.rb
266
271
  - spec/bigid_bgcheck_spec.rb
267
- - spec/lib/bgcheck/doc_type_spec.rb
268
- - spec/lib/bgcheck/result_code_spec.rb
272
+ - spec/factories/result.rb
269
273
  - spec/spec_helper.rb
270
- homepage: https://github.com/Quasar-Flash/bigid-bgcheck-ruby
274
+ - spec/support/shared_examples/errors_shared_examples.rb
275
+ homepage: https://github.com/Quasar-Flash/bigid_bgcheck
271
276
  licenses:
272
277
  - MIT
273
278
  metadata:
274
- changelog_uri: https://github.com/Quasar-Flash/bigid-bgcheck-ruby/blob/master/CHANGELOG.md
275
- source_code_uri: https://github.com/Quasar-Flash/bigid-bgcheck-ruby
276
- bug_tracker_uri: https://github.com/Quasar-Flash/bigid-bgcheck-ruby/issues
277
- post_install_message:
279
+ changelog_uri: https://github.com/Quasar-Flash/bigid_bgcheck/blob/master/CHANGELOG.md
280
+ source_code_uri: https://github.com/Quasar-Flash/bigid_bgcheck
281
+ bug_tracker_uri: https://github.com/Quasar-Flash/bigid_bgcheck/issues
282
+ post_install_message:
278
283
  rdoc_options: []
279
284
  require_paths:
280
285
  - lib
@@ -282,19 +287,30 @@ required_ruby_version: !ruby/object:Gem::Requirement
282
287
  requirements:
283
288
  - - ">="
284
289
  - !ruby/object:Gem::Version
285
- version: '2.5'
290
+ version: '2.7'
286
291
  required_rubygems_version: !ruby/object:Gem::Requirement
287
292
  requirements:
288
293
  - - ">="
289
294
  - !ruby/object:Gem::Version
290
295
  version: '0'
291
296
  requirements: []
292
- rubygems_version: 3.1.4
293
- signing_key:
297
+ rubygems_version: 3.3.3
298
+ signing_key:
294
299
  specification_version: 4
295
300
  summary: Bigid Background Check Library
296
301
  test_files:
302
+ - spec/bigid/bgcheck/bad_request_error_spec.rb
303
+ - spec/bigid/bgcheck/base_error_spec.rb
304
+ - spec/bigid/bgcheck/doc_type_spec.rb
305
+ - spec/bigid/bgcheck/document_not_supported_error_spec.rb
306
+ - spec/bigid/bgcheck/internal_error_spec.rb
307
+ - spec/bigid/bgcheck/invalid_credentials_error_spec.rb
308
+ - spec/bigid/bgcheck/invalid_document_value_error_spec.rb
309
+ - spec/bigid/bgcheck/no_info_error_spec.rb
310
+ - spec/bigid/bgcheck/request_spec.rb
311
+ - spec/bigid/bgcheck/result_code_spec.rb
312
+ - spec/bigid/bgcheck/server_error_spec.rb
297
313
  - spec/bigid_bgcheck_spec.rb
298
- - spec/lib/bgcheck/result_code_spec.rb
299
- - spec/lib/bgcheck/doc_type_spec.rb
314
+ - spec/factories/result.rb
300
315
  - spec/spec_helper.rb
316
+ - spec/support/shared_examples/errors_shared_examples.rb