test: address CodeRabbit nitpicks - use toMatchInlineSnapshot and document as-any cast

Co-Authored-By: mantra <mantra@stack-auth.com>
This commit is contained in:
Devin AI 2026-06-19 00:47:53 +00:00
parent f6c524672f
commit defe617a71

View File

@ -8,9 +8,11 @@ vi.mock("./projects", () => ({
const mockListManagedProjectIds = vi.mocked(projects.listManagedProjectIds);
// Minimal stub satisfying the UsersCrud["Admin"]["Read"] shape required by the functions.
// The actual user object is only forwarded to listManagedProjectIds, which is mocked.
const fakeUser = { id: "user-1" } as Parameters<typeof isPlatformAdmin>[0];
// The actual user object is only forwarded to listManagedProjectIds, which is
// mocked, so the concrete shape doesn't matter. UsersCrud["Admin"]["Read"] is a
// large generated type; building a full fixture adds noise without value here.
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- see above
const fakeUser: Parameters<typeof isPlatformAdmin>[0] = { id: "user-1" } as any;
describe("isPlatformAdmin", () => {
it("returns true when user manages the internal project", async () => {
@ -38,16 +40,15 @@ describe("ensurePlatformAdmin", () => {
it("throws a 403 StatusError for non-platform-admins", async () => {
mockListManagedProjectIds.mockResolvedValue(["customer-project"]);
await expect(ensurePlatformAdmin(fakeUser)).rejects.toMatchObject({
statusCode: 403,
message: "You do not have access to platform analytics.",
});
await expect(ensurePlatformAdmin(fakeUser)).rejects.toMatchInlineSnapshot(
`[StatusError: You do not have access to platform analytics.]`
);
});
it("throws a 403 StatusError when user manages no projects at all", async () => {
mockListManagedProjectIds.mockResolvedValue([]);
await expect(ensurePlatformAdmin(fakeUser)).rejects.toMatchObject({
statusCode: 403,
});
await expect(ensurePlatformAdmin(fakeUser)).rejects.toMatchInlineSnapshot(
`[StatusError: You do not have access to platform analytics.]`
);
});
});