@@ -710,40 +710,45 @@ describe('theme-fs', () => {
710710 test ( 'returns false if file is not in unsyncedFileKeys' , async ( ) => {
711711 // Given
712712 unsyncedFileKeys = new Set ( )
713- const handler = handleSyncUpdate ( unsyncedFileKeys , uploadErrors , fileKey , themeId , adminSession ) !
713+ const handler = handleSyncUpdate ( unsyncedFileKeys , uploadErrors , fileKey , themeId , adminSession )
714714
715715 // When
716- const result = await handler ( 'content' )
716+ const result = await handler ( { value : 'content' } )
717717
718718 // Then
719719 expect ( result ) . toBe ( false )
720720 expect ( bulkUploadThemeAssets ) . not . toHaveBeenCalled ( )
721721 expect ( triggerBrowserFullReload ) . not . toHaveBeenCalled ( )
722722 } )
723723
724- test ( 'uploads file and returns true on successful sync' , async ( ) => {
725- // Given
726- vi . mocked ( bulkUploadThemeAssets ) . mockResolvedValue ( [
727- {
728- key : fileKey ,
729- success : true ,
730- operation : Operation . Upload ,
731- } ,
732- ] )
733- const handler = handleSyncUpdate ( unsyncedFileKeys , uploadErrors , fileKey , themeId , adminSession ) !
734-
735- // When
736- const result = await handler ( 'content' )
737-
738- // Then
739- expect ( result ) . toBe ( true )
740- expect ( bulkUploadThemeAssets ) . toHaveBeenCalledWith (
741- Number ( themeId ) ,
742- [ { key : fileKey , value : 'content' } ] ,
743- adminSession ,
744- )
745- expect ( unsyncedFileKeys . has ( fileKey ) ) . toBe ( false )
746- expect ( triggerBrowserFullReload ) . not . toHaveBeenCalled ( )
724+ Object . entries ( {
725+ text : { value : 'content' } ,
726+ image : { attachment : 'content' } ,
727+ } ) . forEach ( ( [ fileType , fileContent ] ) => {
728+ test ( `uploads ${ fileType } file and returns true on successful sync` , async ( ) => {
729+ // Given
730+ vi . mocked ( bulkUploadThemeAssets ) . mockResolvedValue ( [
731+ {
732+ key : fileKey ,
733+ success : true ,
734+ operation : Operation . Upload ,
735+ } ,
736+ ] )
737+ const handler = handleSyncUpdate ( unsyncedFileKeys , uploadErrors , fileKey , themeId , adminSession )
738+
739+ // When
740+ const result = await handler ( fileContent )
741+
742+ // Then
743+ expect ( result ) . toBe ( true )
744+ expect ( bulkUploadThemeAssets ) . toHaveBeenCalledWith (
745+ Number ( themeId ) ,
746+ [ { key : fileKey , ...fileContent } ] ,
747+ adminSession ,
748+ )
749+ expect ( unsyncedFileKeys . has ( fileKey ) ) . toBe ( false )
750+ expect ( triggerBrowserFullReload ) . not . toHaveBeenCalled ( )
751+ } )
747752 } )
748753
749754 test ( 'throws error and sets uploadErrors on failed sync' , async ( ) => {
@@ -757,10 +762,10 @@ describe('theme-fs', () => {
757762 errors : { asset : errors } ,
758763 } ,
759764 ] )
760- const handler = handleSyncUpdate ( unsyncedFileKeys , uploadErrors , fileKey , themeId , adminSession ) !
765+ const handler = handleSyncUpdate ( unsyncedFileKeys , uploadErrors , fileKey , themeId , adminSession )
761766
762767 // When/Then
763- await expect ( handler ( 'content' ) ) . rejects . toThrow ( '{{ broken liquid file' )
768+ await expect ( handler ( { value : 'content' } ) ) . rejects . toThrow ( '{{ broken liquid file' )
764769 expect ( uploadErrors . get ( fileKey ) ) . toEqual ( errors )
765770 expect ( unsyncedFileKeys . has ( fileKey ) ) . toBe ( true )
766771 expect ( triggerBrowserFullReload ) . toHaveBeenCalledWith ( themeId , fileKey )
@@ -776,10 +781,10 @@ describe('theme-fs', () => {
776781 operation : Operation . Upload ,
777782 } ,
778783 ] )
779- const handler = handleSyncUpdate ( unsyncedFileKeys , uploadErrors , fileKey , themeId , adminSession ) !
784+ const handler = handleSyncUpdate ( unsyncedFileKeys , uploadErrors , fileKey , themeId , adminSession )
780785
781786 // When
782- await handler ( 'content' )
787+ await handler ( { value : 'content' } )
783788
784789 // Then
785790 expect ( uploadErrors . has ( fileKey ) ) . toBe ( false )
0 commit comments