Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/checkr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
require 'checkr/util'

# Requires for classes
require 'checkr/adverse_action'
require 'checkr/adverse_item'
require 'checkr/adverse_item_list'
require 'checkr/candidate'
require 'checkr/county_criminal_search'
require 'checkr/document'
Expand Down
23 changes: 23 additions & 0 deletions lib/checkr/adverse_action.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Checkr
class AdverseAction < APIResource
attribute :status
attribute :report_id
attribute :post_notice_scheduled_at
attribute :post_notice_ready_at
attribute :canceled_at
attribute :individualized_assessment_engaged
attribute :adverse_items, APIList.constructor(:AdverseItem)

api_class_method :create, :post, '/v1/reports/:report_id/adverse_actions'
api_class_method :retrieve, :get, ':path/:id', :arguments => [:id]
api_class_method :cancel, :delete, ':path/:id', :arguments => [:id]

api_instance_method :cancel, :delete

def self.path
'/v1/adverse_actions'
end

APIClass.register_subclass(self, 'adverse_action')
end
end
9 changes: 9 additions & 0 deletions lib/checkr/adverse_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Checkr
class AdverseItem < APIResource
attribute :text

api_class_method :all, :get, '/v1/reports/:report_id/adverse_items', :constructor => :AdverseItemList

APIClass.register_subclass(self, 'adverse_item')
end
end
24 changes: 24 additions & 0 deletions lib/checkr/adverse_item_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Checkr
class AdverseItemList < APIList

attribute :next_href
attribute :previous_href
attribute :count
attr_accessor :parent

api_instance_method :all, :get

def self.construct(json, parent=nil)
lambda = constructor(:AdverseItem)
instance = lambda.call(json)
instance.parent = parent if parent
instance.clear_changed_attributes
instance
end

def path
parent.path + '/adverse_items'
end

end
end
3 changes: 3 additions & 0 deletions lib/checkr/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class Report < APIResource
attribute :candidate, :Candidate
attribute_writer_alias :candidate_id, :candidate

attribute :adverse_items, :AdverseItemList, :nested => true, :default => {}
attribute_writer_alias :adverse_item_ids, :adverse_items

attribute :ssn_trace, :SSNTrace
attribute_writer_alias :ssn_trace_id, :ssn_trace

Expand Down
91 changes: 91 additions & 0 deletions test/checkr/adverse_action_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
require File.expand_path('../../test_helper', __FILE__)

module Checkr
class AdverseActionTest < Test::Unit::TestCase
setup do
@adverse_action_url = "#{Checkr.api_base}#{AdverseAction.path}"
end

should 'be registered' do
assert(APIClass.subclasses.include?(AdverseAction))
assert_equal(AdverseAction, APIClass.subclass_fetch('adverse_action'))
end

context 'Constructed AdverseAction instance' do
setup do
@adverse_action = AdverseAction.construct(test_adverse_action)
end

[
:id,
:object,
:uri,
:created_at,
:status,
:report_id,
:post_notice_scheduled_at,
:post_notice_ready_at,
:canceled_at,
:individualized_assessment_engaged,
].each do |attribute|
should "have the #{attribute.to_s} attribute" do
assert_equal(test_adverse_action[attribute], @adverse_action.public_send(attribute))
end
end
end

context '.create' do
setup do
@report = Report.construct(test_report)
@create_url = "#{Checkr.api_base}#{Report.path}/#{@report.id}/adverse_actions"
end

should 'creates an instance of AdverseAction' do
@mock.expects(:post).once.with(@create_url, anything, anything)
.returns(test_response(test_adverse_action))

adverse_action = AdverseAction.create({ :report_id => @report.id })

assert(adverse_action.is_a?(AdverseAction))
assert_equal(test_adverse_action[:id], adverse_action.id)
end
end

context '.retrieve' do
setup do
@id = test_adverse_action[:id]
@retrieve_url = "#{Checkr.api_base}#{AdverseAction.path}/#{@id}"
end

should 'fetches an instance of AdverseAction' do
@mock.expects(:get).once.with(@retrieve_url, anything, anything)
.returns(test_response(test_adverse_action))

adverse_action = AdverseAction.retrieve(@id)

assert(adverse_action.is_a?(AdverseAction))
assert_equal(@id, adverse_action.id)
end
end

context '#cancel/.cancel' do
setup do
@id = test_adverse_action[:id]
@cancel_url = "#{Checkr.api_base}#{AdverseAction.path}/#{@id}"
end

should 'cancels an instance of AdverseAction' do
@mock.expects(:delete).twice.with(@cancel_url, anything, anything)
.returns(test_response(test_adverse_action))

adverse_action = AdverseAction.cancel(@id)
assert(adverse_action.is_a?(AdverseAction))
assert_equal(@id, adverse_action.id)

adverse_action = AdverseAction.new(@id).cancel
assert(adverse_action.is_a?(AdverseAction))
assert_equal(@id, adverse_action.id)
end
end
end
end
49 changes: 49 additions & 0 deletions test/checkr/adverse_item_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require File.expand_path('../../test_helper', __FILE__)

module Checkr
class AdverseItemTest < Test::Unit::TestCase
setup do
@report = Report.construct(test_report)
@adverse_item_url = "#{Checkr.api_base}#{@report.path}/adverse_items"
end

context 'Constructed AdverseItem instance' do
setup do
@adverse_item = AdverseItem.construct(test_adverse_item)
end

[
:id,
:object,
:uri,
:created_at,
:text,
].each do |attribute|
should "have the #{attribute.to_s} attribute" do
assert_equal(test_adverse_item[attribute], @adverse_item.public_send(attribute))
end
end
end

context '.all' do
should 'return instances of AdverseItem' do
@mock.expects(:get).once.with do |url, params, opts|
url.start_with?(@adverse_item_url)
end.returns(test_response(test_adverse_item_list))

adverse_items = AdverseItem.all({ :report_id => @report.id })

assert(adverse_items.is_a?(AdverseItemList))
assert(adverse_items.length > 0)
adverse_items.each do |adverse_item|
assert(adverse_item.is_a?(AdverseItem))
end
end
end

should 'be registered' do
assert(APIClass.subclasses.include?(AdverseItem))
assert_equal(AdverseItem, APIClass.subclass_fetch('adverse_item'))
end
end
end
42 changes: 42 additions & 0 deletions test/test_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ def test_document
:type=>"driver_license",
:content_type=>"image/jpeg"}
end

def test_document_list
{
:object => 'list',
Expand All @@ -528,13 +529,54 @@ def test_verification
:verification_url=>"http://verifications.checkr.com/db313e73383710d4fa2f18fd",
:completed_at=>nil}
end

def test_verification_list
{
:object => 'list',
:data => [test_verification, test_verification, test_verification],
}
end

def test_adverse_item
{
:id => '71c0c2c79349c9f899bda22d3ccf60b7e0469266',
:object => 'adverse_item',
:text => 'License status: Suspended',
}
end

def test_adverse_item_list
{
:object => 'list',
:count => 2,
:data => [test_adverse_item, test_adverse_item],
}
end

def test_adverse_action
{
:id => '5d0af2cdfccff00034be49e9',
:object => 'adverse_action',
:uri => '/v1/adverse_actions/5d0af2cdfccff00034be49e9',
:created_at => '2019-06-20T02:43:25Z',
:status => 'pending',
:report_id => 'd36abda710bde8fd2c9d2587',
:post_notice_scheduled_at => '2019-06-27T02:43:25Z',
:post_notice_ready_at => '2019-06-27T02:43:25Z',
:canceled_at => nil,
:individualized_assessment_engaged => false,
:adverse_items => test_adverse_item_list,
}
end

def test_adverse_action_list
{
:object => 'list',
:count => 2,
:data => [test_adverse_action, test_adverse_action],
}
end

def test_education_verification
{:id => "5af5e030d24297006cce1e06",
:object => "education_verification",
Expand Down