@@ -197,6 +197,43 @@ Deno.test(
197
197
// Cleanup channel
198
198
await channel . unsubscribe ( )
199
199
} )
200
+
201
+ await t . step ( 'Storage - should upload and list file in bucket' , async ( ) => {
202
+ const bucket = 'test-bucket'
203
+ const filePath = 'test-file.txt'
204
+ const fileContent = new Blob ( [ 'Hello, Supabase Storage!' ] , { type : 'text/plain' } )
205
+
206
+ // use service_role key for bypass RLS
207
+ const SERVICE_ROLE_KEY =
208
+ Deno . env . get ( 'SUPABASE_SERVICE_ROLE_KEY' ) ||
209
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU'
210
+ const supabaseWithServiceRole = createClient ( SUPABASE_URL , SERVICE_ROLE_KEY , {
211
+ realtime : { heartbeatIntervalMs : 500 } ,
212
+ } )
213
+
214
+ // upload
215
+ const { data : uploadData , error : uploadError } = await supabaseWithServiceRole . storage
216
+ . from ( bucket )
217
+ . upload ( filePath , fileContent , { upsert : true } )
218
+ assertEquals ( uploadError , null )
219
+ assertExists ( uploadData )
220
+
221
+ // list
222
+ const { data : listData , error : listError } = await supabaseWithServiceRole . storage
223
+ . from ( bucket )
224
+ . list ( )
225
+ assertEquals ( listError , null )
226
+ assertEquals ( Array . isArray ( listData ) , true )
227
+ if ( ! listData ) throw new Error ( 'listData is null' )
228
+ const fileNames = listData . map ( ( f : any ) => f . name )
229
+ assertEquals ( fileNames . includes ( 'test-file.txt' ) , true )
230
+
231
+ // delete file
232
+ const { error : deleteError } = await supabaseWithServiceRole . storage
233
+ . from ( bucket )
234
+ . remove ( [ filePath ] )
235
+ assertEquals ( deleteError , null )
236
+ } )
200
237
} finally {
201
238
// Ensure cleanup runs even if tests fail
202
239
await cleanup ( )
0 commit comments