@@ -67,28 +67,50 @@ class AlmaSruTest < ActiveSupport::TestCase
6767
6868 test 'lookup returns empty list for non-existent records' do
6969 output = StringIO . new
70+ original_logger = Rails . logger
7071 Rails . logger = Logger . new ( output )
7172
72- VCR . use_cassette ( 'alma sru nonexistent record' ) do
73- needle = 'alma9900000000006761'
73+ begin
74+ VCR . use_cassette ( 'alma sru nonexistent record' ) do
75+ needle = 'alma9900000000006761'
7476
75- result = AlmaSru . lookup ( needle )
77+ result = AlmaSru . lookup ( needle )
7678
77- assert_equal ( result , [ ] )
79+ assert_equal ( result , [ ] )
7880
79- # This condition gets logged for local investigation due to control field mismatch
80- assert_match ( 'Alma lookup failure: Control field mismatch' , output . string )
81+ # This condition gets logged for local investigation due to control field mismatch
82+ assert_match ( 'Alma lookup failure: Control field mismatch' , output . string )
83+ end
84+ ensure
85+ Rails . logger = original_logger
8186 end
8287 end
8388
84- test 'lookup returns nil if env not set' do
85- needle = '990002935920106761'
89+ test 'lookup returns empty list if alma URL not set' do
90+ needle = 'alma990014651640106761'
91+
92+ VCR . use_cassette ( 'alma sru single record' ) do
93+ assert_equal ( 1 , AlmaSru . lookup ( needle ) . length )
94+ end
95+
8696 ClimateControl . modify ( MIT_ALMA_URL : nil ) do
8797 assert_equal ( [ ] , AlmaSru . lookup ( needle ) )
8898 end
8999 end
90100
91- test 'lookup returns nil with non-complying ID' do
101+ test 'lookup returns empty list if exl_inst_id not set' do
102+ needle = 'alma990014651640106761'
103+
104+ VCR . use_cassette ( 'alma sru single record' ) do
105+ assert_equal ( 1 , AlmaSru . lookup ( needle ) . length )
106+ end
107+
108+ ClimateControl . modify ( EXL_INST_ID : nil ) do
109+ assert_equal ( [ ] , AlmaSru . lookup ( needle ) )
110+ end
111+ end
112+
113+ test 'lookup returns empty list with non-complying ID' do
92114 needle = 'foo'
93115
94116 result = AlmaSru . lookup ( needle )
@@ -99,34 +121,44 @@ class AlmaSruTest < ActiveSupport::TestCase
99121 test 'lookup survives failing to connect to Alma SRU' do
100122 alma_client = AlmaConnectionError . new
101123 output = StringIO . new
124+ original_logger = Rails . logger
102125 Rails . logger = Logger . new ( output )
103126
104127 needle = 'alma990014651640106761'
105128
106- assert_nothing_raised do
107- result = AlmaSru . lookup ( needle , alma_client : alma_client )
129+ begin
130+ assert_nothing_raised do
131+ result = AlmaSru . lookup ( needle , alma_client : alma_client )
108132
109- assert_equal ( [ ] , result )
133+ assert_equal ( [ ] , result )
110134
111- # This condition gets logged for local investigation
112- assert_match ( 'Alma SRU connection error' , output . string )
135+ # This condition gets logged for local investigation
136+ assert_match ( 'Alma SRU connection error' , output . string )
137+ end
138+ ensure
139+ Rails . logger = original_logger
113140 end
114141 end
115142
116143 test 'lookup survives Alma SRU errors' do
117144 alma_client = AlmaErrorResponse . new
118145 output = StringIO . new
146+ original_logger = Rails . logger
119147 Rails . logger = Logger . new ( output )
120148
121149 needle = 'alma990014651640106761'
122150
123- assert_nothing_raised do
124- result = AlmaSru . lookup ( needle , alma_client : alma_client )
151+ begin
152+ assert_nothing_raised do
153+ result = AlmaSru . lookup ( needle , alma_client : alma_client )
125154
126- assert_equal ( result , [ ] )
155+ assert_equal ( result , [ ] )
127156
128- # This condition gets logged for local investigation
129- assert_match ( 'Alma lookup failure: 500' , output . string )
157+ # This condition gets logged for local investigation
158+ assert_match ( 'Alma lookup failure: 500' , output . string )
159+ end
160+ ensure
161+ Rails . logger = original_logger
130162 end
131163 end
132164
0 commit comments