mirror of
https://github.com/supabase/supabase.git
synced 2026-09-06 09:59:03 +08:00
Adds a contract test that runs `createProjectSupabaseClient()` against the real `@supabase/supabase-js` for each Supabase API key format (temporary, publishable, secret, legacy JWT), asserting that client construction succeeds. Also replaces the placeholder key fixtures in the existing unit tests with realistically shaped ones. Previously the tests mocked the SDK entirely and used keys that don't resemble real formats, so an SDK version that rejects a valid key at construction (as `@supabase/supabase-js` 2.110.4 and 2.110.5 did, reverted in #47945 and fixed in supabase/supabase-js#2526) passed CI unnoticed; with this test, such a regression fails on the dependency bump PR itself. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added coverage confirming project clients work with temporary, publishable, secret, and legacy API key formats. * Updated test scenarios to use realistic temporary API key values. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { createProjectSupabaseClient } from './project-supabase-client'
|
|
import * as apiKeysUtils from '@/data/api-keys/temp-api-keys-utils'
|
|
|
|
// Unlike project-supabase-client.test.ts, this file does not mock
|
|
// @supabase/supabase-js: the real client constructor must run.
|
|
vi.mock('@/data/api-keys/temp-api-keys-utils', () => ({
|
|
getOrRefreshTemporaryApiKey: vi.fn(),
|
|
}))
|
|
|
|
// Supabase API key formats this client must accept.
|
|
const KEY_SHAPES = [
|
|
['temporary key', 'sb_temp_nonce1234567890ab_payload'],
|
|
['publishable key', 'sb_publishable_abc123'],
|
|
['secret key', 'sb_secret_abc123'],
|
|
['legacy JWT key', 'eyJhbGciOiJIUzI1NiJ9.payload.signature'],
|
|
]
|
|
|
|
describe('createProjectSupabaseClient key format contract', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it.each(KEY_SHAPES)('constructs a client with a %s', async (_label, apiKey) => {
|
|
vi.mocked(apiKeysUtils.getOrRefreshTemporaryApiKey).mockResolvedValue({
|
|
apiKey,
|
|
expiryTimeMs: Date.now() + 3600000,
|
|
})
|
|
|
|
const client = await createProjectSupabaseClient('test-ref', 'https://test.supabase.co')
|
|
|
|
expect(client).toBeDefined()
|
|
expect(client.auth).toBeDefined()
|
|
})
|
|
})
|