File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,6 +43,27 @@ describe('imageUtils', () => {
4343 expect ( url ) . toBe ( 'https://public.url/file.png' ) ;
4444 } ) ;
4545
46+ it ( 'uses existing filename from fileUrl if provided' , async ( ) => {
47+ // Simulate providing an existing URL so the helper extracts the filename
48+ const existingUrl = 'https://xyz.supabase.co/storage/v1/object/public/images/folder/existing.png' ;
49+ storageMock . upload . mockResolvedValue ( { error : null } ) ;
50+ storageMock . getPublicUrl . mockReturnValue ( { data : { publicUrl : 'https://public.url/existing.png' } } ) ;
51+
52+ const url = await uploadImage (
53+ mockSupabase as SupabaseClient ,
54+ dummyFile ,
55+ 'folder' ,
56+ existingUrl
57+ ) ;
58+ // Should use filename 'existing.png' instead of generating with uuid
59+ expect ( storageMock . upload ) . toHaveBeenCalledWith (
60+ 'folder/existing.png' ,
61+ dummyFile . buffer ,
62+ { contentType : dummyFile . mimetype , upsert : true }
63+ ) ;
64+ expect ( url ) . toBe ( 'https://public.url/existing.png' ) ;
65+ } ) ;
66+
4667 it ( 'throws ApiError for missing mimetype' , async ( ) => {
4768 const badFile = { ...dummyFile , mimetype : '' } ;
4869 await expect (
You can’t perform that action at this time.
0 commit comments