Files
supabase/e2e/studio/utils/storage/queries.ts
Ali Waseem c7f653f33f chore: move api solution to storage and parallelize tests (#42565)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

- Move storage tests to run in parallel
- Updated utils to use env

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Improved test reliability by shifting storage bucket setup and cleanup
from UI-based to API-backed operations.
* Enhanced test isolation with streamlined prerequisite navigation
steps.

* **Chores**
* Updated environment configuration to support dynamic API URL and
service role key settings.
* Refactored internal storage management utilities for improved
maintainability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-06 10:50:41 -07:00

55 lines
1.4 KiB
TypeScript

import { storageRequest } from './client.js'
interface Bucket {
id: string
name: string
public: boolean
}
/**
* List all storage buckets.
*/
export async function listBuckets(): Promise<Bucket[]> {
return storageRequest<Bucket[]>('/bucket')
}
/**
* Create a storage bucket. Idempotent — skips creation if the bucket already exists.
*
* @param name - Bucket name / id
* @param isPublic - Whether the bucket should be public (default: false)
*/
export async function createBucket(name: string, isPublic: boolean = false): Promise<void> {
const buckets = await listBuckets()
if (buckets.some((b) => b.id === name)) return
await storageRequest('/bucket', {
method: 'POST',
body: { id: name, name, public: isPublic },
})
}
/**
* Delete a storage bucket. Idempotent — empties the bucket first, then deletes it.
* No-ops if the bucket does not exist.
*
* @param name - Bucket name / id
*/
export async function deleteBucket(name: string): Promise<void> {
const buckets = await listBuckets()
if (!buckets.some((b) => b.id === name)) return
await storageRequest(`/bucket/${name}/empty`, { method: 'POST' })
await storageRequest(`/bucket/${name}`, { method: 'DELETE' })
}
/**
* Delete every storage bucket.
*/
export async function deleteAllBuckets(): Promise<void> {
const buckets = await listBuckets()
for (const bucket of buckets) {
await deleteBucket(bucket.id)
}
}