Last active
January 15, 2019 11:02
-
-
Save prashantagarwal/c65d3a3f0c8ef730191f06cf0df7b737 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // I have stored the generated Mock URL as Collection Variable | |
| let snapshotURL = pm.variables.get('snapshotURL'), | |
| /* Create the path that was used in actual request. We will send it along with our Mock endpoint */ | |
| path = pm.request.url.path.join('/'); | |
| /* If request contains any query params then pass those as well to mock endpoint */ | |
| if (pm.request.url.query.count()) { | |
| let params = pm.request.url.query.map((q) => { | |
| return `${q.key}=${q.value}`; | |
| }) | |
| path = `${path}?${params.join('&')}`; | |
| } | |
| // This is the final mock request that we will use. | |
| let snapshotFetchOptions = { | |
| url: `${snapshotURL}/${path}`, | |
| method: pm.request.method | |
| }; | |
| // Make a call to the Mock endpoint to fetch the Snapshot | |
| pm.sendRequest(snapshotFetchOptions, function (err, res) { | |
| let snapshotResponse = res.json(); | |
| if (err || snapshotResponse.error) { | |
| return; | |
| } | |
| pm.test.skip(`Response should match its saved Snapshot`, () => { | |
| //Match the API response with the snapshot response | |
| pm.expect(pm.response.json()).to.eql(snapshotResponse); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment