|
| 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 |
0 commit comments