mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 00:19:08 +00:00
## Problem Components and fetchers are moving to endpoint-bound FGA grants, so more tests need to mock `/platform/profile/permissions/v2` and mint grants. Each test file currently defines its own permissions response type and mock, and `testGrant` lives inside `guarded-fetch.test.ts`. Resolves [FE-4692](https://linear.app/supabase/issue/FE-4692/test-infra-global-msw-handler-for-v2-permissions-and-testgrant). ## Solution * `tests/lib/permissions-fixtures.ts`: shared `PermissionsV2Response` type, `ALL_FGA_PERMISSIONS`, `allPermissionsFor(slugs)` (grants everything at the org level), and `NO_PERMISSIONS`. * `tests/lib/msw-permissions.ts`: `mockPermissions(response)` and `mockPermissionsError({ status, message })` on top of `addAPIMock`. * `tests/lib/test-grant.ts`: `testGrant(endpoint, { variant, organizationSlug, projectRef, permissionsProjectRef })` for unit tests of fetchers and query options, moved out of `guarded-fetch.test.ts`. * Existing tests that mocked the v2 endpoint now use the shared helpers. `IndirectTaxDeclarationModal.test.tsx` keeps its own `addAPIMock` because a test asserts the request was served. * Documented in `apps/studio/tests/README.md` and the `studio-mock-api-tests` skill.
25 lines
897 B
TypeScript
25 lines
897 B
TypeScript
import type { platformComponents as components } from 'api-types'
|
|
|
|
import { FGA_PERMISSIONS, type FgaPermissions } from '@/hooks/misc/useCheckPermissionsV2'
|
|
|
|
export type PermissionsV2Response = components['schemas']['UserPermissionsResponse_Output']
|
|
|
|
export const ALL_FGA_PERMISSIONS: FgaPermissions[] = Object.values(FGA_PERMISSIONS).flatMap(
|
|
(group) => Object.values(group)
|
|
)
|
|
|
|
/** Grants every FGA permission at the org level, which also covers every project in the org. */
|
|
export function allPermissionsFor(organizationSlugs: readonly string[]): PermissionsV2Response {
|
|
return {
|
|
organizations: organizationSlugs.map((slug) => ({
|
|
slug,
|
|
role: 'owner',
|
|
permissions: ALL_FGA_PERMISSIONS,
|
|
projects: [],
|
|
})),
|
|
}
|
|
}
|
|
|
|
/** No organization memberships, so every permission check is denied. */
|
|
export const NO_PERMISSIONS: PermissionsV2Response = { organizations: [] }
|