Skip to content

Commit ed7accd

Browse files
author
georgiy.rusanov
committed
added bucket test
1 parent 3a97f7a commit ed7accd

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,13 @@ jobs:
176176
npm ci
177177
npm run build
178178
179+
- name: Install jq
180+
run: sudo apt-get update && sudo apt-get install -y jq
181+
179182
- name: Run integration tests
180-
run: npm run test:integration || npm run test:integration
183+
run: |
184+
export SUPABASE_SERVICE_ROLE_KEY="$(supabase status --output json | jq -r '.SERVICE_ROLE_KEY')"
185+
npm run test:integration || npm run test:integration
181186
182187
- name: Stop Supabase
183188
if: always()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Create test bucket for storage tests
2+
insert into storage.buckets (id, name, public)
3+
values ('test-bucket', 'test-bucket', false)
4+
on conflict (id) do nothing;

test/integration.test.ts

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)