Skip to content

Commit

Permalink
added test for 'requestWasSuccessfull' option based on query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
melya committed Jul 1, 2021
1 parent fee9305 commit 9e9852a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/express-rate-limit-test.js
Expand Up @@ -458,6 +458,40 @@ describe("express-rate-limit node module", () => {
assert(!store.decrement_was_called, "decrement was not called on the store");
});

it("should decrement hits with success response with custom 'requestWasSuccessful' option based on query parameter", async () => {
const store = new MockStore();
createAppWith(
rateLimit({
skipSuccessfulRequests: true,
requestWasSuccessful: function (req) {
return req.query.success === "1";
},
store: store,
})
);

await request(app).get("/?success=1");

assert(store.decrement_was_called, "decrement was called on the store");
});

it("should not decrement hits with failed response with custom 'requestWasSuccessful' option based on query parameter", async () => {
const store = new MockStore();
createAppWith(
rateLimit({
skipSuccessfulRequests: true,
requestWasSuccessful: function (req) {
return req.query.success === "1";
},
store: store,
})
);

await request(app).get("/?success=0");

assert(!store.decrement_was_called, "decrement was not called on the store");
});

it("should decrement hits with failed response and skipFailedRequests", async () => {
const store = new MockStore();
createAppWith(
Expand Down

0 comments on commit 9e9852a

Please sign in to comment.