Skip to content

Commit f2754a1

Browse files
committed
tests update
1 parent d077061 commit f2754a1

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

packages/service-utils/src/core/rateLimit/rateLimit.test.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const mockRedis = {
1010

1111
// Mocking the updateRateLimitedAt function
1212
vi.mock("../../../src/core/api", () => ({
13-
updateRateLimitedAt: vi.fn(),
13+
updateRateLimitedAt: vi.fn().mockResolvedValue({}),
1414
}));
1515

1616
describe("rateLimit", () => {
@@ -59,27 +59,8 @@ describe("rateLimit", () => {
5959
expect(mockRedis.expire).not.toHaveBeenCalled();
6060
});
6161

62-
it("should report rate limit if exceeded but not block", async () => {
63-
mockRedis.incr.mockResolvedValue(51); // Current count is 51 requests in 10 seconds.
64-
65-
const result = await rateLimit({
66-
project: validProjectResponse,
67-
limitPerSecond: 5,
68-
serviceConfig: validServiceConfig,
69-
redis: mockRedis,
70-
});
71-
72-
expect(result).toEqual({
73-
rateLimited: false,
74-
requestCount: 51,
75-
rateLimit: 50,
76-
});
77-
expect(updateRateLimitedAt).toHaveBeenCalled();
78-
expect(mockRedis.expire).not.toHaveBeenCalled();
79-
});
80-
8162
it("should rate limit if exceeded hard limit", async () => {
82-
mockRedis.incr.mockResolvedValue(101);
63+
mockRedis.incr.mockResolvedValue(51);
8364

8465
const result = await rateLimit({
8566
project: validProjectResponse,
@@ -90,7 +71,7 @@ describe("rateLimit", () => {
9071

9172
expect(result).toEqual({
9273
rateLimited: true,
93-
requestCount: 101,
74+
requestCount: 51,
9475
rateLimit: 50,
9576
status: 429,
9677
errorMessage: `You've exceeded your storage rate limit at 5 reqs/sec. To get higher rate limits, contact us at https://thirdweb.com/contact-us.`,
@@ -131,9 +112,13 @@ describe("rateLimit", () => {
131112
});
132113

133114
expect(result).toEqual({
134-
rateLimited: false,
115+
rateLimited: true,
135116
requestCount: 10,
136117
rateLimit: 5,
118+
status: 429,
119+
errorMessage:
120+
"You've exceeded your storage rate limit at 5 reqs/sec. To get higher rate limits, contact us at https://thirdweb.com/contact-us.",
121+
errorCode: "RATE_LIMIT_EXCEEDED",
137122
});
138123
});
139124

0 commit comments

Comments
 (0)