Skip to content

Commit

Permalink
Fixed unit test, incorrect use resetAllMocks (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffersonGibin committed Apr 26, 2024
1 parent 5d80c6f commit 7f680de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/core/policies/rate-limit-per-period.policy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ describe("rate-limit-per-period.policy unit test", () => {
});

describe("method class saveHit", () => {
beforeEach(() => {
jest.resetAllMocks();
});

test("It's should call method saveHit the cache", async () => {
// 2023-02-23T13:19:50.000Z
const periodWindowStartMock = MOCK_LAST_TIME_REQUEST - 10000;
Expand Down Expand Up @@ -223,6 +219,12 @@ describe("rate-limit-per-period.policy unit test", () => {
test("It's shouldn't execute nothing when the period don't start", async () => {
// 2023-02-23T13:19:50.000Z
const periodDontStart = MOCK_LAST_TIME_REQUEST - 10000;

// 2023-02-23T13:20:00.000Z
const mockDate = new Date(MOCK_LAST_TIME_REQUEST);

jest.resetAllMocks();
jest.spyOn(mockDate, "getTime").mockReturnValue(MOCK_LAST_TIME_REQUEST);
jest.spyOn(Date, "now").mockReturnValue(periodDontStart);

jest
Expand Down
1 change: 0 additions & 1 deletion src/core/policies/rate-limit-per-period.policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export class RateLimitPerPeriodPolicy extends RateLimitPolicy {
const timestampNow = Date.now();
const periodWindowStart = this.policySettings?.periodWindowStart.getTime();
const periodWindowStarted = timestampNow >= periodWindowStart;

// If the period window will be started then save or update hit
if (periodWindowStarted) {
// If don't exists cache then save with value hit as ONE
Expand Down

0 comments on commit 7f680de

Please sign in to comment.