Skip to content

Commit dc91295

Browse files
committed
bring back the "all" parameter for tests
1 parent dcd7acc commit dc91295

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

packages/node-sdk/src/rate-limiter.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ export function newRateLimiter(windowSizeMs: number) {
1414
"windowSizeMs must be greater than 0",
1515
);
1616

17-
const lastAllowedTimestampsByKey: { [key: string]: number } = {};
17+
let lastAllowedTimestampsByKey: { [key: string]: number } = {};
18+
19+
function clearStale(all: boolean = false): void {
20+
if (all) {
21+
lastAllowedTimestampsByKey = {};
22+
}
1823

19-
function clearStale(): void {
2024
const expireBeforeTimestamp = Date.now() - windowSizeMs;
2125
const keys = Object.keys(lastAllowedTimestampsByKey);
2226

packages/node-sdk/test/client.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ describe("BucketClient", () => {
447447

448448
beforeEach(() => {
449449
vi.mocked(httpClient.post).mockResolvedValue({ body: { success: true } });
450-
client["rateLimiter"].clear(true);
450+
client["rateLimiter"].clearStale(true);
451451
});
452452

453453
it("should return a new client instance with the `user`, `company` and `other` set", async () => {
@@ -568,7 +568,7 @@ describe("BucketClient", () => {
568568
const client = new BucketClient(validOptions);
569569

570570
beforeEach(() => {
571-
client["rateLimiter"].clear(true);
571+
client["rateLimiter"].clearStale(true);
572572
});
573573

574574
// try with both string and number IDs
@@ -653,7 +653,7 @@ describe("BucketClient", () => {
653653
const client = new BucketClient(validOptions);
654654

655655
beforeEach(() => {
656-
client["rateLimiter"].clear(true);
656+
client["rateLimiter"].clearStale(true);
657657
});
658658

659659
test.each([
@@ -747,7 +747,7 @@ describe("BucketClient", () => {
747747
const client = new BucketClient(validOptions);
748748

749749
beforeEach(() => {
750-
client["rateLimiter"].clear(true);
750+
client["rateLimiter"].clearStale(true);
751751
});
752752

753753
test.each([
@@ -1411,7 +1411,7 @@ describe("BucketClient", () => {
14111411
},
14121412
);
14131413

1414-
client["rateLimiter"].clear(true);
1414+
client["rateLimiter"].clearStale(true);
14151415

14161416
httpClient.post.mockResolvedValue({
14171417
ok: true,
@@ -2449,7 +2449,7 @@ describe("BoundBucketClient", () => {
24492449
await client.flush();
24502450

24512451
vi.mocked(httpClient.post).mockClear();
2452-
client["rateLimiter"].clear(true);
2452+
client["rateLimiter"].clearStale(true);
24532453
});
24542454

24552455
it("should create a client instance", () => {

0 commit comments

Comments
 (0)