mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-20 06:02:14 +03:00
feat: enhance GLM quota handling and add new quota labels for Z.AI
This commit is contained in:
@@ -95,15 +95,29 @@ test("MiniMax quota payloads use generic provider parsing and stale resets still
|
||||
assert.equal(providerLimitUtils.formatQuotaLabel(parsed[1].name), "Weekly");
|
||||
});
|
||||
|
||||
test("Z.AI quota labels render token and time limit usage", () => {
|
||||
assert.equal(providerLimitUtils.formatQuotaLabel("tokens"), "Tokens");
|
||||
assert.equal(providerLimitUtils.formatQuotaLabel("time_limit"), "Time Limit");
|
||||
test("Z.AI quota labels render 5h, weekly and monthly tool usage", () => {
|
||||
assert.equal(providerLimitUtils.formatQuotaLabel("5 Hours Quota"), "5 Hours");
|
||||
assert.equal(providerLimitUtils.formatQuotaLabel("Weekly Quota"), "Weekly");
|
||||
assert.equal(providerLimitUtils.formatQuotaLabel("Monthly Tools"), "Monthly Tools");
|
||||
|
||||
const future = new Date(Date.now() + 5 * 60_000).toISOString();
|
||||
const parsed = providerLimitUtils.parseQuotaData("zai", {
|
||||
quotas: {
|
||||
tokens: { used: 18, total: 100, remaining: 82, remainingPercentage: 82, resetAt: future },
|
||||
time_limit: {
|
||||
"5 Hours Quota": {
|
||||
used: 15,
|
||||
total: 100,
|
||||
remaining: 85,
|
||||
remainingPercentage: 85,
|
||||
resetAt: future,
|
||||
},
|
||||
"Weekly Quota": {
|
||||
used: 4,
|
||||
total: 100,
|
||||
remaining: 96,
|
||||
remainingPercentage: 96,
|
||||
resetAt: future,
|
||||
},
|
||||
"Monthly Tools": {
|
||||
used: 0,
|
||||
total: 100,
|
||||
remaining: 100,
|
||||
@@ -113,9 +127,11 @@ test("Z.AI quota labels render token and time limit usage", () => {
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(parsed.length, 2);
|
||||
assert.equal(parsed[0].name, "tokens");
|
||||
assert.equal(parsed[0].remainingPercentage, 82);
|
||||
assert.equal(parsed[1].name, "time_limit");
|
||||
assert.equal(parsed[1].remainingPercentage, 100);
|
||||
assert.equal(parsed.length, 3);
|
||||
assert.equal(parsed[0].name, "5 Hours Quota");
|
||||
assert.equal(parsed[0].remainingPercentage, 85);
|
||||
assert.equal(parsed[1].name, "Weekly Quota");
|
||||
assert.equal(parsed[1].remainingPercentage, 96);
|
||||
assert.equal(parsed[2].name, "Monthly Tools");
|
||||
assert.equal(parsed[2].remainingPercentage, 100);
|
||||
});
|
||||
|
||||
@@ -902,11 +902,21 @@ test("usage service covers Qwen, Qoder, GLM, Z.AI and GLMT branches", async () =
|
||||
limits: [
|
||||
{
|
||||
type: "TOKENS_LIMIT",
|
||||
percentage: "64",
|
||||
unit: 3,
|
||||
usage: 15,
|
||||
currentValue: 85,
|
||||
percentage: "15",
|
||||
nextResetTime: Date.now() + 120_000,
|
||||
},
|
||||
{
|
||||
type: "TOKENS_LIMIT",
|
||||
unit: 6,
|
||||
percentage: "64",
|
||||
nextResetTime: Date.now() + 604_800_000,
|
||||
},
|
||||
{
|
||||
type: "TIME_LIMIT",
|
||||
unit: 5,
|
||||
percentage: "7",
|
||||
nextResetTime: Date.now() + 300_000,
|
||||
},
|
||||
@@ -930,18 +940,21 @@ test("usage service covers Qwen, Qoder, GLM, Z.AI and GLMT branches", async () =
|
||||
providerSpecificData: { apiRegion: "invalid-region" },
|
||||
});
|
||||
assert.equal(glm.plan, "Pro");
|
||||
assert.equal(glm.quotas.tokens.used, 64);
|
||||
assert.equal(glm.quotas.tokens.remaining, 36);
|
||||
assert.equal(glm.quotas.time_limit.used, 7);
|
||||
assert.equal(glm.quotas.time_limit.remaining, 93);
|
||||
assert.equal(glm.quotas["5 Hours Quota"].used, 15);
|
||||
assert.equal(glm.quotas["5 Hours Quota"].remaining, 85);
|
||||
assert.equal(glm.quotas["Weekly Quota"].used, 64);
|
||||
assert.equal(glm.quotas["Weekly Quota"].remaining, 36);
|
||||
assert.equal(glm.quotas["Monthly Tools"].used, 7);
|
||||
assert.equal(glm.quotas["Monthly Tools"].remaining, 93);
|
||||
|
||||
const zai: any = await usageService.getUsageForProvider({
|
||||
provider: "zai",
|
||||
apiKey: "glm-key",
|
||||
});
|
||||
assert.equal(zai.plan, "Pro");
|
||||
assert.equal(zai.quotas.tokens.used, 64);
|
||||
assert.equal(zai.quotas.time_limit.remaining, 93);
|
||||
assert.equal(zai.quotas["5 Hours Quota"].used, 15);
|
||||
assert.equal(zai.quotas["Weekly Quota"].remaining, 36);
|
||||
assert.equal(zai.quotas["Monthly Tools"].remaining, 93);
|
||||
|
||||
const glmt: any = await usageService.getUsageForProvider({
|
||||
provider: "glmt",
|
||||
@@ -949,8 +962,8 @@ test("usage service covers Qwen, Qoder, GLM, Z.AI and GLMT branches", async () =
|
||||
providerSpecificData: { apiRegion: "international" },
|
||||
});
|
||||
assert.equal(glmt.plan, "Pro");
|
||||
assert.equal(glmt.quotas.tokens.used, 64);
|
||||
assert.equal(glmt.quotas.tokens.remaining, 36);
|
||||
assert.equal(glmt.quotas["5 Hours Quota"].used, 15);
|
||||
assert.equal(glmt.quotas["Weekly Quota"].remaining, 36);
|
||||
|
||||
globalThis.fetch = async () => new Response("nope", { status: 401 });
|
||||
await assert.rejects(
|
||||
|
||||
Reference in New Issue
Block a user