Skip to content

Commit a5f787c

Browse files
author
georgiy.rusanov
committed
added bucket test for bun
1 parent ed7accd commit a5f787c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/integration/bun/integration.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,40 @@ test('should handle invalid credentials', async () => {
109109
expect(error).not.toBeNull()
110110
expect(data.user).toBeNull()
111111
})
112+
113+
test('should upload and list file in bucket', async () => {
114+
const bucket = 'test-bucket'
115+
const filePath = 'test-file.txt'
116+
const fileContent = new Blob(['Hello, Supabase Storage!'], { type: 'text/plain' })
117+
118+
// use service_role key for bypass RLS
119+
const SERVICE_ROLE_KEY =
120+
process.env.SUPABASE_SERVICE_ROLE_KEY ||
121+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU'
122+
const supabaseWithServiceRole = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, {
123+
realtime: { heartbeatIntervalMs: 500 },
124+
})
125+
126+
// upload
127+
const { data: uploadData, error: uploadError } = await supabaseWithServiceRole.storage
128+
.from(bucket)
129+
.upload(filePath, fileContent, { upsert: true })
130+
expect(uploadError).toBeNull()
131+
expect(uploadData).toBeDefined()
132+
133+
// list
134+
const { data: listData, error: listError } = await supabaseWithServiceRole.storage
135+
.from(bucket)
136+
.list()
137+
expect(listError).toBeNull()
138+
expect(Array.isArray(listData)).toBe(true)
139+
if (!listData) throw new Error('listData is null')
140+
const fileNames = listData.map((f: any) => f.name)
141+
expect(fileNames).toContain('test-file.txt')
142+
143+
// delete file
144+
const { error: deleteError } = await supabaseWithServiceRole.storage
145+
.from(bucket)
146+
.remove([filePath])
147+
expect(deleteError).toBeNull()
148+
})

0 commit comments

Comments
 (0)