Skip to content

Commit

Permalink
fix(utils/testing): ensure API mock works with req.params and metho…
Browse files Browse the repository at this point in the history
…d chaining
  • Loading branch information
0x-r4bbit authored and iurimatias committed Feb 26, 2020
1 parent 62a2291 commit 1a56d5f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/utils/testing/src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 1a56d5f

Please sign in to comment.