chore: resolve cubic comments

This commit is contained in:
Charlie Lamb
2026-04-20 13:49:04 +01:00
parent ce37e77be2
commit dcd2be574e
2 changed files with 73 additions and 1 deletions

View File

@@ -77,7 +77,24 @@ export const handleCheck = createRoute({
flag: null,
});
return c.json(fallbackResponse);
const featureToUse = ctx.features.find(
(feature) => feature.id === body.feature_id,
);
const transformedFallbackResponse = featureToUse
? applyResponseVersionChanges<CheckResponseV3>({
input: fallbackResponse,
targetVersion: ctx.apiVersion,
resource: AffectedResource.Check,
legacyData: {
noCusEnts: false,
featureToUse,
},
ctx,
})
: fallbackResponse;
return c.json(transformedFallbackResponse);
}
let response: CheckResponseV3;

View File

@@ -64,3 +64,58 @@ test(`${chalk.yellowBright("check-fallback: /check returns allowed=true on retry
CusService.getFull = originalGetFull;
}
}, 20000);
test(`${chalk.yellowBright("check-fallback-legacy: /check fallback applies response version transforms")}`, async () => {
const messagesItem = items.monthlyMessages({ includedUsage: 1000 });
const freeProd = products.base({
id: "check-fallback-legacy-free",
items: [messagesItem],
});
const { customerId } = await initScenario({
customerId: "check-fallback-legacy",
setup: [s.customer({ testClock: false }), s.products({ list: [freeProd] })],
actions: [s.attach({ productId: freeProd.id })],
});
const originalGetFull = CusService.getFull;
const app = createHonoApp();
try {
CusService.getFull = (async () => {
const error = new Error("simulated db outage") as Error & {
code: string;
};
error.code = "CONNECT_TIMEOUT";
throw error;
}) as typeof CusService.getFull;
const response = await app.fetch(
new Request("http://localhost/v1/balances.check", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.UNIT_TEST_AUTUMN_SECRET_KEY || ""}`,
"Content-Type": "application/json",
"x-api-version": ApiVersion.V1_Beta.toString(),
"x-skip-cache": "true",
},
body: JSON.stringify({
customer_id: customerId,
feature_id: TestFeature.Messages,
}),
}),
);
expect(response.status).toBe(200);
expect(await response.json()).toEqual({
allowed: false,
code: "feature_found",
customer_id: customerId,
feature_id: TestFeature.Messages,
entity_id: undefined,
required_balance: 1,
});
} finally {
CusService.getFull = originalGetFull;
}
}, 20000);