-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathuse-algolia-search.spec.ts
More file actions
27 lines (21 loc) · 937 Bytes
/
use-algolia-search.spec.ts
File metadata and controls
27 lines (21 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { describe, expect, it, vi } from 'vitest'
import fixture from '~~/test/fixtures/algolia/search/security-holder.json'
const mockSearch = vi.fn()
vi.mock('algoliasearch/lite', () => ({
liteClient: () => ({ search: mockSearch }),
}))
describe('useAlgoliaSearch', () => {
it('maps isSecurityHeld through to NpmSearchResult.package', async () => {
mockSearch.mockResolvedValue({
results: [{ hits: fixture, nbHits: fixture.length }],
})
const { search } = useAlgoliaSearch()
const { objects } = await search('')
const bad = objects.find(o => o.package.name === 'vuln-npm')
const good = objects.find(o => o.package.name === 'npmx-connector')
expect(bad?.package.isSecurityHeld).toBe(true)
expect(good?.package.isSecurityHeld).toBe(false)
const filtered = objects.filter(o => !o.package.isSecurityHeld).map(o => o.package.name)
expect(filtered).toEqual(['npmx-connector'])
})
})