diff --git a/server/routes/api/suggestions/suggestions.test.ts b/server/routes/api/suggestions/suggestions.test.ts index cb3b36fdc3..1595ba29ba 100644 --- a/server/routes/api/suggestions/suggestions.test.ts +++ b/server/routes/api/suggestions/suggestions.test.ts @@ -1,5 +1,6 @@ import { EmailDisplay, TeamPreference } from "@shared/types"; import { + buildCollection, buildGroup, buildGroupUser, buildGuestUser, @@ -138,6 +139,27 @@ describe("#suggestions.mention", () => { } }); + it("should present collections", async () => { + const user = await buildUser(); + const collection = await buildCollection({ + teamId: user.teamId, + userId: user.id, + name: "Elephants", + }); + + const res = await server.post("/api/suggestions.mention", user, { + body: { query: "Elephants" }, + }); + const body = await res.json(); + const [found] = body.data.collections; + + expect(res.status).toEqual(200); + expect(found.id).toEqual(collection.id); + expect(found.url).toEqual(collection.path); + expect(found.content).toBeUndefined(); + expect(found.data).toBeUndefined(); + }); + it("should require authentication", async () => { const res = await server.post("/api/suggestions.mention"); expect(res.status).toEqual(401); diff --git a/server/routes/api/suggestions/suggestions.ts b/server/routes/api/suggestions/suggestions.ts index 8d57b947da..95c9000dc9 100644 --- a/server/routes/api/suggestions/suggestions.ts +++ b/server/routes/api/suggestions/suggestions.ts @@ -15,6 +15,7 @@ import SearchProviderManager from "@server/utils/SearchProviderManager"; import { QueryHelper } from "@server/storage/QueryHelper"; import { can } from "@server/policies"; import { + presentCollection, presentDocuments, presentGroup, presentUser, @@ -153,15 +154,22 @@ router.post( ), withinLimit( "collections", - () => - SearchProviderManager.getProvider().searchCollectionsForUser( - actor, - { - query, - offset, - limit, - } - ), + async () => { + const found = + await SearchProviderManager.getProvider().searchCollectionsForUser( + actor, + { + query, + offset, + limit, + } + ); + return Promise.all( + found.map((collection) => + presentCollection(ctx, collection, { includeData: false }) + ) + ); + }, [] ), ]);