@@ -2,16 +2,16 @@ import { createClient, RealtimeChannel, SupabaseClient } from '../src/index'
22
33// These tests assume that a local Supabase server is already running
44// Start a local Supabase instance with 'supabase start' before running these tests
5- describe ( 'Supabase Integration Tests' , ( ) => {
6- // Default local dev credentials from Supabase CLI
7- const SUPABASE_URL = 'http://127.0.0.1:54321'
8- const ANON_KEY =
9- 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'
5+ // Default local dev credentials from Supabase CLI
6+ const SUPABASE_URL = 'http://127.0.0.1:54321'
7+ const ANON_KEY =
8+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'
109
11- const supabase = createClient ( SUPABASE_URL , ANON_KEY , {
12- realtime : { heartbeatIntervalMs : 500 } ,
13- } )
10+ const supabase = createClient ( SUPABASE_URL , ANON_KEY , {
11+ realtime : { heartbeatIntervalMs : 500 } ,
12+ } )
1413
14+ describe ( 'Supabase Integration Tests' , ( ) => {
1515 test ( 'should connect to Supabase instance' , async ( ) => {
1616 expect ( supabase ) . toBeDefined ( )
1717 expect ( supabase ) . toBeInstanceOf ( SupabaseClient )
@@ -306,3 +306,40 @@ describe('Supabase Integration Tests', () => {
306306 } , 10000 )
307307 } )
308308} )
309+
310+ describe ( 'Storage API' , ( ) => {
311+ const bucket = 'test-bucket'
312+ const filePath = 'test-file.txt'
313+ const fileContent = new Blob ( [ 'Hello, Supabase Storage!' ] , { type : 'text/plain' } )
314+
315+ // use service_role key for bypass RLS
316+ const SERVICE_ROLE_KEY = process . env . SUPABASE_SERVICE_ROLE_KEY || 'use-service-role-key'
317+ const supabaseWithServiceRole = createClient ( SUPABASE_URL , SERVICE_ROLE_KEY , {
318+ realtime : { heartbeatIntervalMs : 500 } ,
319+ } )
320+
321+ test ( 'upload and list file in bucket' , async ( ) => {
322+ // upload
323+ const { data : uploadData , error : uploadError } = await supabaseWithServiceRole . storage
324+ . from ( bucket )
325+ . upload ( filePath , fileContent , { upsert : true } )
326+ expect ( uploadError ) . toBeNull ( )
327+ expect ( uploadData ) . toBeDefined ( )
328+
329+ // list
330+ const { data : listData , error : listError } = await supabaseWithServiceRole . storage
331+ . from ( bucket )
332+ . list ( )
333+ expect ( listError ) . toBeNull ( )
334+ expect ( Array . isArray ( listData ) ) . toBe ( true )
335+ if ( ! listData ) throw new Error ( 'listData is null' )
336+ const fileNames = listData . map ( ( f : any ) => f . name )
337+ expect ( fileNames ) . toContain ( 'test-file.txt' )
338+
339+ // delete file
340+ const { error : deleteError } = await supabaseWithServiceRole . storage
341+ . from ( bucket )
342+ . remove ( [ filePath ] )
343+ expect ( deleteError ) . toBeNull ( )
344+ } )
345+ } )
0 commit comments