Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
fix(service): convert ms to secs in in increment-func (fixes #1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed May 13, 2023
1 parent 65cd3ca commit 8269a2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/throttler-storage-redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ export class ThrottlerStorageRedisService implements ThrottlerStorageRedis, OnMo
throw new TypeError('Expected timeToExpire to be a number');
}

return { totalHits, timeToExpire };
return {
totalHits,
timeToExpire: Math.ceil(timeToExpire / 1000),
};
}

onModuleDestroy() {
Expand Down
16 changes: 8 additions & 8 deletions test/controller.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe.each`
expect(response.headers).not.toMatchObject({
'x-ratelimit-limit': '2',
'x-ratelimit-remaining': '1',
'x-ratelimit-reset': /^\d+$/,
'x-ratelimit-reset': '10',
});
});
it('GET /ignore-user-agents', async () => {
Expand All @@ -94,7 +94,7 @@ describe.each`
expect(response.headers).not.toMatchObject({
'x-ratelimit-limit': '2',
'x-ratelimit-remaining': '1',
'x-ratelimit-reset': /^\d+$/,
'x-ratelimit-reset': '10',
});
});
it('GET /', async () => {
Expand All @@ -103,7 +103,7 @@ describe.each`
expect(response.headers).toMatchObject({
'x-ratelimit-limit': '2',
'x-ratelimit-remaining': '1',
'x-ratelimit-reset': /^\d+$/,
'x-ratelimit-reset': '10',
});
});
});
Expand All @@ -124,13 +124,13 @@ describe.each`
expect(response.headers).toMatchObject({
'x-ratelimit-limit': limit.toString(),
'x-ratelimit-remaining': (limit - (i + 1)).toString(),
'x-ratelimit-reset': /^\d+$/,
'x-ratelimit-reset': '10',
});
}
const errRes = await httPromise(appUrl + '/limit' + url, method);
expect(errRes.data).toMatchObject({ statusCode: 429, message: /ThrottlerException/ });
expect(errRes.headers).toMatchObject({
'retry-after': /^\d+$/,
'retry-after': '10',
});
expect(errRes.status).toBe(429);
},
Expand All @@ -147,15 +147,15 @@ describe.each`
expect(response.headers).toMatchObject({
'x-ratelimit-limit': limit.toString(),
'x-ratelimit-remaining': (limit - (i + 1)).toString(),
'x-ratelimit-reset': /^\d+$/,
'x-ratelimit-reset': '10',
});
} else {
expect(response.data).toMatchObject({
statusCode: 429,
message: /ThrottlerException/,
});
expect(response.headers).toMatchObject({
'retry-after': /^\d+$/,
'retry-after': '10',
});
expect(response.status).toBe(429);
}
Expand All @@ -172,7 +172,7 @@ describe.each`
expect(response.headers).toMatchObject({
'x-ratelimit-limit': '5',
'x-ratelimit-remaining': '4',
'x-ratelimit-reset': /^\d+$/,
'x-ratelimit-reset': '60',
});
});
});
Expand Down

0 comments on commit 8269a2b

Please sign in to comment.