fix(utils/testing): ensure API mock works with `req.params` and method chaining

This commit is contained in:
Pascal Precht 2020-02-17 12:21:29 +01:00 committed by Iuri Matias
parent 62a229198b
commit 1a56d5f792
1 changed files with 8 additions and 7 deletions

View File

@ -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;
}
}