@@ -73,14 +73,29 @@ def cdi_record
7373 assert_equal 'full record' , normalized [ :links ] . first [ 'kind' ]
7474
7575 # Second link should be the Alma openurl
76- assert_equal 'openurl ' , normalized [ :links ] . second [ 'kind' ]
76+ assert_equal 'Check Availability ' , normalized [ :links ] . second [ 'kind' ]
7777 end
7878
7979 test 'handles missing links' do
8080 normalized = NormalizePrimoRecord . new ( minimal_record , 'test' ) . normalize
8181 assert_empty normalized [ :links ]
8282 end
8383
84+ test 'parse_link_string creates expected data structure' do
85+ # Strings that don't start with $$ should not be processed
86+ link_string = 'https://example.com?param1=value1¶m2=value2'
87+ assert_nil NormalizePrimoRecord . new ( full_record , 'test' ) . send ( :parse_link_string , link_string )
88+
89+ # Extract properly formatted links
90+ link_string = '$$Uhttps://libproxy.mit.edu/login?&url=https://www.jstor.org/stable/pdf/20464433$$EPDF$$P50$$Gjstor$$H'
91+ expected = { 'U' => 'https://libproxy.mit.edu/login?&url=https://www.jstor.org/stable/pdf/20464433' , 'E' => 'PDF' , 'P' => '50' , 'G' => 'jstor' , 'H' => '' }
92+ assert_equal expected , NormalizePrimoRecord . new ( full_record , 'test' ) . send ( :parse_link_string , link_string )
93+
94+ link_string = '$$Uhttps://libproxy.mit.edu/login?&url=https://www.jstor.org/stable/20464433$$EHTML$$P50$$Gjstor$$H'
95+ expected = { 'U' => 'https://libproxy.mit.edu/login?&url=https://www.jstor.org/stable/20464433' , 'E' => 'HTML' , 'P' => '50' , 'G' => 'jstor' , 'H' => '' }
96+ assert_equal expected , NormalizePrimoRecord . new ( full_record , 'test' ) . send ( :parse_link_string , link_string )
97+ end
98+
8499 test 'normalizes citation for cdi records' do
85100 record = full_record . dup
86101 record [ 'pnx' ] [ 'control' ] [ 'recordid' ] = [ 'cdi_crossref_primary_10_1234_test_article' ]
@@ -286,8 +301,10 @@ def cdi_record
286301 link_kinds = normalized [ :links ] . map { |link | link [ 'kind' ] }
287302
288303 assert_includes link_kinds , 'full record'
289- assert_includes link_kinds , 'openurl'
290- assert_equal 2 , normalized [ :links ] . length # Only full record and openurl
304+ assert_includes link_kinds , 'Check Availability'
305+ assert_includes link_kinds , 'View PDF'
306+ assert_includes link_kinds , 'View HTML'
307+ assert_equal 4 , normalized [ :links ] . length
291308 end
292309
293310 # Additional coverage tests for existing methods
@@ -359,14 +376,14 @@ def cdi_record
359376 test 'handles openurl server validation' do
360377 # Test with matching server
361378 normalized = NormalizePrimoRecord . new ( full_record , 'test' ) . normalize
362- openurl_link = normalized [ :links ] . find { |link | link [ 'kind' ] == 'openurl ' }
379+ openurl_link = normalized [ :links ] . find { |link | link [ 'kind' ] == 'Check Availability ' }
363380 assert_not_nil openurl_link
364381
365382 # Test with mismatched server. Should log warning but still return URL
366383 record = full_record . deep_dup
367384 record [ 'delivery' ] [ 'almaOpenurl' ] = 'https://different.server.com/openurl?param=value'
368385 normalized = NormalizePrimoRecord . new ( record , 'test' ) . normalize
369- openurl_link = normalized [ :links ] . find { |link | link [ 'kind' ] == 'openurl ' }
386+ openurl_link = normalized [ :links ] . find { |link | link [ 'kind' ] == 'Check Availability ' }
370387 assert_not_nil openurl_link
371388 end
372389
0 commit comments