test(coach): seed the budget-refusal integration test at the user-plan cap

The daily cap is now provider-aware; the seeded chain resolves to a
user-egress provider, so the refusal must be seeded at USER_PLAN_CAP
rather than the smaller operator cap to trip the gate.
This commit is contained in:
Marc-André Bombeck committed 2026-06-26 14:17:36 +02:00
1 parent 5f640e1420
commit e818178be8
1 file changed
+7 -3
+7 -3
View File
@@ -24,7 +24,7 @@ process.env.ENCRYPTION_KEY ??=
import { cookieJar, headerJar } from "./mock-next-headers";
import { getPrismaClient, truncateAllTables } from "./setup";
import { OPERATOR_COST_CAP } from "@/lib/ai/coach/budget";
import { USER_PLAN_CAP } from "@/lib/ai/coach/budget";
vi.mock("next/headers", async () => {
const { cookieJar, headerJar } = await import("./mock-next-headers");
@@ -223,11 +223,15 @@ describe("POST /api/insights/chat — integration", () => {
const { userId } = await seedUserWithSession();
const prisma = getPrismaClient();
const dateKey = new Date().toISOString().slice(0, 10);
// v1.21.0 — the daily cap is now provider-aware: the seeded user resolves
// to a user-egress chain, so the applicable ceiling is USER_PLAN_CAP. Seed
// the spend at that ceiling so the reservation trips the gate. (Seeding the
// smaller operator cap would no longer refuse on this chain.)
await prisma.coachUsage.create({
data: {
userId,
dateKey,
totalTokens: OPERATOR_COST_CAP,
totalTokens: USER_PLAN_CAP,
messageCount: 50,
},
});
@@ -251,7 +255,7 @@ describe("POST /api/insights/chat — integration", () => {
const usage = await prisma.coachUsage.findUnique({
where: { userId_dateKey: { userId, dateKey } },
});
expect(usage?.totalTokens).toBe(OPERATOR_COST_CAP);
expect(usage?.totalTokens).toBe(USER_PLAN_CAP);
});
it("returns 404 (not 403) when conversationId belongs to another user", async () => {