Skip to content

Commit

Permalink
fix(triggerEvents): fix response format for request with triggerEvents (
Browse files Browse the repository at this point in the history
#2546)

* fix(triggerEvents): fix format of response when triggerEvents active, the response was formatted twice

* chore(test): fixed test since response modified with triggerEvents
  • Loading branch information
QuentinRousselet authored Aug 8, 2024
1 parent 76a7bb9 commit ffed901
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/api/funnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,8 @@ class Funnel {
async executePluginRequest(request) {
try {
if (request.input.triggerEvents) {
return await this.processRequest(request);
const response = await this.processRequest(request);
return { ...response.result };
}
return await doAction(this.getController(request), request);
} catch (e) {
Expand Down
10 changes: 4 additions & 6 deletions test/api/funnel/executePluginRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,24 @@ describe("funnel.executePluginRequest", () => {

it("should trigger pipes if triggerEvent is enabled", async () => {
const request = new Request({
controller: "testme",
action: "succeed",
controller: "testme",
triggerEvents: true,
});

return funnel.executePluginRequest(request).then((response) => {
should(response).be.exactly(request);
return funnel.executePluginRequest(request).then(() => {
should(kuzzle.pipe).calledWith("testme:beforeSucceed");
should(kuzzle.pipe).calledWith("testme:afterSucceed");
});
});

it("should not trigger pipes if triggerEvent is disabled", async () => {
const request = new Request({
controller: "testme",
action: "succeed",
controller: "testme",
});

return funnel.executePluginRequest(request).then((response) => {
should(response).be.exactly(request);
return funnel.executePluginRequest(request).then(() => {
should(kuzzle.pipe).not.calledWith("testme:beforeSucceed");
should(kuzzle.pipe).not.calledWith("testme:afterSucceed");
});
Expand Down

0 comments on commit ffed901

Please sign in to comment.