diff --git a/packages/x-adapter-platform/src/__tests__/platform.adapter.spec.ts b/packages/x-adapter-platform/src/__tests__/platform.adapter.spec.ts index 982843448a..4ccfdc5c76 100644 --- a/packages/x-adapter-platform/src/__tests__/platform.adapter.spec.ts +++ b/packages/x-adapter-platform/src/__tests__/platform.adapter.spec.ts @@ -160,7 +160,7 @@ describe('platformAdapter tests', () => { topTrends: { content: [ { - title_raw: 'shoes' + keywords: 'shoes' } ] } @@ -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' } ] } diff --git a/packages/x-adapter-platform/src/schemas/models/suggestion.schema.ts b/packages/x-adapter-platform/src/schemas/models/suggestion.schema.ts index 29d2b916a8..f22877c7c3 100644 --- a/packages/x-adapter-platform/src/schemas/models/suggestion.schema.ts +++ b/packages/x-adapter-platform/src/schemas/models/suggestion.schema.ts @@ -8,8 +8,8 @@ import { PlatformSuggestion } from '../../types/models/suggestion.model'; * @public */ export const suggestionSchema = createMutableSchema({ - 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: () => [], diff --git a/packages/x-adapter-platform/src/types/models/suggestion.model.ts b/packages/x-adapter-platform/src/types/models/suggestion.model.ts index bea44a46cc..df052b0331 100644 --- a/packages/x-adapter-platform/src/types/models/suggestion.model.ts +++ b/packages/x-adapter-platform/src/types/models/suggestion.model.ts @@ -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; }