Publish curated projectbrain source from 88fab8df1542019289e947f092c2b387e0825c60
This commit is contained in:
1 parent
48e72d07e0
commit
eca2891b07
45 files changed
+2697
-328
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import Fastify from "fastify";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { loadEnv } from "../src/config/env.js";
|
||||
import { registerOperatingSystemRoutes } from "../src/routes/operatingSystem.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ updateWorkDependencies: vi.fn() }));
|
||||
|
||||
vi.mock("../src/services/workGraph.js", () => ({
|
||||
claimReadyWork: vi.fn(),
|
||||
getProjectWorkGraph: vi.fn(),
|
||||
listWorkGraphHistory: vi.fn(),
|
||||
recordWorkCompletion: vi.fn(),
|
||||
reclaimExpiredWork: vi.fn(),
|
||||
releaseWork: vi.fn(),
|
||||
updateWorkDependencies: mocks.updateWorkDependencies,
|
||||
}));
|
||||
|
||||
const env = loadEnv({
|
||||
NODE_ENV: "test",
|
||||
PROJECTBRAIN_DATA_SOURCE: "database",
|
||||
DATABASE_URL: "postgresql://fixture:fixture@localhost:5432/projectbrain_fixture",
|
||||
PROJECTBRAIN_OWNER_USERNAME: "fixture-owner",
|
||||
PROJECTBRAIN_OWNER_PASSWORD: "fixture-only-owner-password",
|
||||
PROJECTBRAIN_AUTH_SECRET: "fixture-only-auth-secret-with-at-least-32-characters",
|
||||
});
|
||||
|
||||
describe("operating-system work-graph routes", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("maps an active work-graph lease conflict to 409 with the authenticated actor", async () => {
|
||||
mocks.updateWorkDependencies.mockRejectedValue(new Error("WORK_GRAPH_ACTIVE_LEASE"));
|
||||
const app = Fastify();
|
||||
app.decorateRequest("authUser", null);
|
||||
app.addHook("onRequest", async (request) => {
|
||||
request.authUser = {
|
||||
id: "member-id",
|
||||
username: "authenticated-member",
|
||||
role: "member",
|
||||
credentialVersion: 1,
|
||||
};
|
||||
});
|
||||
await registerOperatingSystemRoutes(app, { env });
|
||||
|
||||
try {
|
||||
const response = await app.inject({
|
||||
method: "PUT",
|
||||
url: "/api/projects/project-1/work-graph/node-1/dependencies",
|
||||
payload: { dependencyNodeIds: ["node-2"], actor: "forged-caller" },
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(409);
|
||||
expect(response.json().error.code).toBe("WORK_GRAPH_ACTIVE_LEASE");
|
||||
expect(mocks.updateWorkDependencies).toHaveBeenCalledWith(
|
||||
"project-1",
|
||||
"node-1",
|
||||
["node-2"],
|
||||
"authenticated-member",
|
||||
);
|
||||
} finally {
|
||||
await app.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user