Skip to content

Commit

Permalink
Test getWorkspaceScope
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-balitskyi committed Dec 12, 2024
1 parent 7969c34 commit 1e70dc0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
48 changes: 48 additions & 0 deletions src/lib/blueprint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
createProperties,
getPreferredMethod,
getSemanticMethod,
getWorkspaceScope,
type Method,
type OpenapiAuthMethod,
} from 'lib/blueprint.js'
import type { OpenapiOperation, OpenapiSchema } from 'lib/openapi.js'

Expand Down Expand Up @@ -343,3 +345,49 @@ test('getPreferredMethod: delete and post', (t) => {
'Preferred method should be POST when both DELETE and POST are available',
)
})

test('getWorkspaceScope: no auth methods', (t) => {
const authMethods: OpenapiAuthMethod[] = []
t.is(
getWorkspaceScope(authMethods),
'none',
'Workspace scope should be "none" when no auth methods are present',
)
})

test('getWorkspaceScope: only unscoped auth methods', (t) => {
const authMethods: OpenapiAuthMethod[] = [
'pat_without_workspace',
'console_session_token_without_workspace',
]
t.is(
getWorkspaceScope(authMethods),
'none',
'Workspace scope should be "none" when only unscoped auth methods are present',
)
})

test('getWorkspaceScope: only scoped auth methods', (t) => {
const authMethods: OpenapiAuthMethod[] = [
'api_key',
'client_session',
'pat_with_workspace',
]
t.is(
getWorkspaceScope(authMethods),
'required',
'Workspace scope should be "required" when only scoped auth methods are present',
)
})

test('getWorkspaceScope: both scoped and unscoped auth methods', (t) => {
const authMethods: OpenapiAuthMethod[] = [
'pat_with_workspace',
'pat_without_workspace',
]
t.is(
getWorkspaceScope(authMethods),
'optional',
'Workspace scope should be "optional" when both scoped and unscoped auth methods are present',
)
})
4 changes: 1 addition & 3 deletions src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,9 @@ const createEndpointFromOperation = async (
return authMethod as OpenapiAuthMethod
},
)

const endpointAuthMethods = operationAuthMethods
.map(mapOpenapiToSeamAuthMethod)
.filter((authMethod): authMethod is SeamAuthMethod => authMethod != null)

const workspaceScope = getWorkspaceScope(operationAuthMethods)

const endpoint: Omit<Endpoint, 'codeSamples'> = {
Expand Down Expand Up @@ -552,7 +550,7 @@ const createEndpointFromOperation = async (
}
}

type OpenapiAuthMethod = z.infer<typeof AuthMethodSchema>
export type OpenapiAuthMethod = z.infer<typeof AuthMethodSchema>

export const getWorkspaceScope = (
authMethods: OpenapiAuthMethod[],
Expand Down

0 comments on commit 1e70dc0

Please sign in to comment.