-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12002 from Budibase/fix/users-column-search-mapping
Fix/users column search mapping
- Loading branch information
Showing
2 changed files
with
73 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}, | ||
}, | ||
} | ||
|
||
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, | ||
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 = "[email protected]" | ||
const params: SearchParams = { | ||
tableId, | ||
query: { | ||
equal: { | ||
"1:user": email, | ||
it("shouldn't change any other input", () => { | ||
const email = "[email protected]" | ||
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() | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters