Skip to content

Commit 50a46d8

Browse files
rtymchyknothingisfunny
authored andcommitted
AdverseItem and AdverseAction Resources (#61)
Add AdverseItem and AdverseAction Resources
1 parent 9701f3f commit 50a46d8

File tree

8 files changed

+244
-0
lines changed

8 files changed

+244
-0
lines changed

lib/checkr.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
require 'checkr/util'
1919

2020
# Requires for classes
21+
require 'checkr/adverse_action'
22+
require 'checkr/adverse_item'
23+
require 'checkr/adverse_item_list'
2124
require 'checkr/candidate'
2225
require 'checkr/county_criminal_search'
2326
require 'checkr/document'

lib/checkr/adverse_action.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Checkr
2+
class AdverseAction < APIResource
3+
attribute :status
4+
attribute :report_id
5+
attribute :post_notice_scheduled_at
6+
attribute :post_notice_ready_at
7+
attribute :canceled_at
8+
attribute :individualized_assessment_engaged
9+
attribute :adverse_items, APIList.constructor(:AdverseItem)
10+
11+
api_class_method :create, :post, '/v1/reports/:report_id/adverse_actions'
12+
api_class_method :retrieve, :get, ':path/:id', :arguments => [:id]
13+
api_class_method :cancel, :delete, ':path/:id', :arguments => [:id]
14+
15+
api_instance_method :cancel, :delete
16+
17+
def self.path
18+
'/v1/adverse_actions'
19+
end
20+
21+
APIClass.register_subclass(self, 'adverse_action')
22+
end
23+
end

lib/checkr/adverse_item.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Checkr
2+
class AdverseItem < APIResource
3+
attribute :text
4+
5+
api_class_method :all, :get, '/v1/reports/:report_id/adverse_items', :constructor => :AdverseItemList
6+
7+
APIClass.register_subclass(self, 'adverse_item')
8+
end
9+
end

lib/checkr/adverse_item_list.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Checkr
2+
class AdverseItemList < APIList
3+
4+
attribute :next_href
5+
attribute :previous_href
6+
attribute :count
7+
attr_accessor :parent
8+
9+
api_instance_method :all, :get
10+
11+
def self.construct(json, parent=nil)
12+
lambda = constructor(:AdverseItem)
13+
instance = lambda.call(json)
14+
instance.parent = parent if parent
15+
instance.clear_changed_attributes
16+
instance
17+
end
18+
19+
def path
20+
parent.path + '/adverse_items'
21+
end
22+
23+
end
24+
end

lib/checkr/report.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class Report < APIResource
1111
attribute :candidate, :Candidate
1212
attribute_writer_alias :candidate_id, :candidate
1313

14+
attribute :adverse_items, :AdverseItemList, :nested => true, :default => {}
15+
attribute_writer_alias :adverse_item_ids, :adverse_items
16+
1417
attribute :ssn_trace, :SSNTrace
1518
attribute_writer_alias :ssn_trace_id, :ssn_trace
1619

test/checkr/adverse_action_test.rb

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
require File.expand_path('../../test_helper', __FILE__)
2+
3+
module Checkr
4+
class AdverseActionTest < Test::Unit::TestCase
5+
setup do
6+
@adverse_action_url = "#{Checkr.api_base}#{AdverseAction.path}"
7+
end
8+
9+
should 'be registered' do
10+
assert(APIClass.subclasses.include?(AdverseAction))
11+
assert_equal(AdverseAction, APIClass.subclass_fetch('adverse_action'))
12+
end
13+
14+
context 'Constructed AdverseAction instance' do
15+
setup do
16+
@adverse_action = AdverseAction.construct(test_adverse_action)
17+
end
18+
19+
[
20+
:id,
21+
:object,
22+
:uri,
23+
:created_at,
24+
:status,
25+
:report_id,
26+
:post_notice_scheduled_at,
27+
:post_notice_ready_at,
28+
:canceled_at,
29+
:individualized_assessment_engaged,
30+
].each do |attribute|
31+
should "have the #{attribute.to_s} attribute" do
32+
assert_equal(test_adverse_action[attribute], @adverse_action.public_send(attribute))
33+
end
34+
end
35+
end
36+
37+
context '.create' do
38+
setup do
39+
@report = Report.construct(test_report)
40+
@create_url = "#{Checkr.api_base}#{Report.path}/#{@report.id}/adverse_actions"
41+
end
42+
43+
should 'creates an instance of AdverseAction' do
44+
@mock.expects(:post).once.with(@create_url, anything, anything)
45+
.returns(test_response(test_adverse_action))
46+
47+
adverse_action = AdverseAction.create({ :report_id => @report.id })
48+
49+
assert(adverse_action.is_a?(AdverseAction))
50+
assert_equal(test_adverse_action[:id], adverse_action.id)
51+
end
52+
end
53+
54+
context '.retrieve' do
55+
setup do
56+
@id = test_adverse_action[:id]
57+
@retrieve_url = "#{Checkr.api_base}#{AdverseAction.path}/#{@id}"
58+
end
59+
60+
should 'fetches an instance of AdverseAction' do
61+
@mock.expects(:get).once.with(@retrieve_url, anything, anything)
62+
.returns(test_response(test_adverse_action))
63+
64+
adverse_action = AdverseAction.retrieve(@id)
65+
66+
assert(adverse_action.is_a?(AdverseAction))
67+
assert_equal(@id, adverse_action.id)
68+
end
69+
end
70+
71+
context '#cancel/.cancel' do
72+
setup do
73+
@id = test_adverse_action[:id]
74+
@cancel_url = "#{Checkr.api_base}#{AdverseAction.path}/#{@id}"
75+
end
76+
77+
should 'cancels an instance of AdverseAction' do
78+
@mock.expects(:delete).twice.with(@cancel_url, anything, anything)
79+
.returns(test_response(test_adverse_action))
80+
81+
adverse_action = AdverseAction.cancel(@id)
82+
assert(adverse_action.is_a?(AdverseAction))
83+
assert_equal(@id, adverse_action.id)
84+
85+
adverse_action = AdverseAction.new(@id).cancel
86+
assert(adverse_action.is_a?(AdverseAction))
87+
assert_equal(@id, adverse_action.id)
88+
end
89+
end
90+
end
91+
end

test/checkr/adverse_item_test.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require File.expand_path('../../test_helper', __FILE__)
2+
3+
module Checkr
4+
class AdverseItemTest < Test::Unit::TestCase
5+
setup do
6+
@report = Report.construct(test_report)
7+
@adverse_item_url = "#{Checkr.api_base}#{@report.path}/adverse_items"
8+
end
9+
10+
context 'Constructed AdverseItem instance' do
11+
setup do
12+
@adverse_item = AdverseItem.construct(test_adverse_item)
13+
end
14+
15+
[
16+
:id,
17+
:object,
18+
:uri,
19+
:created_at,
20+
:text,
21+
].each do |attribute|
22+
should "have the #{attribute.to_s} attribute" do
23+
assert_equal(test_adverse_item[attribute], @adverse_item.public_send(attribute))
24+
end
25+
end
26+
end
27+
28+
context '.all' do
29+
should 'return instances of AdverseItem' do
30+
@mock.expects(:get).once.with do |url, params, opts|
31+
url.start_with?(@adverse_item_url)
32+
end.returns(test_response(test_adverse_item_list))
33+
34+
adverse_items = AdverseItem.all({ :report_id => @report.id })
35+
36+
assert(adverse_items.is_a?(AdverseItemList))
37+
assert(adverse_items.length > 0)
38+
adverse_items.each do |adverse_item|
39+
assert(adverse_item.is_a?(AdverseItem))
40+
end
41+
end
42+
end
43+
44+
should 'be registered' do
45+
assert(APIClass.subclasses.include?(AdverseItem))
46+
assert_equal(AdverseItem, APIClass.subclass_fetch('adverse_item'))
47+
end
48+
end
49+
end

test/test_data.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ def test_document
513513
:type=>"driver_license",
514514
:content_type=>"image/jpeg"}
515515
end
516+
516517
def test_document_list
517518
{
518519
:object => 'list',
@@ -528,13 +529,54 @@ def test_verification
528529
:verification_url=>"http://verifications.checkr.com/db313e73383710d4fa2f18fd",
529530
:completed_at=>nil}
530531
end
532+
531533
def test_verification_list
532534
{
533535
:object => 'list',
534536
:data => [test_verification, test_verification, test_verification],
535537
}
536538
end
537539

540+
def test_adverse_item
541+
{
542+
:id => '71c0c2c79349c9f899bda22d3ccf60b7e0469266',
543+
:object => 'adverse_item',
544+
:text => 'License status: Suspended',
545+
}
546+
end
547+
548+
def test_adverse_item_list
549+
{
550+
:object => 'list',
551+
:count => 2,
552+
:data => [test_adverse_item, test_adverse_item],
553+
}
554+
end
555+
556+
def test_adverse_action
557+
{
558+
:id => '5d0af2cdfccff00034be49e9',
559+
:object => 'adverse_action',
560+
:uri => '/v1/adverse_actions/5d0af2cdfccff00034be49e9',
561+
:created_at => '2019-06-20T02:43:25Z',
562+
:status => 'pending',
563+
:report_id => 'd36abda710bde8fd2c9d2587',
564+
:post_notice_scheduled_at => '2019-06-27T02:43:25Z',
565+
:post_notice_ready_at => '2019-06-27T02:43:25Z',
566+
:canceled_at => nil,
567+
:individualized_assessment_engaged => false,
568+
:adverse_items => test_adverse_item_list,
569+
}
570+
end
571+
572+
def test_adverse_action_list
573+
{
574+
:object => 'list',
575+
:count => 2,
576+
:data => [test_adverse_action, test_adverse_action],
577+
}
578+
end
579+
538580
def test_education_verification
539581
{:id => "5af5e030d24297006cce1e06",
540582
:object => "education_verification",

0 commit comments

Comments
 (0)