Comparing version 5.3.8 to 5.4.0
@@ -11,13 +11,11 @@ 'use strict'; | ||
exports.default = function (options) { | ||
var url = options.url; | ||
var forceFail = options.forceFail; | ||
var onError = options.onError; | ||
var log = options.log; | ||
var backendOptions = options.backendOptions; | ||
var url = options.url, | ||
forceFail = options.forceFail, | ||
onError = options.onError, | ||
log = options.log, | ||
backendOptions = options.backendOptions; | ||
var _ref = backendOptions ? backendOptions : {}; | ||
var _ref = backendOptions ? backendOptions : {}, | ||
fetch = _ref.fetch; | ||
var fetch = _ref.fetch; | ||
var messageCallback = void 0; | ||
@@ -24,0 +22,0 @@ |
@@ -13,2 +13,3 @@ 'use strict'; | ||
exports.requestUse = requestUse; | ||
exports.mockReturn = mockReturn; | ||
exports.startMockingRequests = startMockingRequests; | ||
@@ -23,2 +24,4 @@ exports.stopMockingRequests = stopMockingRequests; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var backend = null; | ||
@@ -192,3 +195,3 @@ var backendSet = false; | ||
function prepareRequest(observer, request) { | ||
var tries = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2]; | ||
var tries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
@@ -225,3 +228,3 @@ | ||
function setBackend() { | ||
var _options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -301,2 +304,18 @@ if (useMiddlewareQueue.length > 1) { | ||
function mockReturn(key, value) { | ||
var argLength = arguments.length; | ||
startMockingRequests(); | ||
requestUse().subscribe(function (_ref) { | ||
var req = _ref.req, | ||
reply = _ref.reply; | ||
var replyObj = { header: _extends({}, req.headers, { statusCode: 200 }) }; | ||
if (argLength === 1) replyObj.body = key;else replyObj.body = _defineProperty({}, key, value); | ||
reply(replyObj); | ||
reset(); | ||
}); | ||
} | ||
/** | ||
@@ -303,0 +322,0 @@ * If mocking requests, don't require a backend |
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -42,6 +42,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
response: function response(_ref) { | ||
var req = _ref.req; | ||
var send = _ref.send; | ||
var reply = _ref.reply; | ||
var next = _ref.next; | ||
var req = _ref.req, | ||
send = _ref.send, | ||
reply = _ref.reply, | ||
next = _ref.next; | ||
@@ -262,4 +262,4 @@ reply({ | ||
}, function (_ref2) { | ||
var req = _ref2.req; | ||
var err = _ref2.err; | ||
var req = _ref2.req, | ||
err = _ref2.err; | ||
@@ -286,2 +286,39 @@ expect(err.__header.statusCode).toBe(404); | ||
}); | ||
it('should make mocking a single return value easy for a given end point using key and value for body', function () { | ||
var returnValue = [{ 'user1': 'hi' }]; | ||
(0, _request.mockReturn)('contacts', returnValue); | ||
(0, _rxws2.default)({ | ||
method: 'get', | ||
resource: 'email-accounts.contacts', | ||
parameters: { 'email-accounts': 1 } | ||
}).pluck('contacts').subscribe(function (value) { | ||
expect(value).toEqual(returnValue); | ||
}); | ||
var returnValue2 = [{ 'user2': 'hi' }]; | ||
(0, _request.mockReturn)('address', returnValue2); | ||
(0, _rxws2.default)({ | ||
method: 'get', | ||
resource: 'email-accounts.address', | ||
parameters: { 'email-accounts': 1 } | ||
}).pluck('address').subscribe(function (value) { | ||
expect(value).toEqual(returnValue2); | ||
}); | ||
}); | ||
it('should make mocking a single return value easy for a given end point passing entire body', function () { | ||
var returnValue = [{ 'user1': 'hi' }]; | ||
(0, _request.mockReturn)({ 'contacts': returnValue }); | ||
(0, _rxws2.default)({ | ||
method: 'get', | ||
resource: 'email-accounts.contacts', | ||
parameters: { 'email-accounts': 1 } | ||
}).pluck('contacts').subscribe(function (value) { | ||
expect(value).toEqual(returnValue); | ||
}); | ||
}); | ||
}); | ||
@@ -354,5 +391,5 @@ | ||
response: function response(_ref3) { | ||
var res = _ref3.res; | ||
var reply = _ref3.reply; | ||
var retry = _ref3.retry; | ||
var res = _ref3.res, | ||
reply = _ref3.reply, | ||
retry = _ref3.retry; | ||
@@ -394,6 +431,6 @@ reply(res); | ||
response1: function response1(_ref4) { | ||
var res = _ref4.res; | ||
var reply = _ref4.reply; | ||
var retry = _ref4.retry; | ||
var next = _ref4.next; | ||
var res = _ref4.res, | ||
reply = _ref4.reply, | ||
retry = _ref4.retry, | ||
next = _ref4.next; | ||
@@ -403,6 +440,6 @@ next(); | ||
response2: function response2(_ref5) { | ||
var res = _ref5.res; | ||
var reply = _ref5.reply; | ||
var retry = _ref5.retry; | ||
var next = _ref5.next; | ||
var res = _ref5.res, | ||
reply = _ref5.reply, | ||
retry = _ref5.retry, | ||
next = _ref5.next; | ||
@@ -412,6 +449,6 @@ next(); | ||
response3: function response3(_ref6) { | ||
var res = _ref6.res; | ||
var reply = _ref6.reply; | ||
var retry = _ref6.retry; | ||
var next = _ref6.next; | ||
var res = _ref6.res, | ||
reply = _ref6.reply, | ||
retry = _ref6.retry, | ||
next = _ref6.next; | ||
@@ -421,5 +458,5 @@ next(); | ||
response4: function response4(_ref7) { | ||
var res = _ref7.res; | ||
var reply = _ref7.reply; | ||
var retry = _ref7.retry; | ||
var res = _ref7.res, | ||
reply = _ref7.reply, | ||
retry = _ref7.retry; | ||
@@ -470,6 +507,6 @@ reply(res); | ||
response1: function response1(_ref8) { | ||
var res = _ref8.res; | ||
var reply = _ref8.reply; | ||
var retry = _ref8.retry; | ||
var next = _ref8.next; | ||
var res = _ref8.res, | ||
reply = _ref8.reply, | ||
retry = _ref8.retry, | ||
next = _ref8.next; | ||
@@ -479,6 +516,6 @@ next(); | ||
response2: function response2(_ref9) { | ||
var res = _ref9.res; | ||
var reply = _ref9.reply; | ||
var retry = _ref9.retry; | ||
var next = _ref9.next; | ||
var res = _ref9.res, | ||
reply = _ref9.reply, | ||
retry = _ref9.retry, | ||
next = _ref9.next; | ||
@@ -488,6 +525,6 @@ reply(res); | ||
response3: function response3(_ref10) { | ||
var res = _ref10.res; | ||
var reply = _ref10.reply; | ||
var retry = _ref10.retry; | ||
var next = _ref10.next; | ||
var res = _ref10.res, | ||
reply = _ref10.reply, | ||
retry = _ref10.retry, | ||
next = _ref10.next; | ||
@@ -497,5 +534,5 @@ next(); | ||
response4: function response4(_ref11) { | ||
var res = _ref11.res; | ||
var reply = _ref11.reply; | ||
var retry = _ref11.retry; | ||
var res = _ref11.res, | ||
reply = _ref11.reply, | ||
retry = _ref11.retry; | ||
@@ -546,5 +583,5 @@ reply(res); | ||
response: function response(_ref12) { | ||
var res = _ref12.res; | ||
var reply = _ref12.reply; | ||
var retry = _ref12.retry; | ||
var res = _ref12.res, | ||
reply = _ref12.reply, | ||
retry = _ref12.retry; | ||
@@ -551,0 +588,0 @@ retry(); |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.rx = exports.reset = exports.stopMockingRequests = exports.startMockingRequests = exports.requestUse = exports.use = exports.onNotification = exports.setBackend = exports.patch = exports.head = exports.put = exports.post = exports.get = exports.remove = undefined; | ||
exports.rx = exports.reset = exports.stopMockingRequests = exports.startMockingRequests = exports.mockReturn = exports.requestUse = exports.use = exports.onNotification = exports.setBackend = exports.patch = exports.head = exports.put = exports.post = exports.get = exports.remove = undefined; | ||
@@ -54,2 +54,3 @@ var _rx = require('rx'); | ||
_request2.default.requestUse = _request.requestUse; | ||
_request2.default.mockReturn = _request.mockReturn; | ||
@@ -71,2 +72,3 @@ _request2.default.startMockingRequests = _request.startMockingRequests; | ||
exports.requestUse = _request.requestUse; | ||
exports.mockReturn = _request.mockReturn; | ||
exports.startMockingRequests = _request.startMockingRequests; | ||
@@ -73,0 +75,0 @@ exports.stopMockingRequests = _request.stopMockingRequests; |
@@ -8,8 +8,8 @@ 'use strict'; | ||
exports.default = function (options) { | ||
var url = options.url; | ||
var forceFail = options.forceFail; | ||
var onSuccess = options.onSuccess; | ||
var onError = options.onError; | ||
var log = options.log; | ||
var backendOptions = options.backendOptions; | ||
var url = options.url, | ||
forceFail = options.forceFail, | ||
onSuccess = options.onSuccess, | ||
onError = options.onError, | ||
log = options.log, | ||
backendOptions = options.backendOptions; | ||
@@ -16,0 +16,0 @@ |
@@ -10,3 +10,3 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -54,3 +54,3 @@ exports.log = log; | ||
function log() { | ||
var level = arguments.length <= 0 || arguments[0] === undefined ? 5 : arguments[0]; | ||
var level = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5; | ||
var message = arguments[1]; | ||
@@ -121,4 +121,4 @@ | ||
onNext: function onNext(_ref) { | ||
var req = _ref.req; | ||
var send = _ref.send; | ||
var req = _ref.req, | ||
send = _ref.send; | ||
@@ -133,4 +133,4 @@ send(req); | ||
onNext: function onNext(_ref2) { | ||
var res = _ref2.res; | ||
var reply = _ref2.reply; | ||
var res = _ref2.res, | ||
reply = _ref2.reply; | ||
@@ -137,0 +137,0 @@ reply(res); |
@@ -71,3 +71,2 @@ 'use strict'; | ||
// doesn't throw | ||
// falsy, but valid | ||
makeRequest(); | ||
@@ -74,0 +73,0 @@ }); |
{ | ||
"name": "rxws", | ||
"version": "5.3.8", | ||
"version": "5.4.0", | ||
"description": "A RESTful reactive JavaScript implmentation on top of web sockets", | ||
@@ -5,0 +5,0 @@ "main": "lib/rxws.js", |
@@ -291,2 +291,18 @@ import { Observable } from 'rx'; | ||
export function mockReturn(key, value) { | ||
const argLength = arguments.length; | ||
startMockingRequests(); | ||
requestUse().subscribe(({req, reply}) => { | ||
const replyObj = {header: {...req.headers, statusCode: 200}}; | ||
if (argLength === 1) | ||
replyObj.body = key; | ||
else | ||
replyObj.body = {[key]: value}; | ||
reply(replyObj); | ||
reset(); | ||
}); | ||
} | ||
/** | ||
@@ -293,0 +309,0 @@ * If mocking requests, don't require a backend |
@@ -1,2 +0,2 @@ | ||
import makeRequest, { setBackend, reset, startMockingRequests, stopMockingRequests } from './request'; | ||
import makeRequest, { setBackend, reset, startMockingRequests, stopMockingRequests, mockReturn } from './request'; | ||
import remove from './remove'; | ||
@@ -270,2 +270,45 @@ import rxws from './rxws'; | ||
}) | ||
it('should make mocking a single return value easy for a given end point using key and value for body', () => { | ||
const returnValue = [{'user1': 'hi'}]; | ||
mockReturn('contacts', returnValue); | ||
rxws({ | ||
method: 'get', | ||
resource: 'email-accounts.contacts', | ||
parameters: {'email-accounts': 1}, | ||
}) | ||
.pluck('contacts') | ||
.subscribe(value => { | ||
expect(value).toEqual(returnValue); | ||
}); | ||
const returnValue2 = [{'user2': 'hi'}]; | ||
mockReturn('address', returnValue2); | ||
rxws({ | ||
method: 'get', | ||
resource: 'email-accounts.address', | ||
parameters: {'email-accounts': 1}, | ||
}) | ||
.pluck('address') | ||
.subscribe(value => { | ||
expect(value).toEqual(returnValue2); | ||
}); | ||
}); | ||
it('should make mocking a single return value easy for a given end point passing entire body', () => { | ||
const returnValue = [{'user1': 'hi'}]; | ||
mockReturn({'contacts': returnValue}); | ||
rxws({ | ||
method: 'get', | ||
resource: 'email-accounts.contacts', | ||
parameters: {'email-accounts': 1}, | ||
}) | ||
.pluck('contacts') | ||
.subscribe(value => { | ||
expect(value).toEqual(returnValue); | ||
}); | ||
}); | ||
}); | ||
@@ -272,0 +315,0 @@ |
@@ -14,2 +14,3 @@ import rx from 'rx'; | ||
requestUse, | ||
mockReturn, | ||
startMockingRequests, | ||
@@ -31,2 +32,3 @@ stopMockingRequests, | ||
makeRequest.requestUse = requestUse; | ||
makeRequest.mockReturn = mockReturn; | ||
@@ -50,2 +52,3 @@ makeRequest.startMockingRequests = startMockingRequests; | ||
export { mockReturn } | ||
export { startMockingRequests }; | ||
@@ -52,0 +55,0 @@ export { stopMockingRequests }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
164183
44
5153
22