⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(search): return each workspace once in global search
Justin Willhite0dde3dd4096d
diff --git a/apps/api/src/search/controllers/global-search.ts b/apps/api/src/search/controllers/global-search.tsindex d22c586ed..5f83f9e92 100644--- a/apps/api/src/search/controllers/global-search.ts+++ b/apps/api/src/search/controllers/global-search.ts@@ -376,10 +376,6 @@ async function globalSearch(params: SearchParams): Promise<{relevanceScore: workspaceRelevanceScore.as("relevanceScore"),}).from(workspaceTable)- .leftJoin(- workspaceUserTable,- eq(workspaceTable.id, workspaceUserTable.workspaceId),- ).where(and(inArray(workspaceTable.id, accessibleWorkspaceIds),diff --git a/tests/api-integration/search-workspace-dedup.test.ts b/tests/api-integration/search-workspace-dedup.test.tsnew file mode 100644index 000000000..487911cba--- /dev/null+++ b/tests/api-integration/search-workspace-dedup.test.ts@@ -0,0 +1,40 @@+import { beforeEach, describe, expect, it } from "vite-plus/test";+import db, { schema } from "../../apps/api/src/database";+import { createApp } from "../../apps/api/src/index";+import { mockAuthenticatedSession } from "./helpers/auth";+import { resetTestDatabase } from "./helpers/database";+import { createWorkspaceMember } from "./helpers/fixtures";++describe("global search workspace results", () => {+ beforeEach(async () => {+ await resetTestDatabase();+ });++ it("returns a workspace once regardless of its member count", async () => {+ const member = await createWorkspaceMember({+ workspaceName: "Repro Space",+ });+ const other = await createWorkspaceMember();+ await db.insert(schema.workspaceUserTable).values({+ workspaceId: member.workspace.id,+ userId: other.user.id,+ role: "member",+ joinedAt: new Date(),+ });++ mockAuthenticatedSession(member.user);+ const { app } = createApp();+ const response = await app.request(+ `/api/search?${new URLSearchParams({ q: "repro", type: "workspaces", workspaceId: member.workspace.id })}`,+ );++ expect(response.status).toBe(200);+ const body = await response.json();+ expect(body.results).toHaveLength(1);+ expect(body.results[0]).toMatchObject({+ id: member.workspace.id,+ type: "workspace",+ });+ expect(body.totalCount).toBe(1);+ });+});