34 lines
1.6 KiB
TypeScript
34 lines
1.6 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { api } from './api'
|
|
|
|
afterEach(() => { vi.unstubAllGlobals() })
|
|
|
|
describe('AutoDiscover list request', () => {
|
|
it('passes the abort signal so an over-budget project list request is cancelled', async () => {
|
|
const seen: (RequestInit | undefined)[] = []
|
|
vi.stubGlobal('fetch', async (_path: string, init?: RequestInit) => {
|
|
seen.push(init)
|
|
return new Response('[]', { status: 200 })
|
|
})
|
|
const controller = new AbortController()
|
|
await api.listProjects(controller.signal)
|
|
await api.listProjects()
|
|
expect(seen[0]?.signal).toBe(controller.signal)
|
|
expect(seen[1]).toBeUndefined()
|
|
})
|
|
|
|
it('reads the linked creation capability from the identity response', async () => {
|
|
vi.stubGlobal('fetch', async () => new Response(JSON.stringify({ owner: 'bob', name: 'Bob', auth: true,
|
|
linkedCapabilities: { projectCreate: true, source: 'system-grant', linkedActions: ['project.members.manage'], authorityEpoch: 4 } }), { status: 200 }))
|
|
const me = await api.me()
|
|
expect(me.linkedCapabilities).toMatchObject({ projectCreate: true, source: 'system-grant' })
|
|
})
|
|
|
|
it('returns the linked expansion from a role permission write receipt', async () => {
|
|
vi.stubGlobal('fetch', async () => new Response(JSON.stringify({ receiptId: 'r1', roleVersion: 3, authorityEpoch: 9,
|
|
linkedExpansion: ['project.members.manage'] }), { status: 200 }))
|
|
const receipt = await api.replaceRolePermissions('role_pm', 2, [{ actionId: 'project.create', allowed: true, capAllowed: true }], 'key')
|
|
expect(receipt.linkedExpansion).toEqual(['project.members.manage'])
|
|
})
|
|
})
|