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(board): preserve cached views and drain fallback detail events

Tin8899e639bc81
diff --git a/apps/api/src/plugins/gitea/webhooks/issue-edited.ts b/apps/api/src/plugins/gitea/webhooks/issue-edited.ts
index cbd66b218..b609982eb 100644
--- a/apps/api/src/plugins/gitea/webhooks/issue-edited.ts
+++ b/apps/api/src/plugins/gitea/webhooks/issue-edited.ts
@@ -1,4 +1,3 @@
-import { publishEvent } from "../../../events";
import { eq } from "drizzle-orm";
import db from "../../../database";
import { taskTable } from "../../../database/schema";
@@ -154,9 +153,6 @@ export async function handleGiteaIssueEdited(
title: issue.title,
metadata: updatedMetadata,
});
- await publishEvent("project.updated", {
- projectId: integration.projectId,
- });
}
return;
diff --git a/apps/api/src/plugins/gitea/webhooks/issue-labeled.ts b/apps/api/src/plugins/gitea/webhooks/issue-labeled.ts
index 57f859996..f0057cba4 100644
--- a/apps/api/src/plugins/gitea/webhooks/issue-labeled.ts
+++ b/apps/api/src/plugins/gitea/webhooks/issue-labeled.ts
@@ -190,26 +190,15 @@ export async function handleGiteaIssueLabeled(
task.project.workspaceId,
giteaLabelsForSync(issue.labels),
);
- await publishEvent("project.updated", {
- projectId: integration.projectId,
- });
}
continue;
}
if (!addedLabel) {
- if (priority)
- await publishEvent("project.updated", {
- projectId: integration.projectId,
- });
continue;
}
if (isSystemLabelName(addedLabel.name)) {
- if (priority)
- await publishEvent("project.updated", {
- projectId: integration.projectId,
- });
continue;
}
@@ -263,9 +252,6 @@ export async function handleGiteaIssueLabeled(
await db.delete(labelTable).where(eq(labelTable.id, label.id));
}
}
- await publishEvent("project.updated", {
- projectId: integration.projectId,
- });
} catch (error) {
console.error("Gitea issue_labeled handler failed for integration", {
integrationId: integration.id,
diff --git a/apps/api/src/plugins/github/webhooks/issue-edited.ts b/apps/api/src/plugins/github/webhooks/issue-edited.ts
index 86bcc2312..8847206bc 100644
--- a/apps/api/src/plugins/github/webhooks/issue-edited.ts
+++ b/apps/api/src/plugins/github/webhooks/issue-edited.ts
@@ -1,4 +1,3 @@
-import { publishEvent } from "../../../events";
import { eq } from "drizzle-orm";
import db from "../../../database";
import { taskTable } from "../../../database/schema";
@@ -182,9 +181,6 @@ export async function handleIssueEdited(payload: IssueEditedPayload) {
title: issue.title,
metadata: updatedMetadata,
});
- await publishEvent("project.updated", {
- projectId: integration.projectId,
- });
console.log(
`Synced ${Object.keys(updateData).join(", ")} from GitHub issue #${issue.number} to task ${task.id}`,
diff --git a/apps/api/src/plugins/github/webhooks/issue-labeled.ts b/apps/api/src/plugins/github/webhooks/issue-labeled.ts
index d2a98c398..63252bec6 100644
--- a/apps/api/src/plugins/github/webhooks/issue-labeled.ts
+++ b/apps/api/src/plugins/github/webhooks/issue-labeled.ts
@@ -76,10 +76,6 @@ export async function handleIssueLabeled(payload: IssueLabeledPayload) {
}
if (!addedLabel) {
- if (priority)
- await publishEvent("project.updated", {
- projectId: integration.projectId,
- });
return;
}
@@ -88,10 +84,6 @@ export async function handleIssueLabeled(payload: IssueLabeledPayload) {
addedLabel.name.startsWith("status:");
if (isSystemLabel) {
- if (priority)
- await publishEvent("project.updated", {
- projectId: integration.projectId,
- });
return;
}
@@ -144,7 +136,6 @@ export async function handleIssueLabeled(payload: IssueLabeledPayload) {
}
}
- await publishEvent("project.updated", { projectId: integration.projectId });
return;
}
}
diff --git a/apps/api/src/plugins/gitlab/webhooks/issue-updated.ts b/apps/api/src/plugins/gitlab/webhooks/issue-updated.ts
index f471f51f8..ba3375d71 100644
--- a/apps/api/src/plugins/gitlab/webhooks/issue-updated.ts
+++ b/apps/api/src/plugins/gitlab/webhooks/issue-updated.ts
@@ -216,9 +216,6 @@ export async function handleGitlabIssueUpdated(
title: issue.title,
metadata,
});
- await publishEvent("project.updated", {
- projectId: integration.projectId,
- });
}
}
@@ -269,9 +266,6 @@ export async function handleGitlabIssueUpdated(
nonSystemLabels(currentLabels),
changes?.labels?.previous,
);
- await publishEvent("project.updated", {
- projectId: integration.projectId,
- });
}
} catch (error) {
console.error("GitLab issue update handler failed for integration", {
diff --git a/apps/web/src/hooks/use-project-websocket-cache.test.tsx b/apps/web/src/hooks/use-project-websocket-cache.test.tsx
index b4086c6f7..1ca88fa0e 100644
--- a/apps/web/src/hooks/use-project-websocket-cache.test.tsx
+++ b/apps/web/src/hooks/use-project-websocket-cache.test.tsx
@@ -428,3 +428,48 @@ it.each(["TASK_UPDATED", "TASK_CREATED", "TASK_MOVED", "TASK_LABEL_UPDATED"])(
});
},
);
+
+it("drains queued detail events after retries fall back to polling", async () => {
+ vi.useFakeTimers();
+ try {
+ mocks.client.getQueryState.mockReturnValue({ fetchStatus: "fetching" });
+ renderHook(() => useProjectWebSocket("p"));
+ Socket.current.message("COMMENT_UPDATED", { taskId: "a" });
+ Socket.current.message("TASK_LABEL_UPDATED", { taskId: "a" });
+ Socket.current.message("TASK_UPDATED", { taskId: "a" });
+ Socket.current.message("TASK_RELATION_UPDATED", {
+ sourceTaskId: "a",
+ targetTaskId: "b",
+ });
+ for (const delay of [1000, 2000, 4000, 8000, 16000]) {
+ Socket.current.onclose?.();
+ await vi.advanceTimersByTimeAsync(delay);
+ }
+ Socket.current.onclose?.();
+ mocks.client.invalidateQueries.mockClear();
+ mocks.getTask.mockClear();
+ mocks.client.getQueryState.mockReturnValue({ fetchStatus: "idle" });
+ const listener = mocks.subscribe.mock.calls[0][0] as (
+ event: unknown,
+ ) => void;
+ listener({
+ query: { queryKey: ["tasks", "p"], state: { fetchStatus: "idle" } },
+ });
+ await vi.runAllTicks();
+ for (const key of [
+ ["comments", "a"],
+ ["activities", "a"],
+ ["labels", "a"],
+ ["task", "a"],
+ ["external-links", "a"],
+ ["task-relations", "b"],
+ ])
+ expect(mocks.client.invalidateQueries).toHaveBeenCalledWith({
+ queryKey: key,
+ });
+ expect(mocks.getTask).not.toHaveBeenCalled();
+ } finally {
+ cleanup();
+ vi.useRealTimers();
+ }
+});
diff --git a/apps/web/src/hooks/use-project-websocket.ts b/apps/web/src/hooks/use-project-websocket.ts
index 4c6c52f26..8139d4591 100644
--- a/apps/web/src/hooks/use-project-websocket.ts
+++ b/apps/web/src/hooks/use-project-websocket.ts
@@ -62,6 +62,70 @@ export function useProjectWebSocket(projectId: string) {
let pingInterval: ReturnType<typeof setInterval> | null = null;
let fallbackInterval: ReturnType<typeof setInterval> | null = null;
+ function invalidateDetails(message: {
+ type: string;
+ taskId?: string;
+ sourceTaskId?: string;
+ targetTaskId?: string;
+ }) {
+ if (message.type === "PROJECT_UPDATED") {
+ queryClient.invalidateQueries({ queryKey: ["projects"] });
+ return;
+ }
+
+ if (message.type === "TASK_RELATION_UPDATED") {
+ if (message.sourceTaskId) {
+ queryClient.invalidateQueries({
+ queryKey: ["task", message.sourceTaskId],
+ });
+ queryClient.invalidateQueries({
+ queryKey: ["task-relations", message.sourceTaskId],
+ });
+ }
+ if (message.targetTaskId) {
+ queryClient.invalidateQueries({
+ queryKey: ["task", message.targetTaskId],
+ });
+ queryClient.invalidateQueries({
+ queryKey: ["task-relations", message.targetTaskId],
+ });
+ }
+ if (!message.sourceTaskId && !message.targetTaskId) {
+ queryClient.invalidateQueries({
+ queryKey: ["task-relations"],
+ });
+ }
+ } else {
+ queryClient.invalidateQueries({
+ queryKey: ["task", message.taskId],
+ });
+ }
+
+ if (message.type === "TASK_LABEL_UPDATED") {
+ queryClient.invalidateQueries({
+ queryKey: ["labels", message.taskId],
+ });
+ }
+
+ if (
+ (message.type === "TASK_UPDATED" || message.type === "TASK_MOVED") &&
+ message.taskId
+ ) {
+ queryClient.invalidateQueries({
+ queryKey: ["external-links", message.taskId],
+ });
+ }
+
+ if (message.type === "COMMENT_UPDATED") {
+ queryClient.invalidateQueries({
+ queryKey: ["activities", message.taskId],
+ });
+ queryClient.invalidateQueries({
+ queryKey: ["comments", message.taskId],
+ });
+ }
+ }
+
function clearPing() {
if (pingInterval !== null) {
clearInterval(pingInterval);
@@ -346,63 +410,7 @@ export function useProjectWebSocket(projectId: string) {
}
}
- if (message.type === "PROJECT_UPDATED") {
- queryClient.invalidateQueries({ queryKey: ["projects"] });
- return;
- }
-
- if (message.type === "TASK_RELATION_UPDATED") {
- if (message.sourceTaskId) {
- queryClient.invalidateQueries({
- queryKey: ["task", message.sourceTaskId],
- });
- queryClient.invalidateQueries({
- queryKey: ["task-relations", message.sourceTaskId],
- });
- }
- if (message.targetTaskId) {
- queryClient.invalidateQueries({
- queryKey: ["task", message.targetTaskId],
- });
- queryClient.invalidateQueries({
- queryKey: ["task-relations", message.targetTaskId],
- });
- }
- if (!message.sourceTaskId && !message.targetTaskId) {
- queryClient.invalidateQueries({
- queryKey: ["task-relations"],
- });
- }
- } else {
- queryClient.invalidateQueries({
- queryKey: ["task", message.taskId],
- });
- }
-
- if (message.type === "TASK_LABEL_UPDATED") {
- queryClient.invalidateQueries({
- queryKey: ["labels", message.taskId],
- });
- }
-
- if (
- (message.type === "TASK_UPDATED" ||
- message.type === "TASK_MOVED") &&
- message.taskId
- ) {
- queryClient.invalidateQueries({
- queryKey: ["external-links", message.taskId],
- });
- }
-
- if (message.type === "COMMENT_UPDATED") {
- queryClient.invalidateQueries({
- queryKey: ["activities", message.taskId],
- });
- queryClient.invalidateQueries({
- queryKey: ["comments", message.taskId],
- });
- }
+ invalidateDetails(message);
}
} catch {
// Ignore malformed messages
@@ -429,6 +437,7 @@ export function useProjectWebSocket(projectId: string) {
queryKey: ["tasks", projectId],
});
}, 30_000);
+ flushPending();
}
};
}
@@ -446,7 +455,7 @@ export function useProjectWebSocket(projectId: string) {
flushQueued = false;
if (
disposed ||
- !activeSocket ||
+ (!activeSocket && fallbackInterval === null) ||
queryClient.getQueryState(["tasks", projectId])?.fetchStatus ===
"fetching"
)
@@ -460,8 +469,19 @@ export function useProjectWebSocket(projectId: string) {
}
const messages = Array.from(pendingMessages.values());
pendingMessages.clear();
- for (const data of messages)
- activeSocket.onmessage?.(new MessageEvent("message", { data }));
+ for (const data of messages) {
+ if (activeSocket)
+ activeSocket.onmessage?.(new MessageEvent("message", { data }));
+ else {
+ // Fallback polling repairs the board; queued detail events still
+ // need to refresh their own caches after pagination finishes.
+ try {
+ invalidateDetails(JSON.parse(data));
+ } catch {
+ /* Malformed message. */
+ }
+ }
+ }
});
}
const unsubscribe = queryClient.getQueryCache().subscribe(({ query }) => {
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.test.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.test.tsx
new file mode 100644
index 000000000..6bb6bd40b
--- /dev/null
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.test.tsx
@@ -0,0 +1,107 @@
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import type { ComponentType, ReactNode } from "react";
+import { afterEach, expect, it, vi } from "vite-plus/test";
+import { Route } from "./board";
+const m = vi.hoisted(() => ({
+ project: {
+ id: "p",
+ name: "Project",
+ columns: [],
+ plannedTasks: [],
+ archivedTasks: [],
+ } as unknown,
+ retry: vi.fn(),
+}));
+vi.mock("@tanstack/react-router", () => ({
+ createFileRoute: () => (options: unknown) => ({
+ ...(options as object),
+ useParams: () => ({ projectId: "p", workspaceId: "w" }),
+ useSearch: () => ({}),
+ }),
+ useNavigate: () => vi.fn(),
+}));
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+vi.mock("@/hooks/queries/task/use-get-tasks", () => ({
+ useGetTasks: () => ({
+ data: m.project,
+ isError: true,
+ isFetching: false,
+ refetch: m.retry,
+ }),
+}));
+vi.mock("@/store/project", () => ({
+ default: () => ({ project: m.project, setProject: vi.fn() }),
+}));
+vi.mock("@/store/user-preferences", () => ({
+ useUserPreferencesStore: () => ({ viewMode: "board", setViewMode: vi.fn() }),
+}));
+vi.mock("@/store/background", () => ({
+ useBackgroundStore: () => ({ background: null }),
+}));
+vi.mock("@/hooks/use-board-sort", () => ({
+ useBoardSort: () => ({ sort: { field: "position" }, setSort: vi.fn() }),
+}));
+vi.mock("@/hooks/use-keyboard-shortcuts", () => ({
+ useRegisterShortcuts: vi.fn(),
+ getModifierKeyText: () => "Ctrl",
+}));
+vi.mock("@/hooks/queries/task/use-description-matches", () => ({
+ useDescriptionMatches: () => ({ ids: [], isLoading: false, isError: false }),
+}));
+vi.mock("@/hooks/use-task-filters-with-labels-support", () => ({
+ useTaskFiltersWithLabelsSupport: () => ({
+ filteredProject: m.project,
+ filters: {},
+ hasActiveFilters: false,
+ }),
+}));
+vi.mock(
+ "@/hooks/queries/custom-field/use-get-custom-fields-by-project",
+ () => ({ default: () => ({ data: [] }) }),
+);
+vi.mock(
+ "@/hooks/queries/custom-field/use-get-custom-field-filter-values",
+ () => ({ default: () => ({ data: [] }) }),
+);
+vi.mock("@/hooks/queries/label/use-get-labels-by-workspace", () => ({
+ default: () => ({ data: [] }),
+}));
+vi.mock(
+ "@/hooks/queries/workspace-users/use-get-active-workspace-users",
+ () => ({ useGetActiveWorkspaceUsers: () => ({ data: [] }) }),
+);
+vi.mock("@/components/common/project-layout", () => ({
+ default: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+}));
+vi.mock("@/components/kanban-board", () => ({
+ default: ({ disableDragDrop }: { disableDragDrop: boolean }) => (
+ <div aria-label="Cached board" data-drag-disabled={disableDragDrop}>
+ Cached task
+ </div>
+ ),
+}));
+vi.mock("@/components/board/board-toolbar", () => ({ default: () => null }));
+vi.mock("@/components/list-view", () => ({ default: () => null }));
+vi.mock("@/components/page-title", () => ({ default: () => null }));
+vi.mock("@/components/shared/modals/create-task-modal", () => ({
+ default: () => null,
+}));
+vi.mock("@/components/task/task-details-sheet", () => ({
+ default: () => null,
+}));
+afterEach(cleanup);
+it("keeps cached tasks readable and disables reordering when a refresh fails", () => {
+ const Component = (Route as unknown as { component: ComponentType })
+ .component;
+ render(<Component />);
+ expect(screen.getByText("Cached task")).toBeDefined();
+ expect(
+ screen.getByLabelText("Cached board").getAttribute("data-drag-disabled"),
+ ).toBe("true");
+ fireEvent.click(
+ screen.getByRole("button", { name: "tasks:descriptionRetry" }),
+ );
+ expect(m.retry).toHaveBeenCalledOnce();
+});
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.tsx
index e929f9917..32c2f17e7 100644
--- a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.tsx
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.tsx
@@ -305,28 +305,30 @@ function RouteComponent() {
</p>
)}
+ {boardError && (
+ <p role="alert" className="p-4 text-destructive">
+ {t("tasks:calendar.loadError")}{" "}
+ <button
+ type="button"
+ className="underline"
+ onClick={() => void retryBoard()}
+ >
+ {t("tasks:descriptionRetry")}
+ </button>
+ </p>
+ )}
<div
className={cn("flex h-full flex-1 overflow-hidden", {
"bg-background": !background,
})}
>
- {boardError ? (
- <p role="alert" className="p-4 text-destructive">
- {t("tasks:calendar.loadError")}{" "}
- <button
- type="button"
- className="underline"
- onClick={() => void retryBoard()}
- >
- {t("tasks:descriptionRetry")}
- </button>
- </p>
- ) : sortedProject ? (
+ {sortedProject ? (
viewMode === "board" ? (
<KanbanBoard
project={sortedProject}
disableDragDrop={
boardFetching ||
+ boardError ||
(sort.field !== "position" && sort.field !== "number")
}
sortedByNumber={sort.field === "number"}
@@ -334,10 +336,12 @@ function RouteComponent() {
) : (
<ListView
project={sortedProject}
- disableDragDrop={boardFetching || sort.field !== "position"}
+ disableDragDrop={
+ boardFetching || boardError || sort.field !== "position"
+ }
/>
)
- ) : (
+ ) : boardError ? null : (
<BoardSkeleton />
)}
</div>
diff --git a/tests/api-integration/provider-board-live-updates.test.ts b/tests/api-integration/provider-board-live-updates.test.ts
deleted file mode 100644
index a7abe0b80..000000000
--- a/tests/api-integration/provider-board-live-updates.test.ts
+++ /dev/null
@@ -1,193 +0,0 @@
-import { beforeEach, expect, it, vi } from "vite-plus/test";
-import { eq } from "drizzle-orm";
-import db, { schema } from "../../apps/api/src/database";
-import { handleIssueEdited } from "../../apps/api/src/plugins/github/webhooks/issue-edited";
-import { handleIssueLabeled } from "../../apps/api/src/plugins/github/webhooks/issue-labeled";
-import { handleGiteaIssueEdited } from "../../apps/api/src/plugins/gitea/webhooks/issue-edited";
-import { handleGiteaIssueLabeled } from "../../apps/api/src/plugins/gitea/webhooks/issue-labeled";
-import { handleGitlabIssueUpdated } from "../../apps/api/src/plugins/gitlab/webhooks/issue-updated";
-import { resetTestDatabase } from "./helpers/database";
-import {
- createWorkspaceMember,
- createProjectFixture,
-} from "./helpers/fixtures";
-const m = vi.hoisted(() => ({
- integrations: [] as unknown[],
- publish: vi.fn(async () => {}),
-}));
-vi.mock("../../apps/api/src/events", () => ({ publishEvent: m.publish }));
-vi.mock(
- "../../apps/api/src/plugins/github/services/task-service",
- async (original) => ({
- ...(await original<
- typeof import("../../apps/api/src/plugins/github/services/task-service")
- >()),
- findAllIntegrationsByRepo: async () => m.integrations,
- }),
-);
-vi.mock(
- "../../apps/api/src/plugins/gitea/services/integration-lookup",
- async (original) => ({
- ...(await original<
- typeof import("../../apps/api/src/plugins/gitea/services/integration-lookup")
- >()),
- findAllIntegrationsByGiteaRepo: async () => m.integrations,
- }),
-);
-vi.mock(
- "../../apps/api/src/plugins/gitlab/services/integration-lookup",
- async (original) => ({
- ...(await original<
- typeof import("../../apps/api/src/plugins/gitlab/services/integration-lookup")
- >()),
- findAllIntegrationsByGitlabProject: async () => m.integrations,
- }),
-);
-beforeEach(async () => {
- await resetTestDatabase();
- m.publish.mockClear();
-});
-it.each([
- ["github", "text"],
- ["gitea", "text"],
- ["gitlab", "text"],
- ["github", "priority"],
- ["gitea", "priority"],
- ["gitlab", "priority"],
- ["github", "label"],
- ["gitea", "label"],
- ["gitlab", "label"],
- ["github", "label-delete"],
- ["gitea", "label-delete"],
- ["gitlab", "label-delete"],
-])(
- "announces committed %s %s edits to observing boards",
- async (provider, kind) => {
- const { workspace } = await createWorkspaceMember();
- const { project } = await createProjectFixture({
- workspaceId: workspace.id,
- });
- const [task] = await db
- .insert(schema.taskTable)
- .values({
- projectId: project.id,
- number: 1,
- title: "Before",
- description: "Before body",
- priority: "low",
- })
- .returning();
- const [integration] = await db
- .insert(schema.integrationTable)
- .values({
- projectId: project.id,
- type: provider,
- config: "{}",
- isActive: true,
- })
- .returning();
- m.integrations = [integration];
- await db.insert(schema.externalLinkTable).values({
- taskId: task.id,
- integrationId: integration.id,
- resourceType: "issue",
- externalId: "1",
- url: "https://provider.example/issues/1",
- metadata: "{}",
- });
- if (kind === "label-delete")
- await db.insert(schema.labelTable).values({
- taskId: task.id,
- workspaceId: workspace.id,
- name: "bug",
- color: "#ff0000",
- });
- const issue = {
- number: 1,
- title: "After",
- body: "After body",
- html_url: "https://gitea.example/owner/repo/issues/1",
- };
- const repository = {
- id: 2,
- name: "repo",
- full_name: "owner/repo",
- owner: { login: "owner" },
- html_url: "https://gitea.example/owner/repo",
- };
- if (provider === "github" || provider === "gitea") {
- if (kind === "text") {
- const payload = {
- action: "edited",
- issue,
- repository,
- changes: { title: { from: "Before" }, body: { from: "Before body" } },
- };
- if (provider === "github") await handleIssueEdited(payload);
- else await handleGiteaIssueEdited(payload);
- } else {
- const label = {
- name: kind === "priority" ? "priority:high" : "bug",
- color: "ff0000",
- };
- const payload = {
- action: kind === "label-delete" ? "unlabeled" : "labeled",
- issue: { ...issue, labels: kind === "label-delete" ? [] : [label] },
- label,
- repository,
- };
- if (provider === "github") await handleIssueLabeled(payload);
- else await handleGiteaIssueLabeled(payload);
- }
- } else {
- const label = {
- title: kind === "priority" ? "priority:high" : "bug",
- color: "#ff0000",
- };
- await handleGitlabIssueUpdated({
- object_attributes: {
- iid: 1,
- title: "After",
- description: "After body",
- url: "https://gitlab.example/owner/repo/-/issues/1",
- action: "update",
- },
- changes:
- kind === "text"
- ? {
- title: { previous: "Before", current: "After" },
- description: { previous: "Before body", current: "After body" },
- }
- : {
- labels: {
- previous: kind === "label-delete" ? [label] : [],
- current: kind === "label-delete" ? [] : [label],
- },
- },
- project: {
- name: "repo",
- web_url: "https://gitlab.example/owner/repo",
- path_with_namespace: "owner/repo",
- },
- });
- }
- const saved = await db.query.taskTable.findFirst({
- where: eq(schema.taskTable.id, task.id),
- });
- if (kind === "text") {
- expect(saved?.title).toBe("After");
- expect(saved?.description).toBe("After body");
- } else if (kind === "priority") expect(saved?.priority).toBe("high");
- else {
- const labels = await db.query.labelTable.findMany({
- where: eq(schema.labelTable.taskId, task.id),
- });
- expect(labels.map((label) => label.name)).toEqual(
- kind === "label-delete" ? [] : ["bug"],
- );
- }
- expect(
- m.publish.mock.calls.filter(([name]) => name === "project.updated"),
- ).toEqual([["project.updated", { projectId: project.id }]]);
- },
-);