Skip to content

Commit

Permalink
Add remaining mocked responses for Basic universal flow test.
Browse files Browse the repository at this point in the history
This PR adds the ability to mock Universal AutoComplete responses. These
mocked reponses are used by the `Basic universal flow` test, in place of
hitting LiveAPI. The entire test is now using fully mocked LiveAPI responses.

TEST=auto

Ensured the acceptance test ran fine.
  • Loading branch information
tmeyer2115 committed Apr 15, 2022
1 parent 00c8a13 commit 8920685
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/acceptance/acceptancesuites/acceptancesuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
VERTICAL_SEARCH_URL_REGEX
} from '../constants';
import FacetsPage from '../pageobjects/facetspage';
import { MockedUniversalSearchRequest } from '../fixtures/responses/universal';
import { MockedUniversalAutoCompleteRequest, MockedUniversalSearchRequest } from '../fixtures/responses/universal';
import { Selector, RequestLogger } from 'testcafe';
import {
browserBackButton,
Expand All @@ -26,7 +26,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);
})
Expand Down
51 changes: 51 additions & 0 deletions tests/acceptance/fixtures/responses/universal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
import { RequestMock } from 'testcafe';

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.includes('a')) {
mockedResponse.response.results = [
{ value: 'amani farooque phone number', matchedSubstrings: [], queryIntents: [], verticalKeys: [] }
];
}

return mockedResponse;
}

const UniversalSearchResponse = {
meta: {
uuid: '0180235e-7fcd-5262-247b-d3537eea0002',
Expand Down Expand Up @@ -484,3 +523,15 @@ export const MockedUniversalSearchRequest = RequestMock()
return urlRegex.test(request.url) && request.method === 'get';
})
.respond(UniversalSearchResponse, 200, CORSHeaders);

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;
});

0 comments on commit 8920685

Please sign in to comment.