1
0
Fork 0
mirror of synced 2024-09-10 06:26:02 +12:00
This commit is contained in:
Adria Navarro 2023-10-09 13:21:40 +02:00
parent a5477f14d2
commit d7aa23f740

View file

@ -20,58 +20,73 @@ const tableWithUserCol: Table = {
}, },
} }
describe("searchInputMapping", () => { const tableWithUsersCol: Table = {
const globalUserId = dbCore.generateGlobalUserID() _id: tableId,
const userMedataId = dbCore.generateUserMetadataID(globalUserId) 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", () => { describe.each([tableWithUserCol, tableWithUsersCol])(
const params: SearchParams = { "searchInputMapping",
tableId, col => {
query: { const globalUserId = dbCore.generateGlobalUserID()
equal: { const userMedataId = dbCore.generateUserMetadataID(globalUserId)
"1:user": userMedataId,
it("should be able to map ro_ to global user IDs", () => {
const params: SearchParams = {
tableId,
query: {
equal: {
"1:user": userMedataId,
},
}, },
}, }
} const output = searchInputMapping(col, params)
const output = searchInputMapping(tableWithUserCol, params) expect(output.query.equal!["1:user"]).toBe(globalUserId)
expect(output.query.equal!["1:user"]).toBe(globalUserId) })
})
it("should handle array of user IDs", () => { it("should handle array of user IDs", () => {
const params: SearchParams = { const params: SearchParams = {
tableId, tableId,
query: { query: {
oneOf: { oneOf: {
"1:user": [userMedataId, globalUserId], "1:user": [userMedataId, globalUserId],
},
}, },
}, }
} const output = searchInputMapping(col, params)
const output = searchInputMapping(tableWithUserCol, params) expect(output.query.oneOf!["1:user"]).toStrictEqual([
expect(output.query.oneOf!["1:user"]).toStrictEqual([ globalUserId,
globalUserId, globalUserId,
globalUserId, ])
]) })
})
it("shouldn't change any other input", () => { it("shouldn't change any other input", () => {
const email = "test@test.com" const email = "test@test.com"
const params: SearchParams = { const params: SearchParams = {
tableId, tableId,
query: { query: {
equal: { equal: {
"1:user": email, "1:user": email,
},
}, },
}, }
} const output = searchInputMapping(col, params)
const output = searchInputMapping(tableWithUserCol, params) expect(output.query.equal!["1:user"]).toBe(email)
expect(output.query.equal!["1:user"]).toBe(email) })
})
it("shouldn't error if no query supplied", () => { it("shouldn't error if no query supplied", () => {
const params: any = { const params: any = {
tableId, tableId,
} }
const output = searchInputMapping(tableWithUserCol, params) const output = searchInputMapping(col, params)
expect(output.query).toBeUndefined() expect(output.query).toBeUndefined()
}) })
}) }
)