From 1ad3606b14d5e9f10b895c78b38a4934b24c5de8 Mon Sep 17 00:00:00 2001 From: Johnbastian Date: Thu, 12 Sep 2019 20:22:49 +0100 Subject: [PATCH] Code changed to maintain old reference behaviour in non-dev Tests updated --- .../validateObjectArgumentByReference.js | 6 +++ tests/globalize_test.js | 52 ++++++++++++++++--- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/lib/addMethod/globalize/validateObjectArgumentByReference.js b/lib/addMethod/globalize/validateObjectArgumentByReference.js index 3a33fbe..533cbce 100644 --- a/lib/addMethod/globalize/validateObjectArgumentByReference.js +++ b/lib/addMethod/globalize/validateObjectArgumentByReference.js @@ -17,12 +17,18 @@ module.exports = function (referenceModificationErrorMessage, nonObjectErrorMess } else { // eslint-disable-next-line no-console console.warn(referenceModificationErrorMessage); + //Maintain backwards compatibility in non-dev mode + return referencedObject; } } /* Need another cloneDeep, else originalObjectCopy variable becomes a reference for method config's function */ + /* + TODO: introduce breaking change to introduce via a flag + (which also avoids the return of the reference object above) + */ return _.cloneDeep(originalObjectCopy); } else if (_.isPlainObject(returnedObject)) { return returnedObject; diff --git a/tests/globalize_test.js b/tests/globalize_test.js index b0d2cda..e120831 100644 --- a/tests/globalize_test.js +++ b/tests/globalize_test.js @@ -390,7 +390,7 @@ describe('#globalize', function () { .then(done, done); }); - describe('should use original params if modified but not returned (and console warn)', function () { + describe('should use reference params if modified but not returned (and console warn)', function () { const sampleGlobal = { _globalOptions: { @@ -414,7 +414,13 @@ describe('#globalize', function () { it('global', function (done) { globalize.before.call(sampleGlobal, {}, _.cloneDeep(originalParams)) .then(function (params) { - assert.deepEqual(params, originalParams); + assert.deepEqual( + params, + { + id: 'abc123', + notes: 'Hello' + } + ); }) .then(done, done); }); @@ -426,7 +432,13 @@ describe('#globalize', function () { _.cloneDeep(originalParams) ) .then(function (params) { - assert.deepEqual(params, originalParams); + assert.deepEqual( + params, + { + id: 'abc123', + notes: ' World' + } + ); }) .then(done, done); }); @@ -438,7 +450,13 @@ describe('#globalize', function () { _.cloneDeep(originalParams) ) .then(function (params) { - assert.deepEqual(params, originalParams); + assert.deepEqual( + params, + { + id: 'abc123', + notes: 'Hello World' + } + ); }) .then(done, done); }); @@ -684,7 +702,7 @@ describe('#globalize', function () { .then(done, done); }); - describe('should use original request if modified but not returned (and console warn)', function () { + describe('should use reference request if modified but not returned (and console warn)', function () { const sampleGlobal = { _globalOptions: { @@ -708,7 +726,13 @@ describe('#globalize', function () { it('global', function (done) { globalize.beforeRequest.call(sampleGlobal, {}, _.cloneDeep(originalRequest)) .then(function (request) { - assert.deepEqual(request, originalRequest); + assert.deepEqual( + request, + { + method: 'get', + url: 'test.com?hello=world' + } + ); }) .then(done, done); }); @@ -720,7 +744,13 @@ describe('#globalize', function () { _.cloneDeep(originalRequest) ) .then(function (request) { - assert.deepEqual(request, originalRequest); + assert.deepEqual( + request, + { + method: 'get', + url: 'test.com&test=123' + } + ); }) .then(done, done); }); @@ -732,7 +762,13 @@ describe('#globalize', function () { _.cloneDeep(originalRequest) ) .then(function (request) { - assert.deepEqual(request, originalRequest); + assert.deepEqual( + request, + { + method: 'get', + url: 'test.com?hello=world&test=123' + } + ); }) .then(done, done); });