mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## Summary - `getReadReplicas` now accepts an optional `headers?: HeadersInit` param, forwarded to the underlying `get()` call — mirrors `getContentById`/`getNotebook`. - Pure plumbing: no behavior change for existing (browser/cookie-auth) callers. Part 1/6 of the stack for FE-4225 (expose valid database identifiers to the notebook AI agent). This PR lets a server-side AI tool call `getReadReplicas` with the request's bearer token in a later PR in the stack. ## Test plan - [x] `getReadReplicas` unit test verifying the header is forwarded on the outgoing request - [x] `pnpm --filter studio exec tsc --noEmit` passes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved read-replica data requests by forwarding authorization headers correctly. * Maintained existing request cancellation and error-handling behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { HttpResponse } from 'msw'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
getMaxReplicas,
|
|
getReadReplicas,
|
|
READ_REPLICA_COMPUTE_CAPS,
|
|
READ_REPLICAS_MAX_COUNT,
|
|
} from './replicas-query'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
describe('getMaxReplicas', () => {
|
|
it('returns 0 for ineligible compute sizes (pico, nano, micro)', () => {
|
|
expect(getMaxReplicas('ci_pico')).toBe(0)
|
|
expect(getMaxReplicas('ci_nano')).toBe(0)
|
|
expect(getMaxReplicas('ci_micro')).toBe(0)
|
|
})
|
|
|
|
it('returns 4 for ci_small', () => {
|
|
expect(getMaxReplicas('ci_small')).toBe(4)
|
|
})
|
|
|
|
it('returns 4 for ci_medium', () => {
|
|
expect(getMaxReplicas('ci_medium')).toBe(4)
|
|
})
|
|
|
|
it('returns 4 for ci_large', () => {
|
|
expect(getMaxReplicas('ci_large')).toBe(4)
|
|
})
|
|
|
|
it('returns READ_REPLICAS_MAX_COUNT for ci_xlarge and above', () => {
|
|
expect(getMaxReplicas('ci_xlarge')).toBe(READ_REPLICAS_MAX_COUNT)
|
|
expect(getMaxReplicas('ci_2xlarge')).toBe(READ_REPLICAS_MAX_COUNT)
|
|
})
|
|
|
|
it('returns READ_REPLICAS_MAX_COUNT for any unknown compute tier', () => {
|
|
expect(getMaxReplicas('unknown_tier')).toBe(READ_REPLICAS_MAX_COUNT)
|
|
})
|
|
|
|
it('returns READ_REPLICAS_MAX_COUNT when no compute addon is provided', () => {
|
|
expect(getMaxReplicas(undefined)).toBe(READ_REPLICAS_MAX_COUNT)
|
|
})
|
|
|
|
it('all eligible READ_REPLICA_COMPUTE_CAPS are greater than 0 and at most READ_REPLICAS_MAX_COUNT', () => {
|
|
for (const [, cap] of Object.entries(READ_REPLICA_COMPUTE_CAPS)) {
|
|
if (cap > 0) {
|
|
expect(cap).toBeLessThanOrEqual(READ_REPLICAS_MAX_COUNT)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('getReadReplicas', () => {
|
|
it('forwards the given headers on the request', async () => {
|
|
let receivedAuthHeader: string | null = null
|
|
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/databases',
|
|
response: ({ request }) => {
|
|
receivedAuthHeader = request.headers.get('Authorization')
|
|
return HttpResponse.json([])
|
|
},
|
|
})
|
|
|
|
await getReadReplicas({ projectRef: 'default' }, undefined, {
|
|
Authorization: 'Bearer test-token',
|
|
})
|
|
|
|
expect(receivedAuthHeader).toBe('Bearer test-token')
|
|
})
|
|
})
|