@@ -779,4 +779,91 @@ describe('Version Put', () => {
779779 const resp3 = await putVersion ( { } , { Body : 'hello' } ) ;
780780 assert . equal ( 500 , resp3 . status ) ;
781781 } ) ;
782+
783+ it ( 'Test putVersion preserves ContentType' , async ( ) => {
784+ const sentCommands = [ ] ;
785+ const mockS3Client = {
786+ async send ( cmd ) {
787+ sentCommands . push ( cmd ) ;
788+ return {
789+ $metadata : { httpStatusCode : 200 }
790+ } ;
791+ }
792+ } ;
793+
794+ const { putVersion } = await esmock ( '../../../src/storage/version/put.js' , {
795+ '../../../src/storage/utils/version.js' : {
796+ ifNoneMatch : ( ) => mockS3Client ,
797+ } ,
798+ } ) ;
799+
800+ const testParams = {
801+ Bucket : 'test-bucket' ,
802+ Org : 'test-org' ,
803+ Body : 'test content' ,
804+ ID : 'test-id' ,
805+ Version : 'test-version' ,
806+ Ext : 'html' ,
807+ Metadata : { test : 'metadata' } ,
808+ ContentLength : 12 ,
809+ ContentType : 'text/html'
810+ } ;
811+
812+ await putVersion ( { } , testParams ) ;
813+
814+ assert . strictEqual ( sentCommands . length , 1 ) ;
815+ const putCommand = sentCommands [ 0 ] ;
816+ assert . strictEqual ( putCommand . input . Bucket , 'test-bucket' ) ;
817+ assert . strictEqual ( putCommand . input . Key , 'test-org/.da-versions/test-id/test-version.html' ) ;
818+ assert . strictEqual ( putCommand . input . Body , 'test content' ) ;
819+ assert . strictEqual ( putCommand . input . ContentLength , 12 ) ;
820+ assert . strictEqual ( putCommand . input . ContentType , 'text/html' ) ;
821+ assert . deepStrictEqual ( putCommand . input . Metadata , { test : 'metadata' } ) ;
822+ } ) ;
823+
824+ it ( 'Test putObjectWithVersion passes ContentType to putVersion' , async ( ) => {
825+ const sentCommands = [ ] ;
826+ const mockS3Client = {
827+ async send ( cmd ) {
828+ sentCommands . push ( cmd ) ;
829+ return {
830+ $metadata : { httpStatusCode : 200 }
831+ } ;
832+ }
833+ } ;
834+
835+ const mockGetObject = async ( ) => ( {
836+ status : 200 ,
837+ body : 'test body' ,
838+ contentLength : 9 ,
839+ contentType : 'text/plain' ,
840+ metadata : { existing : 'metadata' }
841+ } ) ;
842+
843+ const { putObjectWithVersion } = await esmock ( '../../../src/storage/version/put.js' , {
844+ '../../../src/storage/object/get.js' : {
845+ default : mockGetObject
846+ } ,
847+ '../../../src/storage/utils/version.js' : {
848+ ifNoneMatch : ( ) => mockS3Client ,
849+ generateId : ( ) => 'generated-id' ,
850+ generateVersion : ( ) => 'generated-version'
851+ } ,
852+ } ) ;
853+
854+ const env = { } ;
855+ const daCtx = {
856+ org : 'test-org' ,
857+ ext : 'txt' ,
858+ users : [ { email : 'test@example.com' } ]
859+ } ;
860+
861+ await putObjectWithVersion ( env , daCtx , { key : 'test-file.txt' } , 'test body' , 'test-guid' ) ;
862+
863+ assert . strictEqual ( sentCommands . length , 1 ) ;
864+ const putCommand = sentCommands [ 0 ] ;
865+ assert . strictEqual ( putCommand . input . ContentType , 'text/plain' ) ;
866+ assert . strictEqual ( putCommand . input . Body , 'test body' ) ;
867+ assert . strictEqual ( putCommand . input . ContentLength , 9 ) ;
868+ } ) ;
782869} ) ;
0 commit comments