@@ -12,6 +12,14 @@ def minimal_record
1212 JSON . parse ( File . read ( Rails . root . join ( 'test/fixtures/primo/minimal_record.json' ) ) )
1313 end
1414
15+ def alma_record
16+ JSON . parse ( File . read ( Rails . root . join ( 'test/fixtures/primo/alma_record.json' ) ) )
17+ end
18+
19+ def cdi_record
20+ JSON . parse ( File . read ( Rails . root . join ( 'test/fixtures/primo/cdi_record.json' ) ) )
21+ end
22+
1523 test 'normalizes title' do
1624 normalized = NormalizePrimoRecord . new ( full_record , 'test' ) . normalize
1725 assert_equal 'Testing the Limits of Knowledge' , normalized [ 'title' ]
@@ -95,7 +103,7 @@ def minimal_record
95103
96104 test 'normalizes identifier' do
97105 normalized = NormalizePrimoRecord . new ( full_record , 'test' ) . normalize
98- assert_equal 'MIT01000000001 ' , normalized [ 'identifier' ]
106+ assert_equal 'alma991000000001234567 ' , normalized [ 'identifier' ]
99107 end
100108
101109 test 'normalizes summary' do
@@ -328,4 +336,91 @@ def minimal_record
328336 openurl_link = normalized [ 'links' ] . find { |link | link [ 'kind' ] == 'openurl' }
329337 assert_not_nil openurl_link
330338 end
339+
340+ test 'identifies Alma records correctly' do
341+ normalizer = NormalizePrimoRecord . new ( alma_record , 'test' )
342+ assert normalizer . send ( :alma_record? )
343+ end
344+
345+ test 'identifies CDI records correctly' do
346+ normalizer = NormalizePrimoRecord . new ( cdi_record , 'test' )
347+ assert_not normalizer . send ( :alma_record? )
348+ end
349+
350+ test 'handles missing record ID for alma_record? check' do
351+ record = minimal_record . deep_dup
352+ normalizer = NormalizePrimoRecord . new ( record , 'test' )
353+ assert_not normalizer . send ( :alma_record? )
354+ end
355+
356+ test 'generates FRBR dedup URL for Alma records when frbrized' do
357+ normalized = NormalizePrimoRecord . new ( alma_record , 'test query' ) . normalize
358+ full_record_link = normalized [ 'links' ] . find { |link | link [ 'kind' ] == 'full record' }
359+ assert_not_nil full_record_link
360+
361+ # Should use dedup URL for Alma records
362+ assert_match 'frbrgroupid' , full_record_link [ 'url' ]
363+ assert_match 'alma12345' , full_record_link [ 'url' ]
364+ end
365+
366+ test 'does not generate FRBR dedup URL for CDI records even when frbrized' do
367+ normalized = NormalizePrimoRecord . new ( cdi_record , 'test query' ) . normalize
368+ full_record_link = normalized [ 'links' ] . find { |link | link [ 'kind' ] == 'full record' }
369+ assert_not_nil full_record_link
370+
371+ # Should use regular record link for CDI records, not dedup URL
372+ assert_match %r{/discovery/fulldisplay\? } , full_record_link [ 'url' ]
373+ assert_no_match 'frbrgroupid' , full_record_link [ 'url' ]
374+ end
375+
376+ test 'falls back to regular record link for Alma records without FRBR data' do
377+ record = alma_record . deep_dup
378+ record [ 'pnx' ] [ 'facets' ] [ 'frbrtype' ] = [ '3' ] # Not frbrized
379+
380+ normalized = NormalizePrimoRecord . new ( record , 'test' ) . normalize
381+ full_record_link = normalized [ 'links' ] . find { |link | link [ 'kind' ] == 'full record' }
382+ assert_not_nil full_record_link
383+
384+ # Should use regular record link when not frbrized
385+ assert_match %r{/discovery/fulldisplay\? } , full_record_link [ 'url' ]
386+ assert_no_match 'frbrgroupid' , full_record_link [ 'url' ]
387+ end
388+
389+ test 'frbrized? method works correctly' do
390+ # Frbrized Alma record
391+ normalizer = NormalizePrimoRecord . new ( alma_record , 'test' )
392+ assert normalizer . send ( :frbrized? )
393+
394+ # Frbrized CDI record
395+ normalizer = NormalizePrimoRecord . new ( cdi_record , 'test' )
396+ assert normalizer . send ( :frbrized? )
397+
398+ # Non-frbrized record
399+ record = alma_record . deep_dup
400+ record [ 'pnx' ] [ 'facets' ] [ 'frbrtype' ] = [ '3' ]
401+ normalizer = NormalizePrimoRecord . new ( record , 'test' )
402+ assert_not normalizer . send ( :frbrized? )
403+
404+ # Missing FRBR data
405+ normalizer = NormalizePrimoRecord . new ( minimal_record , 'test' )
406+ assert_not normalizer . send ( :frbrized? )
407+ end
408+
409+ test 'dedup_url requires both frbrized and alma_record conditions' do
410+ # CDI record that is frbrized - should return nil
411+ normalizer = NormalizePrimoRecord . new ( cdi_record , 'test' )
412+ assert_nil normalizer . send ( :dedup_url )
413+
414+ # Alma record that is not frbrized - should return nil
415+ record = alma_record . deep_dup
416+ record [ 'pnx' ] [ 'facets' ] [ 'frbrtype' ] = [ '3' ]
417+ normalizer = NormalizePrimoRecord . new ( record , 'test' )
418+ assert_nil normalizer . send ( :dedup_url )
419+
420+ # Test Alma record that is frbrized - should return URL
421+ normalizer = NormalizePrimoRecord . new ( alma_record , 'test' )
422+ dedup_url = normalizer . send ( :dedup_url )
423+ assert_not_nil dedup_url
424+ assert_match %r{/discovery/search\? } , dedup_url
425+ end
331426end
0 commit comments