mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Fix review findings validating OM-84
This commit is contained in:
1 parent
f0efe26068
commit
94d3822635
2 files changed
+76
-1
No files matched your search
@@ -0,0 +1,74 @@
|
||||
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' })
|
||||
})
|
||||
})
|
||||
@@ -21,8 +21,9 @@ function buildSetSecretRequest({
|
||||
if (kind !== 'secret') {
|
||||
return environment ? { value, environment } : { value }
|
||||
}
|
||||
const request: SetSecretRequest = { value, agentHidden: agentHidden ?? false }
|
||||
const request: SetSecretRequest = { value }
|
||||
if (environment) request.environment = environment
|
||||
if (agentHidden !== undefined) request.agentHidden = agentHidden
|
||||
if (agentHidden && allowedHosts && allowedHosts.length > 0) request.allowedHosts = allowedHosts
|
||||
return request
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user