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(web): omit unassigned userId when creating tasks (#1552)

aorightb69fae35a3a3
diff --git a/apps/web/src/fetchers/task/create-task.test.ts b/apps/web/src/fetchers/task/create-task.test.ts
new file mode 100644
index 000000000..d26847fe5
--- /dev/null
+++ b/apps/web/src/fetchers/task/create-task.test.ts
@@ -0,0 +1,73 @@
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import createTask from "./create-task";
+
+const mocks = vi.hoisted(() => ({
+ post: vi.fn(),
+}));
+
+vi.mock("@kaneo/libs", () => ({
+ client: {
+ task: {
+ ":projectId": {
+ $post: mocks.post,
+ },
+ },
+ },
+}));
+
+describe("createTask", () => {
+ beforeEach(() => {
+ mocks.post.mockReset();
+ mocks.post.mockResolvedValue({
+ ok: true,
+ json: async () => ({ id: "task-1" }),
+ });
+ });
+
+ it.each([undefined, ""])(
+ "omits the assignee when userId is %s",
+ async (userId) => {
+ await createTask(
+ "Unassigned task",
+ "",
+ "project-1",
+ userId,
+ "to-do",
+ undefined,
+ undefined,
+ "no-priority",
+ );
+
+ expect(mocks.post).toHaveBeenCalledWith({
+ json: {
+ title: "Unassigned task",
+ description: "",
+ status: "to-do",
+ startDate: undefined,
+ dueDate: undefined,
+ priority: "no-priority",
+ },
+ param: { projectId: "project-1" },
+ });
+ },
+ );
+
+ it("preserves an assigned userId", async () => {
+ await createTask(
+ "Assigned task",
+ "",
+ "project-1",
+ "user-1",
+ "to-do",
+ undefined,
+ undefined,
+ "no-priority",
+ );
+
+ expect(mocks.post).toHaveBeenCalledWith(
+ expect.objectContaining({
+ json: expect.objectContaining({ userId: "user-1" }),
+ }),
+ );
+ });
+});
diff --git a/apps/web/src/fetchers/task/create-task.ts b/apps/web/src/fetchers/task/create-task.ts
index 0729db2c0..d45a91b1e 100644
--- a/apps/web/src/fetchers/task/create-task.ts
+++ b/apps/web/src/fetchers/task/create-task.ts
@@ -10,7 +10,7 @@ async function createTask(
title: string,
description: string,
projectId: string,
- userId: string,
+ userId: string | undefined,
status: string,
startDate: Date | undefined,
dueDate: Date | undefined,
@@ -24,7 +24,7 @@ async function createTask(
json: {
title,
description,
- userId,
+ ...(userId ? { userId } : {}),
status,
startDate: startDate?.toISOString() || undefined,
dueDate: dueDate?.toISOString() || undefined,
diff --git a/apps/web/src/hooks/mutations/task/use-create-task.ts b/apps/web/src/hooks/mutations/task/use-create-task.ts
index b8c54540b..14f61dc39 100644
--- a/apps/web/src/hooks/mutations/task/use-create-task.ts
+++ b/apps/web/src/hooks/mutations/task/use-create-task.ts
@@ -21,7 +21,7 @@ function useCreateTask() {
title,
description,
projectId,
- userId ?? "",
+ userId,
status,
startDate ? new Date(startDate) : undefined,
dueDate ? new Date(dueDate) : undefined,