Merge branch 'main' into v1-webscraper

This commit is contained in:
Nicolas 2024-08-27 16:16:40 -03:00
commit 88239d7211
3 changed files with 27 additions and 21 deletions

View File

@ -317,21 +317,21 @@ export async function supaCheckTeamCredits(team_id: string, credits: number) {
// Compare the adjusted total credits used with the credits allowed by the plan
if (adjustedCreditsUsed + credits > price.credits) {
await sendNotification(
team_id,
NotificationType.LIMIT_REACHED,
subscription.current_period_start,
subscription.current_period_end
);
// await sendNotification(
// team_id,
// NotificationType.LIMIT_REACHED,
// subscription.current_period_start,
// subscription.current_period_end
// );
return { success: false, message: "Insufficient credits, please upgrade!", remainingCredits: creditLimit - adjustedCreditsUsed };
} else if (creditUsagePercentage >= 0.8) {
// Send email notification for approaching credit limit
await sendNotification(
team_id,
NotificationType.APPROACHING_LIMIT,
subscription.current_period_start,
subscription.current_period_end
);
// await sendNotification(
// team_id,
// NotificationType.APPROACHING_LIMIT,
// subscription.current_period_start,
// subscription.current_period_end
// );
}
return { success: true, message: "Sufficient credits available", remainingCredits: creditLimit - adjustedCreditsUsed };

View File

@ -65,7 +65,7 @@ describe("Rate Limiter Service", () => {
"test-prefix:someToken",
"standard"
);
expect(limiter2.points).toBe(50);
expect(limiter2.points).toBe(100);
const limiter3 = getRateLimiter(
"search" as RateLimiterMode,
@ -188,14 +188,13 @@ describe("Rate Limiter Service", () => {
"test-prefix:someTokenXY",
"hobby"
);
// expect hobby to have 100 points
expect(limiter.points).toBe(10);
expect(limiter.points).toBe(20);
const consumePoints = 5;
const res = await limiter.consume("test-prefix:someTokenXY", consumePoints);
expect(res.consumedPoints).toBe(5);
expect(res.remainingPoints).toBe(5);
expect(res.remainingPoints).toBe(15);
});
it("should return the correct rate limiter for 'crawl' mode", () => {
@ -227,7 +226,7 @@ describe("Rate Limiter Service", () => {
"test-prefix:someToken",
"free"
);
expect(limiter.points).toBe(5);
expect(limiter.points).toBe(10);
const limiter2 = getRateLimiter(
"scrape" as RateLimiterMode,
@ -241,7 +240,14 @@ describe("Rate Limiter Service", () => {
"test-prefix:someToken",
"standard"
);
expect(limiter3.points).toBe(50);
expect(limiter3.points).toBe(100);
const limiter4 = getRateLimiter(
"scrape" as RateLimiterMode,
"test-prefix:someToken",
"growth"
);
expect(limiter4.points).toBe(1000);
});
it("should return the correct rate limiter for 'search' mode", () => {

View File

@ -18,12 +18,12 @@ const RATE_LIMITS = {
},
scrape: {
default: 20,
free: 5,
free: 10,
starter: 20,
standard: 100,
standardOld: 40,
scale: 500,
hobby: 10,
hobby: 20,
standardNew: 100,
standardnew: 100,
growth: 1000,
@ -115,7 +115,7 @@ export function getRateLimiter(
return testSuiteRateLimiter;
}
if(teamId === process.env.DEV_B_TEAM_ID) {
if(teamId && teamId === process.env.DEV_B_TEAM_ID) {
return devBRateLimiter;
}