Skip to content

Commit 84f05c3

Browse files
author
georgiy.rusanov
committed
added bucket test for deno and bun
1 parent ed7accd commit 84f05c3

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,16 @@ jobs:
134134
npm ci
135135
npm run build
136136
137+
- name: Install jq
138+
run: sudo apt-get update && sudo apt-get install -y jq
139+
137140
- name: Run Deno Tests
138141
run: |
139142
cd test/deno
140143
cp ../../supabase-pkg/supabase-supabase-js-0.0.0-automated.tgz .
141144
npm install
142-
npm test || npm test
145+
SERVICE_ROLE_KEY="$(supabase status --output json | jq -r '.SERVICE_ROLE_KEY')"
146+
SUPABASE_SERVICE_ROLE_KEY="$SERVICE_ROLE_KEY" deno test --allow-all --unstable-sloppy-imports integration.test.ts
143147
144148
- name: Run integration and browser tests on Deno 2.x only
145149
if: ${{ matrix.deno == '2.x' }}
@@ -297,12 +301,16 @@ jobs:
297301
- name: Start Supabase
298302
run: supabase start
299303

304+
- name: Install jq
305+
run: sudo apt-get update && sudo apt-get install -y jq
306+
300307
- name: Install dependencies and run tests
301308
run: |
302309
cd test/integration/bun
303310
cp ../../../supabase-pkg/supabase-supabase-js-0.0.0-automated.tgz .
304311
bun install
305-
bun test
312+
SERVICE_ROLE_KEY="$(supabase status --output json | jq -r '.SERVICE_ROLE_KEY')"
313+
SUPABASE_SERVICE_ROLE_KEY="$SERVICE_ROLE_KEY" bun test
306314
307315
- name: Stop Supabase
308316
if: always()

test/deno/integration.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ Deno.test(
1515
const ANON_KEY =
1616
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'
1717

18+
// use service_role key for Storage API tests
19+
const SERVICE_ROLE_KEY = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') || 'use-service-role-key'
20+
1821
const supabase = createClient(SUPABASE_URL, ANON_KEY, {
1922
realtime: { heartbeatIntervalMs: 500 },
2023
})
2124

25+
const supabaseWithServiceRole = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, {
26+
realtime: { heartbeatIntervalMs: 500 },
27+
})
28+
2229
// Cleanup function to be called after all tests
2330
const cleanup = async () => {
2431
await supabase.auth.signOut()
@@ -197,6 +204,34 @@ Deno.test(
197204
// Cleanup channel
198205
await channel.unsubscribe()
199206
})
207+
208+
await t.step('Storage API - upload and list file in bucket', async () => {
209+
const bucket = 'test-bucket'
210+
const filePath = 'deno-test-file.txt'
211+
const fileContent = new Blob(['Hello, Deno Storage Test!'], { type: 'text/plain' })
212+
213+
// upload
214+
const { data: uploadData, error: uploadError } = await supabaseWithServiceRole.storage
215+
.from(bucket)
216+
.upload(filePath, fileContent, { upsert: true })
217+
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+
226+
assertEquals(listError, null)
227+
assertEquals(Array.isArray(listData), true)
228+
if (!listData) throw new Error('listData is null')
229+
const fileNames = listData.map((f: any) => f.name)
230+
assertEquals(fileNames.includes('deno-test-file.txt'), true)
231+
232+
// cleanup
233+
await supabaseWithServiceRole.storage.from(bucket).remove([filePath])
234+
})
200235
} finally {
201236
// Ensure cleanup runs even if tests fail
202237
await cleanup()

test/integration/bun/integration.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ const SUPABASE_URL = 'http://127.0.0.1:54321'
55
const ANON_KEY =
66
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'
77

8+
// Используем service_role key для Storage API тестов
9+
const SERVICE_ROLE_KEY = process.env.SUPABASE_SERVICE_ROLE_KEY || 'use-service-role-key'
10+
811
const supabase = createClient(SUPABASE_URL, ANON_KEY, {
912
realtime: { heartbeatIntervalMs: 500 },
1013
})
1114

15+
const supabaseWithServiceRole = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, {
16+
realtime: { heartbeatIntervalMs: 500 },
17+
})
18+
1219
test('should subscribe to realtime channel', async () => {
1320
await supabase.auth.signOut()
1421
const email = `bun-test-${Date.now()}@example.com`
@@ -109,3 +116,31 @@ test('should handle invalid credentials', async () => {
109116
expect(error).not.toBeNull()
110117
expect(data.user).toBeNull()
111118
})
119+
120+
test('Storage API - upload and list file in bucket', async () => {
121+
const bucket = 'test-bucket'
122+
const filePath = 'bun-test-file.txt'
123+
const fileContent = new Blob(['Hello, Bun Storage Test!'], { type: 'text/plain' })
124+
125+
// upload
126+
const { data: uploadData, error: uploadError } = await supabaseWithServiceRole.storage
127+
.from(bucket)
128+
.upload(filePath, fileContent, { upsert: true })
129+
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+
138+
expect(listError).toBeNull()
139+
expect(Array.isArray(listData)).toBe(true)
140+
if (!listData) throw new Error('listData is null')
141+
const fileNames = listData.map((f: any) => f.name)
142+
expect(fileNames).toContain('bun-test-file.txt')
143+
144+
// cleanup
145+
await supabaseWithServiceRole.storage.from(bucket).remove([filePath])
146+
}, 10000)

0 commit comments

Comments
 (0)