Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(task): treat blank assignee id as unassigned on task creation

github-actions[bot]f5b3717fc021
diff --git a/apps/api/src/task/controllers/create-task.ts b/apps/api/src/task/controllers/create-task.ts
index 3c09065df..7f742afd8 100644
--- a/apps/api/src/task/controllers/create-task.ts
+++ b/apps/api/src/task/controllers/create-task.ts
@@ -30,13 +30,7 @@ async function createTask({
const resolvedStatus = status || "to-do";
const resolvedPriority = priority || "no-priority";
- const normalizedUserId = userId?.trim();
-
- if (userId !== undefined && normalizedUserId === "") {
- throw new HTTPException(400, {
- message: "Assignee id cannot be empty",
- });
- }
+ const normalizedUserId = userId?.trim() || undefined;
await assertValidTaskStatus(resolvedStatus, projectId);
diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.ts
index dde52831c..d984a02fe 100644
--- a/apps/api/src/task/index.ts
+++ b/apps/api/src/task/index.ts
@@ -196,7 +196,7 @@ const task = new Hono<{
dueDate: v.optional(v.string()),
priority: v.picklist(VALID_PRIORITIES),
status: v.string(),
- userId: v.optional(v.pipe(v.string(), v.minLength(1))),
+ userId: v.optional(v.string()),
}),
),
workspaceAccess.fromProject("projectId"),
diff --git a/tests/api-integration/task.test.ts b/tests/api-integration/task.test.ts
index 64bc4668b..fe4239a68 100644
--- a/tests/api-integration/task.test.ts
+++ b/tests/api-integration/task.test.ts
@@ -365,41 +365,52 @@ describe("API integration: task creation", () => {
});
});
- it("rejects task creation when the assignee userId is whitespace only", async () => {
- const member = await createWorkspaceMember();
- const { project } = await createProjectFixture({
- workspaceId: member.workspace.id,
- });
-
- mockAuthenticatedSession(member.user);
- const { app } = createApp();
-
- const response = await app.request(`/api/task/${project.id}`, {
- method: "POST",
- headers: {
- "content-type": "application/json",
- },
- body: JSON.stringify({
- title: "Blank assignee task",
- description: "Whitespace-only userId should be rejected",
- priority: "low",
- status: "to-do",
- userId: " ",
- }),
- });
-
- expect(response.status).toBe(400);
- await expect(response.text()).resolves.toContain(
- "Assignee id cannot be empty",
- );
-
- const persistedTask = await db.query.taskTable.findFirst({
- where: and(
- eq(schema.taskTable.projectId, project.id),
- eq(schema.taskTable.title, "Blank assignee task"),
- ),
- });
-
- expect(persistedTask).toBeUndefined();
- });
+ it.each([
+ ["empty", ""],
+ ["whitespace only", " "],
+ ])(
+ "creates an unassigned task when the assignee userId is %s",
+ async (label, userId) => {
+ const member = await createWorkspaceMember();
+ const { project } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+
+ const title = `Blank assignee task (${label})`;
+ const response = await app.request(`/api/task/${project.id}`, {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ },
+ body: JSON.stringify({
+ title,
+ description: "Blank userId means unassigned",
+ priority: "low",
+ status: "to-do",
+ userId,
+ }),
+ });
+
+ expect(response.status).toBe(200);
+ const payload = (await response.json()) as {
+ userId: string | null;
+ assigneeName?: string;
+ };
+
+ expect(payload.userId).toBeNull();
+ expect(payload.assigneeName).toBeUndefined();
+
+ const persistedTask = await db.query.taskTable.findFirst({
+ where: and(
+ eq(schema.taskTable.projectId, project.id),
+ eq(schema.taskTable.title, title),
+ ),
+ });
+
+ expect(persistedTask?.userId).toBeNull();
+ },
+ );
});