Skip to content

Commit

Permalink
feat(adapter): add mapping for keywords when there's no title_raw (#1236
Browse files Browse the repository at this point in the history
  • Loading branch information
CachedaCodes authored Jun 19, 2023
1 parent d513ef2 commit 5b1ce10
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
53 changes: 51 additions & 2 deletions packages/x-adapter-platform/src/__tests__/platform.adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('platformAdapter tests', () => {
topTrends: {
content: [
{
title_raw: 'shoes'
keywords: 'shoes'
}
]
}
Expand Down Expand Up @@ -205,7 +205,56 @@ describe('platformAdapter tests', () => {
topTrends: {
content: [
{
title_raw: 'shoes'
keywords: 'shoes'
}
]
}
};

const fetchMock = jest.fn(getFetchMock(rawPlatformQuerySuggestionsResponse));
window.fetch = fetchMock as any;

const response = await platformAdapter.querySuggestions({
query: 'boots',
start: 0,
rows: 24,
extraParams: {
instance: 'empathy',
env: 'test',
lang: 'en',
device: 'tablet',
scope: 'tablet'
}
});

expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(
// eslint-disable-next-line max-len
'https://api.test.empathy.co/search/v1/query/empathy/empathize?internal=true&query=boots&start=0&rows=24&instance=empathy&env=test&lang=en&device=tablet&scope=tablet',
{ signal: expect.anything() }
);

expect(response).toStrictEqual({
suggestions: [
{
query: 'shoes',
isCurated: false,
facets: [],
modelName: 'QuerySuggestion',
key: 'shoes'
}
]
});
});

// eslint-disable-next-line max-len
it('should call the query suggestions endpoint and prioritize for title_raw over keywords', async () => {
const rawPlatformQuerySuggestionsResponse: PlatformQuerySuggestionsResponse = {
topTrends: {
content: [
{
title_raw: 'shoes',
keywords: 'no_query'
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { PlatformSuggestion } from '../../types/models/suggestion.model';
* @public
*/
export const suggestionSchema = createMutableSchema<PlatformSuggestion, Suggestion>({
query: 'title_raw',
key: 'title_raw',
query: ({ title_raw, keywords }) => title_raw ?? keywords,
key: ({ title_raw, keywords }) => title_raw ?? keywords,
modelName: (_, $context) =>
$context?.requestParameters?.query ? 'QuerySuggestion' : 'PopularSearch',
facets: () => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
* @public
*/
export interface PlatformSuggestion {
title_raw: string;
// TODO: Remove title_raw when endpoint changes and removes it permanently
title_raw?: string;
keywords: string;
}

0 comments on commit 5b1ce10

Please sign in to comment.