Skip to content

Commit 2271cb5

Browse files
committed
add test for retrieving users in role with mongo query options
1 parent 6a659b1 commit 2271cb5

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/roles/tests/serverAsync.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,38 @@ Tinytest.addAsync(
15961596
}
15971597
);
15981598

1599+
1600+
Tinytest.addAsync(
1601+
"roles -can get all users in role by scope and passes through mongo query arguments only to the users collection when included in the options",
1602+
async function (test) {
1603+
await clearData();
1604+
await Roles.createRoleAsync("admin");
1605+
await Roles.createRoleAsync("user");
1606+
1607+
await Roles.addUsersToRolesAsync(
1608+
[users.eve, users.joe],
1609+
["admin", "user"],
1610+
"scope1"
1611+
);
1612+
await Roles.addUsersToRolesAsync(
1613+
[users.bob, users.joe],
1614+
["admin"],
1615+
"scope2"
1616+
);
1617+
1618+
const cursor = await Roles.getUsersInRoleAsync("admin", { scope: "scope1", queryOptions: {
1619+
fields: { _id: 1, username: 1 },
1620+
limit: 1,
1621+
}});
1622+
const results = await cursor.fetchAsync();
1623+
1624+
test.equal(1, results.length);
1625+
test.isTrue(hasProp(results[0], "_id"));
1626+
test.isTrue(hasProp(results[0], "username"));
1627+
}
1628+
);
1629+
1630+
15991631
Tinytest.addAsync(
16001632
"roles -can use Roles.GLOBAL_SCOPE to assign blanket roles",
16011633
async function (test) {

0 commit comments

Comments
 (0)