-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add remaining mocked responses for
Basic universal flow
test. (#1722)
This PR adds the ability to mock Universal AutoComplete responses. These mocked responses 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
1 parent
34159ee
commit db6cc3c
Showing
4 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const CORSHeaders = { 'access-control-allow-credentials': true, 'access-control-allow-origin': 'http://localhost:9999' }; |
53 changes: 53 additions & 0 deletions
53
tests/acceptance/fixtures/responses/universal/autocomplete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters