Skip to content

Commit

Permalink
Merge 8166424 into b50a7eb
Browse files Browse the repository at this point in the history
  • Loading branch information
yen-tt committed Jun 21, 2022
2 parents b50a7eb + 8166424 commit ba3aa54
Show file tree
Hide file tree
Showing 2 changed files with 270 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/acceptance/acceptancesuites/filtersearchsuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import {
browserForwardButton,
registerIE11NoCacheHook
} from '../utils';
import { MockedFilterSearchRequest } from '../fixtures/responses/filtersearch/search';
import { MockedVerticalSearchRequest } from '../fixtures/responses/vertical/search';
import SearchRequestLogger from '../searchrequestlogger';

fixture`Facets page`
.requestHooks(SearchRequestLogger.createVerticalSearchLogger())
.requestHooks([
SearchRequestLogger.createVerticalSearchLogger(),
MockedFilterSearchRequest,
MockedVerticalSearchRequest
])
.beforeEach(async t => {
await registerIE11NoCacheHook(t, VERTICAL_SEARCH_URL_REGEX);
})
Expand Down
263 changes: 263 additions & 0 deletions tests/acceptance/fixtures/responses/filtersearch/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
import { RequestMock } from 'testcafe';
import { CORSHeaders } from '../cors';

function generateFilterSearchResponse (input) {
const filterSearchResponse = {
meta: {
uuid: '01818675-b843-7a70-a198-e78a25c253c9',
errors: []
},
response: {
businessId: 3350634,
sections: [],
failedVerticals: [],
queryId: '01818675-b853-337d-b514-a999148a3c47'
}
};

const nyDataSections = [
{
results: [
{
key: 'builtin.location',
value: 'New York City, New York, United States',
filter: {
'builtin.location': {
$eq: 'P-place.2618194975855570'
}
},
matchedSubstrings: [
{ offset: 0, length: 3 },
{ offset: 4, length: 4 },
{ offset: 9, length: 4 },
{ offset: 15, length: 3 },
{ offset: 19, length: 4 },
{ offset: 25, length: 6 },
{ offset: 32, length: 6 }
]
},
{
key: 'builtin.location',
value: 'New York, New York, United States',
filter: {
'builtin.location': {
$eq: 'P-place.2618194975855571'
}
},
matchedSubstrings: [
{ offset: 0, length: 3 },
{ offset: 4, length: 4 },
{ offset: 10, length: 3 },
{ offset: 14, length: 4 },
{ offset: 20, length: 6 },
{ offset: 27, length: 6 }
]
},
{
key: 'builtin.location',
value: 'New York County, New York, United States',
filter: {
'builtin.location': {
$eq: 'P-district.12113562209855570'
}
},
matchedSubstrings: [
{ offset: 0, length: 3 },
{ offset: 4, length: 4 },
{ offset: 17, length: 3 },
{ offset: 21, length: 4 },
{ offset: 27, length: 6 },
{ offset: 34, length: 6 }
]
},
{
key: 'builtin.location',
value: 'York, New York, United States',
filter: {
'builtin.location': {
$eq: 'P-place.7548732089697590'
}
},
matchedSubstrings: [
{ offset: 0, length: 4 },
{ offset: 6, length: 3 },
{ offset: 10, length: 4 },
{ offset: 16, length: 6 },
{ offset: 23, length: 6 }
]
},
{
key: 'builtin.location',
value: 'Cork, New York, United States',
filter: {
'builtin.location': {
$eq: 'P-locality.10000148015185230'
}
},
matchedSubstrings: [
{ offset: 0, length: 4 },
{ offset: 6, length: 3 },
{ offset: 10, length: 4 },
{ offset: 16, length: 6 },
{ offset: 23, length: 6 }
]
}
]
}
];

const vaDataSections = [
{
results: [
{
key: 'builtin.location',
value: 'Virginia, United States',
filter: {
'builtin.location': {
$eq: 'P-region.7919684583758790'
}
},
matchedSubstrings: [
{ offset: 0, length: 8 },
{ offset: 10, length: 6 },
{ offset: 17, length: 6 }
]
},
{
key: 'builtin.location',
value: 'Virginia, Minnesota, United States',
filter: {
'builtin.location': {
$eq: 'P-place.16071886618758790'
}
},
matchedSubstrings: [
{ offset: 0, length: 8 },
{ offset: 21, length: 6 },
{ offset: 28, length: 6 }
]
},
{
key: 'builtin.location',
value: 'Virginia, Illinois, United States',
filter: {
'builtin.location': {
$eq: 'P-place.6439139614758790'
}
},
matchedSubstrings: [
{ offset: 0, length: 8 },
{ offset: 20, length: 6 },
{ offset: 27, length: 6 }
]
},
{
key: 'builtin.location',
value: 'Virginia, Missouri, United States',
filter: {
'builtin.location': {
$eq: 'P-locality.10000147694758790'
}
},
matchedSubstrings: [
{ offset: 0, length: 8 },
{ offset: 20, length: 6 },
{ offset: 27, length: 6 }
]
},
{
key: 'builtin.location',
value: 'Virginia, Nebraska, United States',
filter: {
'builtin.location': {
$eq: 'P-place.8464566402758790'
}
},
matchedSubstrings: [
{ offset: 0, length: 8 },
{ offset: 20, length: 6 },
{ offset: 27, length: 6 }
]
},
{
key: 'builtin.location',
value: 'Virginia, Kentucky, United States',
filter: {
'builtin.location': {
$eq: 'P-locality.14961075060758790'
}
},
matchedSubstrings: [
{ offset: 0, length: 8 },
{ offset: 20, length: 6 },
{ offset: 27, length: 6 }
]
},
{
key: 'builtin.location',
value: 'Virginia, South Dakota, United States',
filter: {
'builtin.location': {
$eq: 'P-locality.10000038934758790'
}
},
matchedSubstrings: [
{ offset: 0, length: 8 },
{ offset: 24, length: 6 },
{ offset: 31, length: 6 }
]
},
{
key: 'builtin.location',
value: 'Virginia, Idaho, United States',
filter: {
'builtin.location': {
$eq: 'P-locality.10000153938758790'
}
},
matchedSubstrings: [
{ offset: 0, length: 8 },
{ offset: 17, length: 6 },
{ offset: 24, length: 6 }
]
},
{
key: 'builtin.location',
value: 'Virgilia, California, United States',
filter: {
'builtin.location': {
$eq: 'P-locality.10000098529111390'
}
},
matchedSubstrings: [
{ offset: 0, length: 8 },
{ offset: 22, length: 6 },
{ offset: 29, length: 6 }
]
}
]
}
];

if (input.startsWith('Virginia')) {
filterSearchResponse.response.sections = vaDataSections;
} else if (input.startsWith('New York City')) {
filterSearchResponse.response.sections = nyDataSections;
}

return filterSearchResponse;
}

export const MockedFilterSearchRequest = RequestMock()
.onRequestTo(async request => {
const urlRegex = /^https:\/\/liveapi-cached.yext.com\/v2\/accounts\/me\/answers\/filtersearch/;
return urlRegex.test(request.url) && request.method === 'get';
})
.respond((req, res) => {
const parsedUrl = new URL(req.url);
res.body = JSON.stringify(generateFilterSearchResponse(
parsedUrl.searchParams.get('input')
));
res.headers = CORSHeaders;
res.statusCode = 200;
});

0 comments on commit ba3aa54

Please sign in to comment.