-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AdverseItem and AdverseAction Resources (#61)
Add AdverseItem and AdverseAction Resources
- Loading branch information
1 parent
9701f3f
commit 50a46d8
Showing
8 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters