mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { act } from '@testing-library/react'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { useSetSecret } from './useSecrets'
|
|
import type { SecretScope } from '@/api/secrets'
|
|
import { renderHookWithProviders } from '@/test/render'
|
|
|
|
const repoScope: SecretScope = { scope: 'repo', repoId: 7 }
|
|
const putRoute = '/api/repos/7/:kind/:name'
|
|
|
|
function renderSetSecret() {
|
|
return renderHookWithProviders(() => useSetSecret(repoScope), {
|
|
auth: false,
|
|
theme: false,
|
|
fetchRoutes: [{ method: 'PUT', path: putRoute, respond: () => ({ status: 204 }) }],
|
|
})
|
|
}
|
|
|
|
describe('useSetSecret', () => {
|
|
it('omits agentHidden when the caller does not provide it', async () => {
|
|
const { result, fetchFake } = renderSetSecret()
|
|
|
|
await act(async () => {
|
|
await result.current.mutateAsync({ kind: 'secret', name: 'FOO', value: 'x' })
|
|
})
|
|
|
|
expect(fetchFake.lastRequest('PUT', putRoute)?.body).toEqual({ value: 'x' })
|
|
})
|
|
|
|
it('sends agentHidden false when the caller provides false', async () => {
|
|
const { result, fetchFake } = renderSetSecret()
|
|
|
|
await act(async () => {
|
|
await result.current.mutateAsync({ kind: 'secret', name: 'FOO', value: 'x', agentHidden: false })
|
|
})
|
|
|
|
expect(fetchFake.lastRequest('PUT', putRoute)?.body).toEqual({ value: 'x', agentHidden: false })
|
|
})
|
|
|
|
it('sends agentHidden and the allowed hosts for a hidden secret', async () => {
|
|
const { result, fetchFake } = renderSetSecret()
|
|
|
|
await act(async () => {
|
|
await result.current.mutateAsync({
|
|
kind: 'secret',
|
|
name: 'FOO',
|
|
value: 'x',
|
|
agentHidden: true,
|
|
allowedHosts: ['api.example.com'],
|
|
})
|
|
})
|
|
|
|
expect(fetchFake.lastRequest('PUT', putRoute)?.body).toEqual({
|
|
value: 'x',
|
|
agentHidden: true,
|
|
allowedHosts: ['api.example.com'],
|
|
})
|
|
})
|
|
|
|
it('omits agentHidden and the allowed hosts for a variable', async () => {
|
|
const { result, fetchFake } = renderSetSecret()
|
|
|
|
await act(async () => {
|
|
await result.current.mutateAsync({
|
|
kind: 'variable',
|
|
name: 'FOO',
|
|
value: 'x',
|
|
agentHidden: true,
|
|
allowedHosts: ['api.example.com'],
|
|
})
|
|
})
|
|
|
|
expect(fetchFake.lastRequest('PUT', putRoute)?.body).toEqual({ value: 'x' })
|
|
})
|
|
})
|