Skip to content

Commit

Permalink
Feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeyer2115 committed Apr 15, 2022
1 parent 50e2070 commit e153ed0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 53 deletions.
3 changes: 2 additions & 1 deletion tests/acceptance/acceptancesuites/acceptancesuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
VERTICAL_SEARCH_URL_REGEX
} from '../constants';
import FacetsPage from '../pageobjects/facetspage';
import { MockedUniversalAutoCompleteRequest, 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,
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/fixtures/responses/cors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions tests/acceptance/fixtures/responses/universal/autocomplete.js
Original file line number Diff line number Diff line change
@@ -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;
});
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
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.startsWith('a')) {
mockedResponse.response.results = [
{ value: 'amani farooque phone number', matchedSubstrings: [], queryIntents: [], verticalKeys: [] }
];
}

return mockedResponse;
}
import { CORSHeaders } from '../cors';

const UniversalSearchResponse = {
meta: {
Expand Down Expand Up @@ -515,23 +477,10 @@ const UniversalSearchResponse = {
}
}
};
const CORSHeaders = { 'access-control-allow-credentials': true, 'access-control-allow-origin': 'http://localhost:9999' };

export const MockedUniversalSearchRequest = RequestMock()
.onRequestTo(async request => {
const urlRegex = /^https:\/\/liveapi.yext.com\/v2\/accounts\/me\/answers\/query\?input=amani\+farooque\+phone\+number/;
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 e153ed0

Please sign in to comment.