@@ -3218,6 +3218,62 @@ describe('Strict MODS Conversion', () => {
32183218 'Should not have direct title under relatedItem' )
32193219 } )
32203220
3221+ it ( 'should deduplicate internetMediaType in physicalDescription' , ( ) => {
3222+ const input = `<xml><mods>
3223+ <titleInfo><title>Test</title></titleInfo>
3224+ <physicalDescription>
3225+ <internetMediaType>image/tiff</internetMediaType>
3226+ <internetMediaType>image/jpeg</internetMediaType>
3227+ <internetMediaType>image/tiff</internetMediaType>
3228+ <internetMediaType>image/jpeg</internetMediaType>
3229+ <digitalOrigin>reformatted digital</digitalOrigin>
3230+ </physicalDescription>
3231+ </mods></xml>`
3232+ const result = toStrictMODS ( input )
3233+
3234+ // Should only have one of each type
3235+ const tiffMatches = result . match ( / < i n t e r n e t M e d i a T y p e > i m a g e \/ t i f f < \/ i n t e r n e t M e d i a T y p e > / g) || [ ]
3236+ const jpegMatches = result . match ( / < i n t e r n e t M e d i a T y p e > i m a g e \/ j p e g < \/ i n t e r n e t M e d i a T y p e > / g) || [ ]
3237+
3238+ assert . strictEqual ( tiffMatches . length , 1 , 'Should have exactly one image/tiff' )
3239+ assert . strictEqual ( jpegMatches . length , 1 , 'Should have exactly one image/jpeg' )
3240+ } )
3241+
3242+ it ( 'should deduplicate internetMediaType while preserving order' , ( ) => {
3243+ const input = `<xml><mods>
3244+ <titleInfo><title>Test</title></titleInfo>
3245+ <physicalDescription>
3246+ <internetMediaType>image/tiff</internetMediaType>
3247+ <internetMediaType>image/jpeg</internetMediaType>
3248+ <internetMediaType>application/pdf</internetMediaType>
3249+ <internetMediaType>image/tiff</internetMediaType>
3250+ <internetMediaType>image/jpeg</internetMediaType>
3251+ </physicalDescription>
3252+ </mods></xml>`
3253+ const result = toStrictMODS ( input )
3254+
3255+ // Should have each type once, in order of first appearance
3256+ const types = [ ...result . matchAll ( / < i n t e r n e t M e d i a T y p e > ( .* ?) < \/ i n t e r n e t M e d i a T y p e > / g) ] . map ( m => m [ 1 ] )
3257+
3258+ assert . deepStrictEqual ( types , [ 'image/tiff' , 'image/jpeg' , 'application/pdf' ] ,
3259+ 'Should preserve order of first appearance' )
3260+ } )
3261+
3262+ it ( 'should handle physicalDescription with no internetMediaType' , ( ) => {
3263+ const input = `<xml><mods>
3264+ <titleInfo><title>Test</title></titleInfo>
3265+ <physicalDescription>
3266+ <digitalOrigin>born digital</digitalOrigin>
3267+ <extent>10 pages</extent>
3268+ </physicalDescription>
3269+ </mods></xml>`
3270+ const result = toStrictMODS ( input )
3271+
3272+ assert . ok ( result . includes ( '<digitalOrigin>born digital</digitalOrigin>' ) , 'Should preserve digitalOrigin' )
3273+ assert . ok ( result . includes ( '<extent>10 pages</extent>' ) , 'Should preserve extent' )
3274+ } )
3275+
3276+
32213277 it ( 'should move formBroad and formSpecific to genre' , ( ) => {
32223278 const input = `<xml><mods>
32233279 <titleInfo><title>Test Item</title></titleInfo>
0 commit comments