From 091436339c4a1c1b1e88ce281e69f9751fac511f Mon Sep 17 00:00:00 2001 From: Geoffrey Tisserand Date: Mon, 29 Jan 2018 11:25:19 -0800 Subject: [PATCH] Add Verification --- Changelog.md | 6 +++ lib/checkr.rb | 2 + lib/checkr/report.rb | 3 ++ lib/checkr/verification.rb | 12 ++++++ lib/checkr/verification_list.rb | 24 +++++++++++ lib/checkr/version.rb | 2 +- test/checkr/verification_list_test.rb | 25 ++++++++++++ test/checkr/verifications_test.rb | 58 +++++++++++++++++++++++++++ test/test_data.rb | 15 +++++++ 9 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 lib/checkr/verification.rb create mode 100644 lib/checkr/verification_list.rb create mode 100644 test/checkr/verification_list_test.rb create mode 100644 test/checkr/verifications_test.rb diff --git a/Changelog.md b/Changelog.md index 3ffbc36..70c1ac7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,9 @@ +## v1.5.0 (2018-02-2) + +Features: + +- Add Verification + ## v1.4.0 (2018-01-24) Features: diff --git a/lib/checkr.rb b/lib/checkr.rb index 9e8f72c..c05fe07 100644 --- a/lib/checkr.rb +++ b/lib/checkr.rb @@ -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' diff --git a/lib/checkr/report.rb b/lib/checkr/report.rb index 325e63e..b3a6397 100644 --- a/lib/checkr/report.rb +++ b/lib/checkr/report.rb @@ -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 diff --git a/lib/checkr/verification.rb b/lib/checkr/verification.rb new file mode 100644 index 0000000..b887682 --- /dev/null +++ b/lib/checkr/verification.rb @@ -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 diff --git a/lib/checkr/verification_list.rb b/lib/checkr/verification_list.rb new file mode 100644 index 0000000..0391d07 --- /dev/null +++ b/lib/checkr/verification_list.rb @@ -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 diff --git a/lib/checkr/version.rb b/lib/checkr/version.rb index 6ebc4b6..2a9d838 100644 --- a/lib/checkr/version.rb +++ b/lib/checkr/version.rb @@ -1,3 +1,3 @@ module Checkr - VERSION = '1.4.0'.freeze + VERSION = '1.5.0'.freeze end diff --git a/test/checkr/verification_list_test.rb b/test/checkr/verification_list_test.rb new file mode 100644 index 0000000..7e2c22a --- /dev/null +++ b/test/checkr/verification_list_test.rb @@ -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 diff --git a/test/checkr/verifications_test.rb b/test/checkr/verifications_test.rb new file mode 100644 index 0000000..5710b1c --- /dev/null +++ b/test/checkr/verifications_test.rb @@ -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 diff --git a/test/test_data.rb b/test/test_data.rb index 8fe52a4..19fa30a 100644 --- a/test/test_data.rb +++ b/test/test_data.rb @@ -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 {