From d7aa23f7405e70790650c5e9d4af166bea3f9d10 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 9 Oct 2023 13:21:40 +0200 Subject: [PATCH] Testing --- .../sdk/app/rows/search/tests/utils.spec.ts | 111 ++++++++++-------- 1 file changed, 63 insertions(+), 48 deletions(-) diff --git a/packages/server/src/sdk/app/rows/search/tests/utils.spec.ts b/packages/server/src/sdk/app/rows/search/tests/utils.spec.ts index 08d1f1b1cb..d946eea432 100644 --- a/packages/server/src/sdk/app/rows/search/tests/utils.spec.ts +++ b/packages/server/src/sdk/app/rows/search/tests/utils.spec.ts @@ -20,58 +20,73 @@ const tableWithUserCol: Table = { }, } -describe("searchInputMapping", () => { - const globalUserId = dbCore.generateGlobalUserID() - const userMedataId = dbCore.generateUserMetadataID(globalUserId) +const tableWithUsersCol: Table = { + _id: tableId, + name: "table", + schema: { + user: { + name: "user", + type: FieldType.BB_REFERENCE, + subtype: FieldTypeSubtypes.BB_REFERENCE.USERS, + }, + }, +} - it("should be able to map ro_ to global user IDs", () => { - const params: SearchParams = { - tableId, - query: { - equal: { - "1:user": userMedataId, +describe.each([tableWithUserCol, tableWithUsersCol])( + "searchInputMapping", + col => { + const globalUserId = dbCore.generateGlobalUserID() + const userMedataId = dbCore.generateUserMetadataID(globalUserId) + + it("should be able to map ro_ to global user IDs", () => { + const params: SearchParams = { + tableId, + query: { + equal: { + "1:user": userMedataId, + }, }, - }, - } - const output = searchInputMapping(tableWithUserCol, params) - expect(output.query.equal!["1:user"]).toBe(globalUserId) - }) + } + const output = searchInputMapping(col, params) + expect(output.query.equal!["1:user"]).toBe(globalUserId) + }) - it("should handle array of user IDs", () => { - const params: SearchParams = { - tableId, - query: { - oneOf: { - "1:user": [userMedataId, globalUserId], + it("should handle array of user IDs", () => { + const params: SearchParams = { + tableId, + query: { + oneOf: { + "1:user": [userMedataId, globalUserId], + }, }, - }, - } - const output = searchInputMapping(tableWithUserCol, params) - expect(output.query.oneOf!["1:user"]).toStrictEqual([ - globalUserId, - globalUserId, - ]) - }) + } + const output = searchInputMapping(col, params) + expect(output.query.oneOf!["1:user"]).toStrictEqual([ + globalUserId, + globalUserId, + ]) + }) - it("shouldn't change any other input", () => { - const email = "test@test.com" - const params: SearchParams = { - tableId, - query: { - equal: { - "1:user": email, + it("shouldn't change any other input", () => { + const email = "test@test.com" + const params: SearchParams = { + tableId, + query: { + equal: { + "1:user": email, + }, }, - }, - } - const output = searchInputMapping(tableWithUserCol, params) - expect(output.query.equal!["1:user"]).toBe(email) - }) + } + const output = searchInputMapping(col, params) + expect(output.query.equal!["1:user"]).toBe(email) + }) - it("shouldn't error if no query supplied", () => { - const params: any = { - tableId, - } - const output = searchInputMapping(tableWithUserCol, params) - expect(output.query).toBeUndefined() - }) -}) + it("shouldn't error if no query supplied", () => { + const params: any = { + tableId, + } + const output = searchInputMapping(col, params) + expect(output.query).toBeUndefined() + }) + } +)