-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(js): add JS user agent to Algolia requests (#420)
- Loading branch information
1 parent
226fc54
commit fab2d57
Showing
16 changed files
with
289 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/autocomplete-js/src/__tests__/getAlgoliaHits.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import algoliaPreset from '@algolia/autocomplete-preset-algolia'; | ||
|
||
import { createSearchClient } from '../../../../test/utils'; | ||
import { getAlgoliaHits } from '../getAlgoliaHits'; | ||
import { version } from '../version'; | ||
|
||
jest.mock('@algolia/autocomplete-preset-algolia', () => { | ||
const module = jest.requireActual('@algolia/autocomplete-preset-algolia'); | ||
|
||
return { | ||
...module, | ||
getAlgoliaHits: jest.fn(), | ||
}; | ||
}); | ||
|
||
describe('getAlgoliaHits', () => { | ||
test('forwards params to the preset function', () => { | ||
const searchClient = createSearchClient(); | ||
|
||
getAlgoliaHits({ searchClient, queries: [] }); | ||
|
||
expect(algoliaPreset.getAlgoliaHits).toHaveBeenCalledTimes(1); | ||
expect(algoliaPreset.getAlgoliaHits).toHaveBeenCalledWith({ | ||
searchClient, | ||
queries: [], | ||
userAgents: [{ segment: 'autocomplete-js', version }], | ||
}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/autocomplete-js/src/__tests__/getAlgoliaResults.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import algoliaPreset from '@algolia/autocomplete-preset-algolia'; | ||
|
||
import { createSearchClient } from '../../../../test/utils'; | ||
import { getAlgoliaResults } from '../getAlgoliaResults'; | ||
import { version } from '../version'; | ||
|
||
jest.mock('@algolia/autocomplete-preset-algolia', () => { | ||
const module = jest.requireActual('@algolia/autocomplete-preset-algolia'); | ||
|
||
return { | ||
...module, | ||
getAlgoliaResults: jest.fn(), | ||
}; | ||
}); | ||
|
||
describe('getAlgoliaResults', () => { | ||
test('forwards params to the preset function', () => { | ||
const searchClient = createSearchClient(); | ||
|
||
getAlgoliaResults({ searchClient, queries: [] }); | ||
|
||
expect(algoliaPreset.getAlgoliaResults).toHaveBeenCalledTimes(1); | ||
expect(algoliaPreset.getAlgoliaResults).toHaveBeenCalledWith({ | ||
searchClient, | ||
queries: [], | ||
userAgents: [{ segment: 'autocomplete-js', version }], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { | ||
getAlgoliaHits as getAlgoliaHitsOriginal, | ||
SearchParams, | ||
} from '@algolia/autocomplete-preset-algolia'; | ||
|
||
import { version } from './version'; | ||
|
||
export function getAlgoliaHits<TRecord>({ | ||
searchClient, | ||
queries, | ||
}: Pick<SearchParams, 'searchClient' | 'queries'>) { | ||
return getAlgoliaHitsOriginal<TRecord>({ | ||
searchClient, | ||
queries, | ||
userAgents: [{ segment: 'autocomplete-js', version }], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { | ||
getAlgoliaResults as getAlgoliaResultsOriginal, | ||
SearchParams, | ||
} from '@algolia/autocomplete-preset-algolia'; | ||
|
||
import { version } from './version'; | ||
|
||
export function getAlgoliaResults<TRecord>({ | ||
searchClient, | ||
queries, | ||
}: Pick<SearchParams, 'searchClient' | 'queries'>) { | ||
return getAlgoliaResultsOriginal<TRecord>({ | ||
searchClient, | ||
queries, | ||
userAgents: [{ segment: 'autocomplete-js', version }], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
export * from './autocomplete'; | ||
export * from './getAlgoliaHits'; | ||
export * from './getAlgoliaResults'; | ||
export * from './highlight'; | ||
export { | ||
getAlgoliaResults, | ||
getAlgoliaHits, | ||
} from '@algolia/autocomplete-preset-algolia'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const version = '1.0.0-alpha.39'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.