Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Rules' AND operator with empty rules always intercept the request #6

Closed
255kb opened this issue Apr 28, 2021 · 2 comments
Closed

Rules' AND operator with empty rules always intercept the request #6

255kb opened this issue Apr 28, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@255kb
Copy link
Member

255kb commented Apr 28, 2021

Describe the bug
Having empty rules with "AND" operator serves the corresponding response even if another response's rules match

To Reproduce

  • create 2 responses
  • set the first response's rules to AND, and remove all rules
  • add one rule on the second one
  • make a call that matches the second response, you get the first one

bug#6.zip

Expected behavior
We should get the second one

Mockoon version:
all

OS / OS version:
all

@255kb 255kb added the bug Something isn't working label Apr 28, 2021
@mauriceackel
Copy link

mauriceackel commented Apr 28, 2021

The error is this line

The problem is that Array.every returns true if the input array is empty.
Potential fix:

let response = this.routeResponses.find((routeResponse) => {
  if (routeResponse.rules.length === 0) {
    return false;
  }

  return routeResponse.rulesOperator === 'AND'
    ? routeResponse.rules.every(this.isValidRule)
    : routeResponse.rules.some(this.isValidRule);
});

Notice, that I also changed !!routeResponse.rules.find(this.isValidRule) to routeResponse.rules.some(this.isValidRule) and removed the unnecessary double negation at routeResponse.rules.every(this.isValidRule).

@255kb Can you double-checkt that this logic in fact behaves like the current one? Especially w.r.t. the early return/the if statement.

@255kb 255kb self-assigned this May 5, 2021
@255kb
Copy link
Member Author

255kb commented May 5, 2021

Thanks @mauriceackel your fix is indeed working!

@255kb 255kb closed this as completed in 9e6fb64 May 6, 2021
255kb pushed a commit to mockoon/mockoon that referenced this issue May 6, 2021
Also fix "undefined" being displayed in the modifier following the new request number rule addition.

See mockoon/commons-server#6
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

2 participants