{section.commands.map((command) => (
{command.name}
{command.badge?.()}
{'route' in command && {command.route}}
))}
))}
>
)
}
describe('useTableRelatedResourcesCommands', () => {
let relatedRequests: string[]
let functionRequests: string[]
let tableRequests: string[]
beforeEach(() => {
relatedRequests = []
functionRequests = []
tableRequests = []
mockUseSelectedProjectQuery.mockReturnValue({
data: { id: 1, ref: 'default', name: 'default', connectionString: 'encrypted' },
})
// Resolving the grant's scope reads the project, which the real table
// editor has already loaded
addAPIMock({
method: 'get',
path: '/platform/projects/:ref',
response: PROJECT,
})
addAPIMock({
method: 'post',
path: '/platform/pg-meta/:ref/query',
response: async ({ request }) => {
const { query } = (await request.json()) as { query: string }
if (query.includes('related_functions')) {
functionRequests.push(query)
return HttpResponse.json([REFERENCING_FUNCTIONS])
}
if (query.includes('table_policies')) {
relatedRequests.push(query)
return HttpResponse.json([RELATED_RESOURCES])
}
tableRequests.push(query)
return HttpResponse.json([
{ entity: { id: TABLE_ID, schema: 'public', name: 'blog_posts' } },
])
},
})
})
it('shows the policies and triggers while the function lookup is still running', async () => {
// Reading function bodies is orders of magnitude slower than the index
// probes behind the policies and triggers, so it must not hold them up
addAPIMock({
method: 'post',
path: '/platform/pg-meta/:ref/query',
response: async ({ request }) => {
const { query } = (await request.json()) as { query: string }
if (query.includes('related_functions')) {
functionRequests.push(query)
await delay('infinite')
}
if (query.includes('table_policies')) return HttpResponse.json([RELATED_RESOURCES])
return HttpResponse.json([
{ entity: { id: TABLE_ID, schema: 'public', name: 'blog_posts' } },
])
},
})
customRender(