Clarify missing companyId error for malformed issues path

This commit is contained in:
Dotta
2026-03-06 14:25:34 -06:00
parent f49a003bd9
commit 5aecb148a2
2 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import express from "express";
import request from "supertest";
import { describe, expect, it, vi } from "vitest";
import { companyRoutes } from "../routes/companies.js";
vi.mock("../services/index.js", () => ({
companyService: () => ({
list: vi.fn(),
stats: vi.fn(),
getById: vi.fn(),
create: vi.fn(),
update: vi.fn(),
archive: vi.fn(),
remove: vi.fn(),
}),
companyPortabilityService: () => ({
exportBundle: vi.fn(),
previewImport: vi.fn(),
importBundle: vi.fn(),
}),
accessService: () => ({
canUser: vi.fn(),
ensureMembership: vi.fn(),
}),
logActivity: vi.fn(),
}));
describe("company routes malformed issue path guard", () => {
it("returns a clear error when companyId is missing for issues list path", async () => {
const app = express();
app.use((req, _res, next) => {
(req as any).actor = {
type: "agent",
agentId: "agent-1",
companyId: "company-1",
source: "agent_key",
};
next();
});
app.use("/api/companies", companyRoutes({} as any));
const res = await request(app).get("/api/companies/issues");
expect(res.status).toBe(400);
expect(res.body).toEqual({
error: "Missing companyId in path. Use /api/companies/{companyId}/issues.",
});
});
});