Skip to content

Commit

Permalink
Merge pull request #40 from checkr/g/verifications
Browse files Browse the repository at this point in the history
Add Verification
  • Loading branch information
jperichon authored Jan 30, 2018
2 parents e8a3e50 + 0914363 commit 0e84fdd
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v1.5.0 (2018-02-2)

Features:

- Add Verification

## v1.4.0 (2018-01-24)

Features:
Expand Down
2 changes: 2 additions & 0 deletions lib/checkr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
require 'checkr/sex_offender_search'
require 'checkr/ssn_trace'
require 'checkr/subscription'
require 'checkr/verification'
require 'checkr/verification_list'

# Errors
require 'checkr/errors/checkr_error'
Expand Down
3 changes: 3 additions & 0 deletions lib/checkr/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Report < APIResource
attribute :documents, APIList.constructor(:Document)
attribute_writer_alias :document_ids, :documents

attribute :verifications, :VerificationList, :nested => true, :default => {}
attribute_writer_alias :verification_ids, :verifications

api_class_method :retrieve, :get, ":path/:id", :arguments => [:id]
api_class_method :create, :post

Expand Down
12 changes: 12 additions & 0 deletions lib/checkr/verification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Checkr
class Verification < APIResource

attribute :verification_type
attribute :verification_url
attribute :completed_at

api_class_method :all, :get, "/v1/reports/:report_id/verifications", :constructor => :VerificationList

APIClass.register_subclass(self, "verification")
end
end
24 changes: 24 additions & 0 deletions lib/checkr/verification_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Checkr
class VerificationList < 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(:Verification)
instance = lambda.call(json)
instance.parent = parent if parent
instance.clear_changed_attributes
instance
end

def path
parent.path + "/verifications"
end

end
end
2 changes: 1 addition & 1 deletion lib/checkr/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Checkr
VERSION = '1.4.0'.freeze
VERSION = '1.5.0'.freeze
end
25 changes: 25 additions & 0 deletions test/checkr/verification_list_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require File.expand_path('../../test_helper', __FILE__)

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

context 'VerificationList class' do
should 'be listable' do
@mock.expects(:get).once.with(@verification_url, anything, anything).returns(test_response(test_verification_list))

verifications = @report.verifications.all

assert(verifications.is_a?(VerificationList))
verifications.each do |document|
assert(document.is_a?(Verification))
end
assert(verifications.length > 0)
end
end

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

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

context 'Constructed Verification instance' do
setup do
@verification = Verification.construct(test_verification)
end

should 'have the id attribute' do
assert_equal(test_verification[:id], @verification.id)
end

should 'have the object attribute' do
assert_equal(test_verification[:object], @verification.object)
end

should 'have the uri attribute' do
assert_equal(test_verification[:uri], @verification.uri)
end

should 'have the created_at attribute' do
assert_equal(test_verification[:created_at], @verification.created_at)
end

should 'have the completed_at attribute' do
assert_equal(test_verification[:completed_at], @verification.completed_at)
end

should 'have the verification_type attribute' do
assert_equal(test_verification[:verification_type], @verification.verification_type)
end

should 'have the verification_url attribute' do
assert_equal(test_verification[:verification_url], @verification.verification_url)
end
end

context '#all' do
should 'return instances of Verification' do
@mock.expects(:get).once.with(@verification_url, anything, anything)
.returns(test_response(test_verification_list))
assert_equal(@report.verifications.all.first.class, Verification)
end
end

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

end
end
15 changes: 15 additions & 0 deletions test/test_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,21 @@ def test_document_list
}
end

def test_verification
{:id=>"db313e73383710d4fa2f18fd",
:object=>"verification",
:created_at=>"2015-02-11T20:01:50Z",
:verification_type=>"id",
: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

# Errors
def test_api_error
{
Expand Down

0 comments on commit 0e84fdd

Please sign in to comment.