From 67c08b3b8f4b294b3e3a22a9c2eeb2b31475f89b Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Wed, 1 May 2024 16:38:37 -0700 Subject: [PATCH] [i769] Don't include retirees in list of ineligible patrons for Alma --- app/models/alma_people/alma_person_feed.rb | 16 ++++++--- app/models/alma_people/alma_xml_person.rb | 15 ++++++++ .../alma_people/alma_person_feed_spec.rb | 29 ++++++++++++++++ .../alma_people/alma_xml_person_spec.rb | 34 +++++++++++++++++++ 4 files changed, 90 insertions(+), 4 deletions(-) diff --git a/app/models/alma_people/alma_person_feed.rb b/app/models/alma_people/alma_person_feed.rb index 0baaa391..37cf10d6 100644 --- a/app/models/alma_people/alma_person_feed.rb +++ b/app/models/alma_people/alma_person_feed.rb @@ -14,10 +14,13 @@ def initialize(oit_person_feed: AlmaPeople::OitPersonFeed.new, begin_date: 1.day @enabled_flag = enabled_flag @ineligible_flag = 'I' @invalid_records = [] + @ineligible_count = 0 end private + attr_reader :ineligible_count + def handle(data_set:) data_set.report_time = Time.zone.now.midnight oit_people = oit_person_feed.get_json(begin_date:, end_date:, enabled_flag:) @@ -36,7 +39,7 @@ def build_xml(oit_people:, eligibility:) builder = Nokogiri::XML::Builder.new do |xml| xml.users do oit_people.each do |person| - convert_person_to_xml(xml:, person:) + convert_person_to_xml(xml:, person:, eligibility:) end end end @@ -61,10 +64,11 @@ def transfer_alma_person_file(filename:) report_uploader.run end - def convert_person_to_xml(xml:, person:) + def convert_person_to_xml(xml:, person:, eligibility:) alma_person = AlmaPeople::AlmaXmlPerson.new(xml:, person:) - if alma_person.valid? + if alma_person.valid? && alma_person.should_be_included? alma_person.convert + handle_ineligible_patron_converted if eligibility == 'I' else @invalid_records << alma_person end @@ -80,7 +84,11 @@ def ineligible_user oit_people_ineligible = oit_person_feed.get_json(begin_date:, end_date:, enabled_flag: @ineligible_flag) full_path = build_xml(oit_people: oit_people_ineligible, eligibility: @ineligible_flag) transfer_alma_person_file(filename: full_path) - ", ineligible_people_updated: #{oit_people_ineligible.count}, file: #{File.basename(full_path)}" + ", ineligible_people_updated: #{ineligible_count}, file: #{File.basename(full_path)}" + end + + def handle_ineligible_patron_converted + @ineligible_count = ineligible_count + 1 end end end diff --git a/app/models/alma_people/alma_xml_person.rb b/app/models/alma_people/alma_xml_person.rb index c6231ec3..6f983a51 100644 --- a/app/models/alma_people/alma_xml_person.rb +++ b/app/models/alma_people/alma_xml_person.rb @@ -38,6 +38,13 @@ def convert end end + # #should_be_included? checks to make sure the person meets + # our business logic rules. This is different than #valid?, + # which checks to make sure the data about the person is correct + def should_be_included? + eligible? || not_a_retiree? + end + private def create_status(status_flag:) @@ -138,6 +145,14 @@ def create_address(type:, preferred:, line1:, line2:, line3:, line4:, city:, sta end # rubocop:enable Metrics/ParameterLists # rubocop:enable Metrics/MethodLength + + def eligible? + person["ELIGIBLE_INELIGIBLE"] == 'E' + end + + def not_a_retiree? + person["VCURSTATUS"] != 'RETR' + end end end # rubocop:enable Metrics/AbcSize diff --git a/spec/models/alma_people/alma_person_feed_spec.rb b/spec/models/alma_people/alma_person_feed_spec.rb index 411d6b86..182e77eb 100644 --- a/spec/models/alma_people/alma_person_feed_spec.rb +++ b/spec/models/alma_people/alma_person_feed_spec.rb @@ -141,6 +141,35 @@ data = File.read("spec/fixtures/person_feed/alma_people_#{yesterday}_#{today}_I.xml") expect(validate_xml(data)).to be_truthy end + + context 'when the person is a retiree' do + let(:oit_ineligible_people) do + [{ "VCURAFFIL" => "EM", + "VCURGROUP" => "DF", + "VCURSTATUS" => "RETR", + "UG_CLASS_YEAR" => nil, + "VCLASS" => "N/A", + "VTITLE" => "Emeritus.", + "BEMERITUS" => "FEMER", + "VJOBFUNCTION" => "FR", + "PRF_OR_PRI_FIRST_NAM" => "Retiree", + "PATRON_EXPIRATION_DATE" => "2022-10-31", + "ELIGIBLE_INELIGIBLE" => "I", + "EMPLOYEE_TYPE" => "eme" }, + { "PRF_OR_PRI_FIRST_NAM" => "NotRetired", + "PATRON_EXPIRATION_DATE" => "2022-10-31", + "ELIGIBLE_INELIGIBLE" => "I" }] + end + it('does not include them in the list we send to alma, so they do not lose their privileges') do + expect(alma_person_feed.run).to be_truthy + data_set = DataSet.last + expect(data_set.data).to eq("people_updated: 1, file: alma_people_#{yesterday}_#{today}_E.xml, ineligible_people_updated: 1, file: alma_people_#{yesterday}_#{today}_I.xml") + data = File.read("spec/fixtures/person_feed/alma_people_#{yesterday}_#{today}_I.xml") + expect(validate_xml(data)).to be_truthy + expect(data).to include 'NotRetired' + expect(data).not_to include 'Retiree' + end + end end end diff --git a/spec/models/alma_people/alma_xml_person_spec.rb b/spec/models/alma_people/alma_xml_person_spec.rb index 7666defb..113c9a04 100644 --- a/spec/models/alma_people/alma_xml_person_spec.rb +++ b/spec/models/alma_people/alma_xml_person_spec.rb @@ -151,5 +151,39 @@ end end end + + describe('#should_be_included?') do + end + context 'for a typical Ineligible patron' do + let(:oit_person) do + JSON.parse('{ + "VCURSTATUS": "ACTV", + "ELIGIBLE_INELIGIBLE": "I", + "PATRON_EXPIRATION_DATE": "2024-01-01" + }') + end + it 'returns true' do + Nokogiri::XML::Builder.new do |xml| + alma_person = described_class.new(xml:, person: oit_person) + expect(alma_person.should_be_included?).to eq(true) + end + end + end + + context 'when an otherwise Ineligible patron is a retiree and thus gets borrowing privileges' do + let(:oit_person) do + JSON.parse('{ + "VCURSTATUS": "RETR", + "ELIGIBLE_INELIGIBLE": "I", + "PATRON_EXPIRATION_DATE": "2024-01-01" + }') + end + it 'returns false' do + Nokogiri::XML::Builder.new do |xml| + alma_person = described_class.new(xml:, person: oit_person) + expect(alma_person.should_be_included?).to eq(false) + end + end + end end end