Add tsoa create endpoints for orgs users and projects

This commit is contained in:
2026-03-03 16:06:30 +00:00
parent 8e223bfbec
commit 2d2aacf2c0
12 changed files with 803 additions and 63 deletions

View File

@@ -83,6 +83,76 @@ describe("mock task API", () => {
expect(response.body.organizations).toHaveLength(3);
});
it("creates an organization through the HTTP contract", async () => {
const app = createTestApp();
const response = await sendRequest(app, {
method: "POST",
url: "/orgs",
body: {
slug: "globex-systems",
name: "Globex Systems",
plan: "growth",
industry: "Manufacturing",
},
headers: {
"content-type": "application/json",
},
});
expect(response.status).toBe(201);
expect(response.body.organization.slug).toBe("globex-systems");
expect(response.body.organization.name).toBe("Globex Systems");
});
it("creates a user through the HTTP contract", async () => {
const app = createTestApp();
const response = await sendRequest(app, {
method: "POST",
url: "/users",
body: {
orgId: "org_acme",
fullName: "Iris Quinn",
email: "iris@acme.example",
role: "engineer",
timezone: "Europe/Dublin",
},
headers: {
"content-type": "application/json",
},
});
expect(response.status).toBe(201);
expect(response.body.user.orgId).toBe("org_acme");
expect(response.body.user.email).toBe("iris@acme.example");
});
it("creates a project through the HTTP contract", async () => {
const app = createTestApp();
const response = await sendRequest(app, {
method: "POST",
url: "/projects",
body: {
orgId: "org_acme",
key: "BIZ",
name: "Business Ops Dashboard",
status: "planning",
ownerUserId: "user_acme_1",
dueDate: "2026-06-30",
},
headers: {
"content-type": "application/json",
},
});
expect(response.status).toBe(201);
expect(response.body.project.orgId).toBe("org_acme");
expect(response.body.project.key).toBe("BIZ");
expect(response.body.project.ownerUserId).toBe("user_acme_1");
});
it("filters tasks by org and status", async () => {
const app = createTestApp();

View File

@@ -3,7 +3,17 @@ import { mkdtempSync, rmSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { reseedDatabase } from "../src/database";
import { createTask, getOrganizationSummary, getTaskDetail, listOrganizations, listTasks, updateTask } from "../src/repository";
import {
createOrganization,
createProject,
createTask,
createUser,
getOrganizationSummary,
getTaskDetail,
listOrganizations,
listTasks,
updateTask,
} from "../src/repository";
let tempDir: string | null = null;
@@ -62,6 +72,36 @@ describe("mock task repository", () => {
expect(updated?.assigneeUserId).toBeNull();
});
it("creates organization, user, and project records", () => {
const db = createDb();
const organization = createOrganization(db, {
slug: "zenith-labs",
name: "Zenith Labs",
plan: "starter",
industry: "Biotech",
});
const user = createUser(db, {
orgId: organization!.id as string,
fullName: "Nora Finch",
email: "nora@zenith.example",
role: "org_admin",
timezone: "Europe/Dublin",
});
const project = createProject(db, {
orgId: organization!.id as string,
key: "RND",
name: "Research Dashboard",
status: "planning",
ownerUserId: user!.id as string,
dueDate: "2026-09-01",
});
expect(organization?.slug).toBe("zenith-labs");
expect(user?.orgId).toBe(organization?.id);
expect(project?.ownerUserId).toBe(user?.id);
});
it("returns org summary status counts", () => {
const db = createDb();

View File

@@ -60,12 +60,15 @@ describe("tsoa swagger document", () => {
expect(operations.sort()).toEqual([
"GET /health",
"POST /orgs",
"GET /orgs",
"GET /orgs/{orgId}",
"GET /orgs/{orgId}/projects",
"GET /orgs/{orgId}/tasks",
"GET /users",
"POST /users",
"GET /projects",
"POST /projects",
"GET /tasks",
"POST /tasks",
"GET /tasks/{taskId}",
@@ -84,5 +87,8 @@ describe("tsoa swagger document", () => {
expect(schemas.CreateTaskRequest).toBeDefined();
expect(schemas.UpdateTaskRequest).toBeDefined();
expect(schemas.CreateOrganizationRequest).toBeDefined();
expect(schemas.CreateUserRequest).toBeDefined();
expect(schemas.CreateProjectRequest).toBeDefined();
});
});