Skip to content

Commit 9a50bb4

Browse files
authored
feat(credits-admin): show per-period allotment in subscription block (#369)
1 parent fe31b8c commit 9a50bb4

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/api/v2/credits-admin/handlers/account-view-get.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
effectiveSubscriptionStatus,
88
ENTITLED_SUBSCRIPTION_STATUSES,
99
} from "@/subscriptions/status";
10+
import { tierGrant } from "@/subscriptions/tier-config";
11+
import { requireSubscriptionTier } from "@/subscriptions/tiers";
1012
import { prisma } from "@/utils/prisma";
1113

1214
const DAY_MS = 24 * 60 * 60 * 1000;
@@ -54,6 +56,7 @@ export const accountViewGetHandler = async (
5456
environment: string | null;
5557
willRenew: boolean;
5658
isInTrial: boolean;
59+
perPeriodCredits: number;
5760
} | null = null;
5861
let periodConsumesCredits = 0;
5962

@@ -76,6 +79,10 @@ export const accountViewGetHandler = async (
7679
environment: subscription.environment ?? null,
7780
willRenew: subscription.willRenew,
7881
isInTrial: subscription.isInTrial,
82+
perPeriodCredits: tierGrant(
83+
requireSubscriptionTier(subscription.tier),
84+
subscription.period,
85+
).perPeriod,
7986
};
8087
}
8188

src/api/v2/credits-admin/handlers/admin-page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ function buildHTML(nonce: string, creditsPerUsd: number): string {
251251
"<tr><th>Effective status</th><td>" + esc(s.effectiveStatus) + "</td></tr>" +
252252
"<tr><th>Period</th><td>" + fmtDate(s.currentPeriodStart) + " → " + fmtDate(s.currentPeriodEnd) + "</td></tr>" +
253253
"<tr><th>Environment</th><td>" + esc(s.environment) + "</td></tr>" +
254+
"<tr><th>Allotment (per period)</th><td>" + fmtCredits(s.perPeriodCredits) + " credits</td></tr>" +
254255
"<tr><th>Period consumes</th><td>" + fmtCredits(j.periodConsumesCredits) + " credits</td></tr>" +
255256
"</tbody></table>";
256257
} else {

tests/credits-admin/account-view.integration.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type AccountViewBody = {
2323
environment: string | null;
2424
willRenew: boolean;
2525
isInTrial: boolean;
26+
perPeriodCredits: number;
2627
} | null;
2728
isEntitled: boolean;
2829
balanceCredits: string;
@@ -66,6 +67,7 @@ describe("GET /api/v2/credits-admin/accounts/:accountId", () => {
6667
expect(body.isEntitled).toBe(true);
6768
expect(body.subscription?.effectiveStatus).toBe("active");
6869
expect(BigInt(body.balanceCredits)).toBeGreaterThan(0n);
70+
expect(body.subscription?.perPeriodCredits).toBeGreaterThan(0);
6971
});
7072

7173
it("non-subscriber → no subscription, single wallet balance", async () => {

tests/credits-admin/admin-page.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@ describe("credits-admin page", () => {
4040
expect(res.text).toContain('id="usage-spark"');
4141
expect(res.text).toContain("usageDaily");
4242
});
43+
44+
it("renders the per-period allotment in the subscription block", async () => {
45+
const res = await adminRequest(app, false).get("/api/v2/credits-admin/");
46+
expect(res.text).toContain("Allotment");
47+
expect(res.text).toContain("perPeriodCredits");
48+
});
4349
});

0 commit comments

Comments
 (0)