mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 12:55:06 +03:00
Test utilities ## What is the current behavior? E2E tests that need to verify database state go through the SQL Editor, which is unnecessarily slow and prone to future breakage. ## What is the new behavior? Adds shared db utils for checking database state in Studio E2E tests by querying the database directly. Refactors API access tests to use the new utilities. ## Summary by CodeRabbit * **Tests** * Refactored API access privilege verification to use direct database queries instead of SQL editor interaction. * Added database utility functions for e2e tests to query table existence and access privileges. * Updated test signatures to simplify privilege verification calls.
20 lines
596 B
TypeScript
20 lines
596 B
TypeScript
import { query } from './client.js'
|
|
|
|
/**
|
|
* Check if a table exists in the specified schema.
|
|
*
|
|
* @param schema - The schema name (e.g., 'public')
|
|
* @param tableName - The table name to check
|
|
* @returns true if the table exists, false otherwise
|
|
*/
|
|
export async function tableExists(schema: string, tableName: string): Promise<boolean> {
|
|
const result = await query<{ exists: boolean }>(
|
|
`SELECT EXISTS (
|
|
SELECT 1 FROM information_schema.tables
|
|
WHERE table_schema = $1 AND table_name = $2
|
|
) as exists`,
|
|
[schema, tableName]
|
|
)
|
|
return result[0]?.exists ?? false
|
|
}
|