diff --git a/tests/acceptance/acceptancesuites/acceptancesuite.js b/tests/acceptance/acceptancesuites/acceptancesuite.js index 3dbfc621a..64719fc3f 100644 --- a/tests/acceptance/acceptancesuites/acceptancesuite.js +++ b/tests/acceptance/acceptancesuites/acceptancesuite.js @@ -8,7 +8,8 @@ import { VERTICAL_SEARCH_URL_REGEX } from '../constants'; import FacetsPage from '../pageobjects/facetspage'; -import { MockedUniversalSearchRequest } from '../fixtures/responses/universal'; +import { MockedUniversalAutoCompleteRequest } from '../fixtures/responses/universal/autocomplete'; +import { MockedUniversalSearchRequest } from '../fixtures/responses/universal/search'; import { Selector, RequestLogger } from 'testcafe'; import { browserBackButton, @@ -26,7 +27,13 @@ import SearchRequestLogger from '../searchrequestlogger'; */ fixture`Universal search page works as expected` - .requestHooks([SearchRequestLogger.createUniversalSearchLogger(), MockedUniversalSearchRequest]) + .requestHooks( + [ + SearchRequestLogger.createUniversalSearchLogger(), + MockedUniversalSearchRequest, + MockedUniversalAutoCompleteRequest + ] + ) .beforeEach(async t => { await registerIE11NoCacheHook(t, UNIVERSAL_SEARCH_URL_REGEX); }) diff --git a/tests/acceptance/fixtures/responses/cors.js b/tests/acceptance/fixtures/responses/cors.js new file mode 100644 index 000000000..ea5e709d6 --- /dev/null +++ b/tests/acceptance/fixtures/responses/cors.js @@ -0,0 +1 @@ +export const CORSHeaders = { 'access-control-allow-credentials': true, 'access-control-allow-origin': 'http://localhost:9999' }; diff --git a/tests/acceptance/fixtures/responses/universal/autocomplete.js b/tests/acceptance/fixtures/responses/universal/autocomplete.js new file mode 100644 index 000000000..e6ffd5019 --- /dev/null +++ b/tests/acceptance/fixtures/responses/universal/autocomplete.js @@ -0,0 +1,53 @@ +import { RequestMock } from 'testcafe'; +import { CORSHeaders } from '../cors'; + +function generateAutoCompleteResponse (prompt) { + const mockedResponse = { + meta: { + uuid: '01802d71-9901-1b83-9d50-ff143088f1ab', + errors: [] + }, + response: { + input: { + value: prompt, + queryIntents: [] + }, + results: [] + } + }; + + if (prompt === '') { + mockedResponse.response.results = [ + { + value: 'a Rose by any other name', + matchedSubstrings: [], + queryIntents: [], + verticalKeys: [] + }, + { + value: 'amani farooque phone number', + matchedSubstrings: [], + queryIntents: [], + verticalKeys: [] + } + ]; + } else if (prompt.startsWith('a')) { + mockedResponse.response.results = [ + { value: 'amani farooque phone number', matchedSubstrings: [], queryIntents: [], verticalKeys: [] } + ]; + } + + return mockedResponse; +} + +export const MockedUniversalAutoCompleteRequest = RequestMock() + .onRequestTo(async request => { + const urlRegex = /^https:\/\/liveapi-cached.yext.com\/v2\/accounts\/me\/answers\/autocomplete/; + return urlRegex.test(request.url) && request.method === 'get'; + }) + .respond((req, res) => { + const parsedUrl = new URL(req.url); + res.body = JSON.stringify(generateAutoCompleteResponse(parsedUrl.searchParams.get('input'))); + res.headers = CORSHeaders; + res.statusCode = 200; + }); diff --git a/tests/acceptance/fixtures/responses/universal.js b/tests/acceptance/fixtures/responses/universal/search.js similarity index 99% rename from tests/acceptance/fixtures/responses/universal.js rename to tests/acceptance/fixtures/responses/universal/search.js index 8e4de0b06..089c1e36e 100644 --- a/tests/acceptance/fixtures/responses/universal.js +++ b/tests/acceptance/fixtures/responses/universal/search.js @@ -1,4 +1,5 @@ import { RequestMock } from 'testcafe'; +import { CORSHeaders } from '../cors'; const UniversalSearchResponse = { meta: { @@ -476,7 +477,6 @@ const UniversalSearchResponse = { } } }; -const CORSHeaders = { 'access-control-allow-credentials': true, 'access-control-allow-origin': 'http://localhost:9999' }; export const MockedUniversalSearchRequest = RequestMock() .onRequestTo(async request => {