diff --git a/app/models/normalize_primo_record.rb b/app/models/normalize_primo_record.rb index e277451e..7def2380 100644 --- a/app/models/normalize_primo_record.rb +++ b/app/models/normalize_primo_record.rb @@ -131,6 +131,14 @@ def links end end + # Add Full-text options if pnx['links'] is nil and record has Alma-E (electronic availability) + full_record_link = record_link + if @record.dig('pnx', 'links').nil? && + @record.dig('delivery', 'deliveryCategory')&.include?('Alma-E') && + full_record_link.present? + links << { 'url' => "#{full_record_link}#nui.getit.service_viewit", 'kind' => 'Full-text options' } + end + # Return links if we found any links.any? ? links : [] end @@ -327,8 +335,8 @@ def score # FRBR Group check based on: # https://knowledge.exlibrisgroup.com/Primo/Knowledge_Articles/Primo_Search_API_-_how_to_get_FRBR_Group_members_after_a_search def frbrized? - return unless @record['pnx']['facets'] - return unless @record['pnx']['facets']['frbrtype'] + return false unless @record['pnx']['facets'] + return false unless @record['pnx']['facets']['frbrtype'] @record['pnx']['facets']['frbrtype'].join == '5' end diff --git a/test/models/normalize_primo_record_test.rb b/test/models/normalize_primo_record_test.rb index 96f42e79..090c22a0 100644 --- a/test/models/normalize_primo_record_test.rb +++ b/test/models/normalize_primo_record_test.rb @@ -458,6 +458,60 @@ def cdi_record assert_not normalized[:dedup_record] end + test 'includes Full-text options link when pnx[links] is nil and both Alma-P and Alma-E present' do + record = alma_record.deep_dup + + # Ensure no direct links + record['pnx']['links'] = nil + + # Add delivery category with both physical and electronic + record['delivery']['deliveryCategory'] = %w[Alma-P Alma-E] + normalized = NormalizePrimoRecord.new(record, 'test').normalize + full_text_link = normalized[:links].find { |link| link['kind'] == 'Full-text options' } + assert_not_nil full_text_link + assert_match %r{/discovery/fulldisplay\?}, full_text_link['url'] + assert_match(/#nui\.getit\.service_viewit$/, full_text_link['url']) + end + + test 'excludes Full-text options link when pnx[links] is present' do + record = full_record.deep_dup + + # Add delivery category with electronic + record['delivery']['deliveryCategory'] = %w[Alma-E] + normalized = NormalizePrimoRecord.new(record, 'test').normalize + full_text_link = normalized[:links].find { |link| link['kind'] == 'Full-text options' } + assert_nil full_text_link + end + + test 'excludes Full-text options link when only Alma-P present' do + record = alma_record.deep_dup + record['pnx']['links'] = nil + record['delivery']['deliveryCategory'] = ['Alma-P'] + normalized = NormalizePrimoRecord.new(record, 'test').normalize + full_text_link = normalized[:links].find { |link| link['kind'] == 'Full-text options' } + assert_nil full_text_link + end + + test 'includes Full-text options link when only Alma-E present' do + record = alma_record.deep_dup + record['pnx']['links'] = nil + record['delivery']['deliveryCategory'] = ['Alma-E'] + normalized = NormalizePrimoRecord.new(record, 'test').normalize + full_text_link = normalized[:links].find { |link| link['kind'] == 'Full-text options' } + assert_not_nil full_text_link + assert_match %r{/discovery/fulldisplay\?}, full_text_link['url'] + assert_match(/#nui\.getit\.service_viewit$/, full_text_link['url']) + end + + test 'excludes Full-text options link when no delivery category present' do + record = alma_record.deep_dup + record['pnx']['links'] = nil + record['delivery']['deliveryCategory'] = nil + normalized = NormalizePrimoRecord.new(record, 'test').normalize + full_text_link = normalized[:links].find { |link| link['kind'] == 'Full-text options' } + assert_nil full_text_link + end + test 'dedup_url requires both frbrized and alma_record conditions' do # CDI record that is frbrized - should return nil normalizer = NormalizePrimoRecord.new(cdi_record, 'test')