angular-mock-record
Advanced tools
Comparing version 1.5.3 to 1.6.0
@@ -17,15 +17,13 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
} | ||
MockUtilities.prototype.mockRequest = function (endpoint, mockResponse, method) { | ||
browser.executeScript(this.getMockRequest(endpoint, mockResponse)); | ||
MockUtilities.prototype.mockRequest = function (endpoint, mockResponse, matchOnQuery) { | ||
browser.executeScript(this.getMockRequest(endpoint, mockResponse, matchOnQuery)); | ||
}; | ||
MockUtilities.prototype.getMockRequest = function (endpoint, mockResponse, method) { | ||
MockUtilities.prototype.getMockRequest = function (endpoint, mockResponse, matchOnQuery) { | ||
var url = this.api_host + '/mock/' + endpoint; | ||
var xmlHttp = new XMLHttpRequest(); | ||
if (!method) { | ||
xmlHttp.open('POST', url, false); | ||
xmlHttp.open('POST', url, false); | ||
xmlHttp.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); | ||
if (matchOnQuery) { | ||
xmlHttp.setRequestHeader('Mock-Param', matchOnQuery); | ||
} | ||
else { | ||
xmlHttp.open(method, url, false); | ||
} | ||
xmlHttp.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); | ||
xmlHttp.send(JSON.stringify(mockResponse)); | ||
@@ -32,0 +30,0 @@ return xmlHttp.responseText; |
{ | ||
"name": "angular-mock-record", | ||
"version": "1.5.3", | ||
"version": "1.6.0", | ||
"description": "An angular / protractor framework that mocks and records requests. Requests can be manually mocked or recorded like VCR.", | ||
@@ -5,0 +5,0 @@ "main": "server.js", |
@@ -68,2 +68,17 @@ # angular-mock-record | ||
# Functionality | ||
- To set the client to login as (If not specified, product demo a is the default): | ||
`mockUtilities.setClient( clientOverride.getClientDomain(<client>) );` | ||
- To login and record authenticated requests, use: | ||
`mockUtilities.login(<user from idp auth>);` | ||
- To set a "context" and limit new recordings to the scope of that context: | ||
`mockUtilities.setContext(<name of context>);` | ||
- As usual, clear the mocks in the afterAll block at the end of the spec file. This will also reset context, client and login status: | ||
`mockUtilities.clearMocks();` | ||
# Running the server | ||
@@ -70,0 +85,0 @@ |
@@ -7,4 +7,7 @@ class Mock { | ||
setRequestAsMocked(res, path, response) { | ||
this.mockedRequests[ path.replace('mock/', '') ] = response; | ||
setRequestAsMocked(path, response, headers) { | ||
this.mockedRequests[ path.replace('mock/', '') ] = { | ||
response: response, | ||
headers: headers | ||
}; | ||
} | ||
@@ -11,0 +14,0 @@ |
@@ -30,3 +30,3 @@ const Http = require('./http.js'); | ||
this.mock.setRequestAsMocked(res, req.path, req.body); | ||
this.mock.setRequestAsMocked(req.path, req.body, req.headers); | ||
res.status(200).send(true); | ||
@@ -58,5 +58,5 @@ | ||
} else if (this.hasRequestBeenMocked(matchedPath)) { | ||
} else if (this.hasRequestBeenMocked(matchedPath, req.url)) { | ||
res.status(200).send(this.mock.mockedRequests[matchedPath]); | ||
res.status(200).send(this.mock.mockedRequests[matchedPath].response); | ||
@@ -106,4 +106,9 @@ } else { | ||
hasRequestBeenMocked(matchedPath) { | ||
return this.mock.mockedRequests[matchedPath]; | ||
hasRequestBeenMocked(matchedPath, matchedUrl) { | ||
const foundMock = this.mock.mockedRequests[matchedPath]; | ||
return !!( | ||
(foundMock && !foundMock.headers['mock-param']) || | ||
(foundMock && foundMock.headers['mock-param'] && matchedUrl.indexOf(foundMock.headers['mock-param']) > -1) | ||
); | ||
} | ||
@@ -110,0 +115,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20710
544
88