checkr-canada 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +76 -0
- data/.travis.yml +5 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +140 -0
- data/Rakefile +6 -0
- data/bin/console +16 -0
- data/bin/setup +8 -0
- data/checkr-canada.gemspec +27 -0
- data/lib/checkr-canada.rb +3 -0
- data/lib/checkr/canada.rb +9 -0
- data/lib/checkr/canada/client.rb +34 -0
- data/lib/checkr/canada/entities/address.rb +51 -0
- data/lib/checkr/canada/entities/candidate.rb +113 -0
- data/lib/checkr/canada/entities/criminal_record.rb +49 -0
- data/lib/checkr/canada/entities/document.rb +48 -0
- data/lib/checkr/canada/entities/report.rb +104 -0
- data/lib/checkr/canada/ext/stringify_json_patch.rb +11 -0
- data/lib/checkr/canada/types.rb +60 -0
- data/lib/checkr/canada/version.rb +7 -0
- data/spec/cases/addresses_spec.rb +66 -0
- data/spec/cases/authentication_spec.rb +42 -0
- data/spec/cases/candidates_spec.rb +148 -0
- data/spec/cases/criminal_records_spec.rb +57 -0
- data/spec/cases/document_spec.rb +63 -0
- data/spec/cases/reports_spec.rb +150 -0
- data/spec/checkr/canada/types_spec.rb +109 -0
- data/spec/checkr/canada_spec.rb +9 -0
- data/spec/fixtures/address.json +14 -0
- data/spec/fixtures/candidate.json +24 -0
- data/spec/fixtures/candidates.json +30 -0
- data/spec/fixtures/criminal_record.json +10 -0
- data/spec/fixtures/document.json +8 -0
- data/spec/fixtures/report.json +17 -0
- data/spec/fixtures/reports.json +23 -0
- data/spec/spec_helper.rb +22 -0
- metadata +166 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Criminal Records" do
|
6
|
+
let(:client) { Checkr::Canada::Client.new("test_api_key") }
|
7
|
+
|
8
|
+
describe "#create" do
|
9
|
+
let(:answer) do
|
10
|
+
File.read("./spec/fixtures/criminal_record.json")
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:params) do
|
14
|
+
{
|
15
|
+
candidate_id: 'abc123xyz',
|
16
|
+
offence: "Pissing in the street",
|
17
|
+
sentence_date: Time.new(2001, 3, 21, 14, 0, 0),
|
18
|
+
location: "Moscow"
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
subject(:doc) { client.criminal_records.create(**params) }
|
23
|
+
|
24
|
+
before do
|
25
|
+
stub_request(:post, /candidates\/abc123xyz\/criminal_records/)
|
26
|
+
.to_return(
|
27
|
+
body: answer,
|
28
|
+
status: 201
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "makes request" do
|
33
|
+
subject
|
34
|
+
|
35
|
+
expect(
|
36
|
+
a_request(:post, "https://api.checkr.com/ca/v1/candidates/abc123xyz/criminal_records")
|
37
|
+
).to have_been_made
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns a record", :aggregate_failures do
|
41
|
+
expect(doc.sentence_date).to eq "2001-03-21"
|
42
|
+
expect(doc.created_at).to be_a(DateTime)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "raises when missing params" do
|
46
|
+
params.delete(:offence)
|
47
|
+
|
48
|
+
expect { subject }.to raise_error(ArgumentError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "raises when missing candidate_id" do
|
52
|
+
params.delete(:candidate_id)
|
53
|
+
|
54
|
+
expect { subject }.to raise_error(ArgumentError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Documents" do
|
6
|
+
let(:client) { Checkr::Canada::Client.new("test_api_key") }
|
7
|
+
|
8
|
+
describe "#upload" do
|
9
|
+
let(:answer) do
|
10
|
+
File.read("./spec/fixtures/document.json")
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:params) do
|
14
|
+
{
|
15
|
+
candidate_id: 'abc123xyz',
|
16
|
+
type: "identification",
|
17
|
+
url: "http://example.com/image.png",
|
18
|
+
filename: "test.png"
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
subject(:doc) { client.documents.upload(**params) }
|
23
|
+
|
24
|
+
before do
|
25
|
+
stub_request(:post, /candidates\/abc123xyz\/documents/)
|
26
|
+
.to_return(
|
27
|
+
body: answer,
|
28
|
+
status: 201
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "makes request" do
|
33
|
+
subject
|
34
|
+
|
35
|
+
expect(
|
36
|
+
a_request(:post, "https://api.checkr.com/ca/v1/candidates/abc123xyz/documents")
|
37
|
+
).to have_been_made
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns a document", :aggregate_failures do
|
41
|
+
expect(doc.filename).to eq "test.png"
|
42
|
+
expect(doc.created_at).to be_a(DateTime)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "raises when missing params" do
|
46
|
+
params.delete(:type)
|
47
|
+
|
48
|
+
expect { subject }.to raise_error(ArgumentError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "raises when unknown type" do
|
52
|
+
params[:type] = "image"
|
53
|
+
|
54
|
+
expect { subject }.to raise_error(TypeError)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "raises when missing candidate_id" do
|
58
|
+
params.delete(:candidate_id)
|
59
|
+
|
60
|
+
expect { subject }.to raise_error(ArgumentError)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Reports" do
|
6
|
+
let(:client) { Checkr::Canada::Client.new("test_api_key") }
|
7
|
+
|
8
|
+
describe "#all" do
|
9
|
+
let(:answer) { { data: [], object: "list", count: 0 }.to_json }
|
10
|
+
let(:options) { {} }
|
11
|
+
|
12
|
+
subject { client.reports.all(**options) }
|
13
|
+
|
14
|
+
before do
|
15
|
+
stub_request(:get, /reports/)
|
16
|
+
.to_return(
|
17
|
+
body: answer
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "builds response", :aggregate_failures do
|
22
|
+
expect(subject.count).to eq 0
|
23
|
+
expect(subject.object).to eq 'list'
|
24
|
+
expect(subject.next_href).to be_nil
|
25
|
+
expect(subject.previous_href).to be_nil
|
26
|
+
expect(subject.data.size).to eq 0
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with params" do
|
30
|
+
let(:options) { { per_page: 1, page: 2, foo: "bar" } }
|
31
|
+
|
32
|
+
it "recognizes only valid params" do
|
33
|
+
subject
|
34
|
+
|
35
|
+
expect(
|
36
|
+
a_request(:get, "https://api.checkr.com/ca/v1/reports")
|
37
|
+
.with(query: { per_page: 1, page: 2 })
|
38
|
+
).to have_been_made
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with data" do
|
43
|
+
let(:answer) do
|
44
|
+
File.read("./spec/fixtures/reports.json")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "builds report", :aggregate_failures do
|
48
|
+
expect(subject.data.size).to eq 1
|
49
|
+
|
50
|
+
report = subject.data.first
|
51
|
+
|
52
|
+
expect(report.package).to eq "criminal"
|
53
|
+
expect(report.created_at).to be_a(DateTime)
|
54
|
+
expect(report.created_at.to_date).to eq Date.new(2017, 5, 2)
|
55
|
+
expect(report.candidate_id).to eq "7f23225f47ee143389595481"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#get" do
|
61
|
+
let(:answer) do
|
62
|
+
File.read("./spec/fixtures/report.json")
|
63
|
+
end
|
64
|
+
|
65
|
+
subject(:report) { client.reports.get('123abc') }
|
66
|
+
|
67
|
+
before do
|
68
|
+
stub_request(:get, /reports\/123/)
|
69
|
+
.to_return(
|
70
|
+
body: answer
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "makes request" do
|
75
|
+
subject
|
76
|
+
|
77
|
+
expect(
|
78
|
+
a_request(:get, "https://api.checkr.com/ca/v1/reports/123abc")
|
79
|
+
).to have_been_made
|
80
|
+
end
|
81
|
+
|
82
|
+
it "builds report", :aggregate_failures do
|
83
|
+
expect(report.package).to eq "criminal"
|
84
|
+
expect(report.created_at).to be_a(DateTime)
|
85
|
+
expect(report.created_at.to_date).to eq Date.new(2017, 5, 2)
|
86
|
+
expect(report.candidate_id).to eq "7f23225f47ee143389595481"
|
87
|
+
end
|
88
|
+
|
89
|
+
context "not found" do
|
90
|
+
before do
|
91
|
+
stub_request(:get, /reports\/123/)
|
92
|
+
.to_return(
|
93
|
+
body: { message: 'Not found' }.to_json,
|
94
|
+
status: 404
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "raises error" do
|
99
|
+
expect { subject }.to raise_error(Evil::Client::Operation::ResponseError)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#create" do
|
105
|
+
let(:answer) do
|
106
|
+
File.read("./spec/fixtures/report.json")
|
107
|
+
end
|
108
|
+
|
109
|
+
let(:params) do
|
110
|
+
{
|
111
|
+
candidate_id: "abc123",
|
112
|
+
package: "criminal"
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
subject(:report) { client.reports.create(params) }
|
117
|
+
|
118
|
+
before do
|
119
|
+
stub_request(:post, /reports/)
|
120
|
+
.to_return(
|
121
|
+
body: answer,
|
122
|
+
status: 201
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "makes request" do
|
127
|
+
subject
|
128
|
+
|
129
|
+
expect(
|
130
|
+
a_request(:post, "https://api.checkr.com/ca/v1/candidates/abc123/reports")
|
131
|
+
).to have_been_made
|
132
|
+
end
|
133
|
+
|
134
|
+
it "returns a report", :aggregate_failures do
|
135
|
+
expect(report.package).to eq "criminal"
|
136
|
+
end
|
137
|
+
|
138
|
+
it "raises when unknown package" do
|
139
|
+
params[:package] = "test"
|
140
|
+
|
141
|
+
expect { subject }.to raise_error(Dry::Types::ConstraintError)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "raises when missing candidate_id" do
|
145
|
+
params.delete(:candidate_id)
|
146
|
+
|
147
|
+
expect { subject }.to raise_error(ArgumentError)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Checkr::Canada::Types do
|
6
|
+
describe "Status" do
|
7
|
+
subject { described_class::Status }
|
8
|
+
|
9
|
+
it "accepts", :aggregate_failures do
|
10
|
+
expect(subject["clear"]).to eq "clear"
|
11
|
+
expect(subject["pending"]).to eq "pending"
|
12
|
+
expect(subject["consider"]).to eq "consider"
|
13
|
+
expect(subject["suspended"]).to eq "suspended"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "rejects" do
|
17
|
+
expect { subject["foobar"] }.to raise_error(Dry::Types::ConstraintError)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Date" do
|
22
|
+
subject { described_class::Date }
|
23
|
+
|
24
|
+
it "accepts valid string" do
|
25
|
+
expect(subject["1989-07-01"]).to eq "1989-07-01"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "accepts Date" do
|
29
|
+
expect(subject[Date.new(1988, 2, 12)]).to eq "1988-02-12"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "accepts Time" do
|
33
|
+
expect(subject[Time.new(1990, 12, 31, 12, 0, 0)]).to eq "1990-12-31"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "rejects invalid string" do
|
37
|
+
expect { subject["today"] }.to raise_error(Dry::Types::ConstraintError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "Gender" do
|
42
|
+
subject { described_class::Gender }
|
43
|
+
|
44
|
+
it "accepts", :aggregate_failures do
|
45
|
+
expect(subject["M"]).to eq "M"
|
46
|
+
expect(subject["F"]).to eq "F"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "rejects" do
|
50
|
+
expect { subject["Any"] }.to raise_error(Dry::Types::ConstraintError)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "Package" do
|
55
|
+
subject { described_class::Package }
|
56
|
+
|
57
|
+
it "accepts", :aggregate_failures do
|
58
|
+
expect(subject["mvr"]).to eq "mvr"
|
59
|
+
expect(subject["criminal"]).to eq "criminal"
|
60
|
+
expect(subject["criminal_mvr"]).to eq "criminal_mvr"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "rejects" do
|
64
|
+
expect { subject["stupid"] }.to raise_error(Dry::Types::ConstraintError)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "DocumentType" do
|
69
|
+
subject { described_class::DocumentType }
|
70
|
+
|
71
|
+
it "accepts", :aggregate_failures do
|
72
|
+
expect(subject["identification"]).to eq "identification"
|
73
|
+
expect(subject["consent"]).to eq "consent"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "rejects" do
|
77
|
+
expect { subject["image"] }.to raise_error(Dry::Types::ConstraintError)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "Province" do
|
82
|
+
subject { described_class::Province }
|
83
|
+
|
84
|
+
it "accepts", :aggregate_failures do
|
85
|
+
# rubocop: disable Style/WordArray
|
86
|
+
[
|
87
|
+
'AB',
|
88
|
+
'BC',
|
89
|
+
'MB',
|
90
|
+
'NB',
|
91
|
+
'NL',
|
92
|
+
'NT',
|
93
|
+
'NS',
|
94
|
+
'NU',
|
95
|
+
'ON',
|
96
|
+
'PE',
|
97
|
+
'QC',
|
98
|
+
'SK',
|
99
|
+
'YT'
|
100
|
+
].each do |province|
|
101
|
+
expect(subject[province]).to eq province
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it "rejects" do
|
106
|
+
expect { subject["New York"] }.to raise_error(Dry::Types::ConstraintError)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"id": "123123zya",
|
3
|
+
"object": "address",
|
4
|
+
"uri": "/ca/v1/addresses/123123zya",
|
5
|
+
"created_at": "2017-03-23T03:02:52Z",
|
6
|
+
"updated_at": "2017-03-23T03:02:52Z",
|
7
|
+
"street1": "Mission st",
|
8
|
+
"street2": "4-2",
|
9
|
+
"city": "San Francisco",
|
10
|
+
"region": "BC",
|
11
|
+
"country": "CA",
|
12
|
+
"postal_code": "BC341",
|
13
|
+
"start_date": "2017-01-02"
|
14
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"id": "ca1b9ca32fc52fd902a57487",
|
3
|
+
"custom_id": null,
|
4
|
+
"birth_country": "CA",
|
5
|
+
"birth_place": "Toronto",
|
6
|
+
"dob": "1975-03-19",
|
7
|
+
"driver_license_number": null,
|
8
|
+
"driver_license_province": null,
|
9
|
+
"email": "testonboard@test.com",
|
10
|
+
"entry_date": null,
|
11
|
+
"first_name": "Test",
|
12
|
+
"gender": "M",
|
13
|
+
"last_name": "Candidate",
|
14
|
+
"middle_name": "",
|
15
|
+
"mother_maiden_name": null,
|
16
|
+
"nationality": null,
|
17
|
+
"object": "test_candidate",
|
18
|
+
"phone": "000-000-0002",
|
19
|
+
"province": null,
|
20
|
+
"uri": "/ca/v1/candidates/ca1b9ca32fc52fd902a57487",
|
21
|
+
"created_at": "2017-03-23T03:02:52Z",
|
22
|
+
"address_ids": [],
|
23
|
+
"disclosed_criminal_record_ids": []
|
24
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"object": "list",
|
3
|
+
"count": 1,
|
4
|
+
"data": [
|
5
|
+
{
|
6
|
+
"id": "ca1b9ca32fc52fd902a57487",
|
7
|
+
"custom_id": null,
|
8
|
+
"birth_country": "CA",
|
9
|
+
"birth_place": "Toronto",
|
10
|
+
"dob": "1975-03-19",
|
11
|
+
"driver_license_number": null,
|
12
|
+
"driver_license_province": null,
|
13
|
+
"email": "testonboard@test.com",
|
14
|
+
"entry_date": null,
|
15
|
+
"first_name": "Test",
|
16
|
+
"gender": "M",
|
17
|
+
"last_name": "Candidate",
|
18
|
+
"middle_name": "",
|
19
|
+
"mother_maiden_name": null,
|
20
|
+
"nationality": null,
|
21
|
+
"object": "test_candidate",
|
22
|
+
"phone": "000-000-0002",
|
23
|
+
"province": null,
|
24
|
+
"uri": "/ca/v1/candidates/ca1b9ca32fc52fd902a57487",
|
25
|
+
"created_at": "2017-03-23T03:02:52Z",
|
26
|
+
"address_ids": [],
|
27
|
+
"disclosed_criminal_record_ids": []
|
28
|
+
}
|
29
|
+
]
|
30
|
+
}
|