From 1a56d5f792e31d89cdda3d8394247de8c0738829 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Mon, 17 Feb 2020 12:21:29 +0100 Subject: [PATCH] fix(utils/testing): ensure API mock works with `req.params` and method chaining --- packages/utils/testing/src/plugin.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/utils/testing/src/plugin.js b/packages/utils/testing/src/plugin.js index 36e68cdee6..971e329b10 100644 --- a/packages/utils/testing/src/plugin.js +++ b/packages/utils/testing/src/plugin.js @@ -147,21 +147,22 @@ class PluginsMock { const apiFn = this.plugins.plugin.apiCalls[index]; assert(apiFn, `API call for '${method} ${endpoint}' wanted, but not registered`); - let req; + let req = {}; if (["GET", "DELETE"].includes(method.toUpperCase())) { - req = { - query: params - }; + if (params && params.params) { + req.params = params.params; + } + req.query = params; } else { req = { body: params }; } const resp = { - send: sinon.spy(), - status: sinon.spy() + send: sinon.spy() }; - apiFn(req, resp); + + resp.status = sinon.fake.returns(resp); return resp; } }