diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index f1dc8f19d7..a34669de03 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -1753,5 +1753,139 @@ describe.each([ _rev: expect.any(String), }) }) + + it("fetch all will populate the BB references", async () => { + const [user1, user2, user3] = _.sampleSize(users, 3) + + const rows: { + name: string + description: string + user?: User[] + users?: User[] + tableId: string + }[] = [ + { + ...basicRow(tableId), + name: generator.name(), + description: generator.name(), + users: [user1, user2], + }, + { + ...basicRow(tableId), + name: generator.name(), + description: generator.name(), + user: [user1], + users: [user1, user3], + }, + { + ...basicRow(tableId), + name: generator.name(), + description: generator.name(), + users: [user3], + }, + ] + + await config.api.row.save(tableId, rows[0]) + await config.api.row.save(tableId, rows[1]) + await config.api.row.save(tableId, rows[2]) + + const res = await config.api.row.fetch(tableId) + + expect(res).toEqual( + expect.arrayContaining( + rows.map(r => ({ + name: r.name, + description: r.description, + type: "row", + tableId, + user: r.user?.map(u => ({ + _id: u._id, + email: u.email, + firstName: u.firstName, + lastName: u.lastName, + primaryDisplay: u.email, + })), + users: r.users?.map(u => ({ + _id: u._id, + email: u.email, + firstName: u.firstName, + lastName: u.lastName, + primaryDisplay: u.email, + })), + _id: expect.any(String), + _rev: expect.any(String), + createdAt: timestamp, + updatedAt: timestamp, + })) + ) + ) + }) + + it("search all will populate the BB references", async () => { + const [user1, user2, user3] = _.sampleSize(users, 3) + + const rows: { + name: string + description: string + user?: User[] + users?: User[] + tableId: string + }[] = [ + { + ...basicRow(tableId), + name: generator.name(), + description: generator.name(), + users: [user1, user2], + }, + { + ...basicRow(tableId), + name: generator.name(), + description: generator.name(), + user: [user1], + users: [user1, user3], + }, + { + ...basicRow(tableId), + name: generator.name(), + description: generator.name(), + users: [user3], + }, + ] + + await config.api.row.save(tableId, rows[0]) + await config.api.row.save(tableId, rows[1]) + await config.api.row.save(tableId, rows[2]) + + const res = await config.api.row.search(tableId) + + expect(res).toEqual({ + rows: expect.arrayContaining( + rows.map(r => ({ + name: r.name, + description: r.description, + type: "row", + tableId, + user: r.user?.map(u => ({ + _id: u._id, + email: u.email, + firstName: u.firstName, + lastName: u.lastName, + primaryDisplay: u.email, + })), + users: r.users?.map(u => ({ + _id: u._id, + email: u.email, + firstName: u.firstName, + lastName: u.lastName, + primaryDisplay: u.email, + })), + _id: expect.any(String), + _rev: expect.any(String), + createdAt: timestamp, + updatedAt: timestamp, + })) + ), + }) + }) }) }) diff --git a/packages/server/src/tests/utilities/api/row.ts b/packages/server/src/tests/utilities/api/row.ts index 2db5169e3d..adeb96a593 100644 --- a/packages/server/src/tests/utilities/api/row.ts +++ b/packages/server/src/tests/utilities/api/row.ts @@ -122,4 +122,16 @@ export class RowAPI extends TestAPI { .expect(expectStatus) return request } + + search = async ( + sourceId: string, + { expectStatus } = { expectStatus: 200 } + ): Promise => { + const request = this.request + .post(`/api/${sourceId}/search`) + .set(this.config.defaultHeaders()) + .expect(expectStatus) + + return (await request).body + } }