Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions convex/httpApi.handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('httpApi handlers', () => {
query: 'test',
limit: 5,
highlightedOnly: true,
nonSuspiciousOnly: undefined,
})
expect(response.status).toBe(200)
const json = await response.json()
Expand All @@ -65,6 +66,7 @@ describe('httpApi handlers', () => {
query: 'test',
limit: undefined,
highlightedOnly: true,
nonSuspiciousOnly: undefined,
})
})

Expand All @@ -78,6 +80,35 @@ describe('httpApi handlers', () => {
query: 'test',
limit: undefined,
highlightedOnly: undefined,
nonSuspiciousOnly: undefined,
})
})

it('searchSkillsHttp forwards nonSuspiciousOnly', async () => {
const runAction = vi.fn().mockResolvedValue([])
await __handlers.searchSkillsHandler(
makeCtx({ runAction }),
new Request('https://example.com/api/search?q=test&nonSuspiciousOnly=1'),
)
expect(runAction).toHaveBeenCalledWith(expect.anything(), {
query: 'test',
limit: undefined,
highlightedOnly: undefined,
nonSuspiciousOnly: true,
})
})

it('searchSkillsHttp forwards legacy nonSuspicious alias', async () => {
const runAction = vi.fn().mockResolvedValue([])
await __handlers.searchSkillsHandler(
makeCtx({ runAction }),
new Request('https://example.com/api/search?q=test&nonSuspicious=1'),
)
expect(runAction).toHaveBeenCalledWith(expect.anything(), {
query: 'test',
limit: undefined,
highlightedOnly: undefined,
nonSuspiciousOnly: true,
})
})

Expand Down
9 changes: 7 additions & 2 deletions convex/httpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { ActionCtx } from './_generated/server'
import { httpAction } from './functions'
import { requireApiTokenUser } from './lib/apiTokenAuth'
import { corsHeaders, mergeHeaders } from './lib/httpHeaders'
import { parseBooleanQueryParam } from './lib/httpUtils'
import { publishVersionForUser } from './skills'

type SearchSkillEntry = {
Expand Down Expand Up @@ -44,15 +45,19 @@ async function searchSkillsHandler(ctx: ActionCtx, request: Request) {
const url = new URL(request.url)
const query = url.searchParams.get('q')?.trim() ?? ''
const limit = toOptionalNumber(url.searchParams.get('limit'))
const approvedOnly = url.searchParams.get('approvedOnly') === 'true'
const highlightedOnly = url.searchParams.get('highlightedOnly') === 'true' || approvedOnly
const approvedOnly = parseBooleanQueryParam(url.searchParams.get('approvedOnly'))
const highlightedOnly = parseBooleanQueryParam(url.searchParams.get('highlightedOnly')) || approvedOnly
const nonSuspiciousOnly =
parseBooleanQueryParam(url.searchParams.get('nonSuspiciousOnly')) ||
parseBooleanQueryParam(url.searchParams.get('nonSuspicious'))

if (!query) return json({ results: [] })

const results = (await ctx.runAction(api.search.searchSkills, {
query,
limit,
highlightedOnly: highlightedOnly || undefined,
nonSuspiciousOnly: nonSuspiciousOnly || undefined,
})) as SearchSkillEntry[]

return json({
Expand Down
Loading