From 1fd208e2b1c5d60ffa9baf09f62585fa4c14f125 Mon Sep 17 00:00:00 2001 From: Clayton Tavares Date: Mon, 28 Sep 2026 12:55:05 +0700 Subject: [PATCH] fix(usage): forward `recurring` for codebuddy-intl quota packs (#4422) parseQuotaData had a dedicated case for codebuddy-cn that forwards the recurring field, but none for codebuddy-intl - even though getCodeBuddyIntlUsage (open-sse/services/usage/codebuddy-cn.js) returns the exact same quota shape, bonus packs included. Falling through to the default case dropped recurring, so one-shot bonus packs (recurring:false, resetAt = hard expiry) rendered as recurring and showed 'Reset in' instead of 'Expires in'. Share the codebuddy-cn case with codebuddy-intl. Fixes #4362 --- .../usage/components/ProviderLimits/utils.js | 3 +- .../codebuddy-intl-quota-recurring.test.js | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/unit/codebuddy-intl-quota-recurring.test.js diff --git a/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js b/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js index 769e6e82..9cb7ad71 100644 --- a/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js +++ b/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js @@ -619,7 +619,8 @@ export function parseQuotaData(provider, data) { break; case "codebuddy-cn": - // CodeBuddy CN mixes recurring refill packs ("Monthly"/"Weekly"/...) + case "codebuddy-intl": + // CodeBuddy CN/Intl mix recurring refill packs ("Monthly"/"Weekly"/...) // with one-shot bonus packs ("Bonus Pack N"). Forward `recurring` // so the UI can show "Expires in" for bonus packs (whose resetAt is // a hard expiry, not a refresh) instead of "Reset in". diff --git a/tests/unit/codebuddy-intl-quota-recurring.test.js b/tests/unit/codebuddy-intl-quota-recurring.test.js new file mode 100644 index 00000000..475ed16b --- /dev/null +++ b/tests/unit/codebuddy-intl-quota-recurring.test.js @@ -0,0 +1,32 @@ +// #4362: parseQuotaData had a dedicated `case "codebuddy-cn"` that forwards +// `recurring`, but no case for "codebuddy-intl" — which returns the exact same +// quota shape (open-sse/services/usage/codebuddy-cn.js → getCodeBuddyIntlUsage). +// Falling through to `default` dropped `recurring`, so one-shot bonus packs +// (recurring:false, resetAt = hard expiry) rendered as "Reset in" instead of +// "Expires in". +import { describe, expect, it } from "vitest"; + +import { parseQuotaData } from "../../src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js"; + +const quotas = { + Monthly: { used: 100, total: 1000, resetAt: "2026-11-01T00:00:00Z", recurring: true }, + "Bonus Pack 1": { used: 5, total: 50, resetAt: "2026-10-15T00:00:00Z", recurring: false }, +}; + +function byName(parsed, name) { + return parsed.find((q) => q.name === name); +} + +describe("parseQuotaData forwards `recurring` for codebuddy-intl (#4362)", () => { + it("marks a bonus pack as non-recurring, like codebuddy-cn does", () => { + const intl = parseQuotaData("codebuddy-intl", { quotas }); + expect(byName(intl, "Bonus Pack 1").recurring).toBe(false); + expect(byName(intl, "Monthly").recurring).toBe(true); + }); + + it("matches codebuddy-cn exactly for the same payload", () => { + const cn = parseQuotaData("codebuddy-cn", { quotas }); + const intl = parseQuotaData("codebuddy-intl", { quotas }); + expect(intl).toEqual(cn); + }); +});