Skip to content

Commit

Permalink
Fixed fetch in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StorytellerCZ committed Aug 31, 2024
1 parent 82d6f65 commit 7a7e852
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions roles/tests/serverAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,13 @@ describe('roles async', async function () {

// compare roles, sorted alphabetically
const expected = roles
const actual = Roles.getAllRoles().fetch().map(r => r._id)
const fetchAll = await Roles.getAllRoles().fetchAsync()
const actual = fetchAll.map(r => r._id)

assert.sameMembers(actual, expected)

assert.sameMembers(Roles.getAllRoles({ sort: { _id: -1 } }).fetch().map(r => r._id), expected.reverse())
const fetchSorted = await Roles.getAllRoles({ sort: { _id: -1 } }).fetchAsync()
assert.sameMembers(fetchSorted.map(r => r._id), expected.reverse())
})

it('get an empty list of roles for an empty user', async function () {
Expand Down Expand Up @@ -1231,7 +1233,8 @@ describe('roles async', async function () {

const expected = [users.eve, users.joe]
const cursor = await Roles.getUsersInRoleAsync('admin')
const actual = cursor.fetch().map(r => r._id)
const fetched = await cursor.fetchAsync()
const actual = fetched.map(r => r._id)

assert.sameMembers(actual, expected)
})
Expand All @@ -1245,22 +1248,26 @@ describe('roles async', async function () {

let expected = [users.eve, users.joe]
const cursor1 = await Roles.getUsersInRoleAsync('admin', 'scope1')
let actual = cursor1.fetch().map(r => r._id)
const fetched1 = await cursor1.fetchAsync()
let actual = fetched1.map(r => r._id)

assert.sameMembers(actual, expected)

expected = [users.eve, users.joe]
const cursor2 = await Roles.getUsersInRoleAsync('admin', { scope: 'scope1' })
actual = cursor2.fetch().map(r => r._id)
const fetched2 = await cursor2.fetchAsync()
actual = fetched2.map(r => r._id)
assert.sameMembers(actual, expected)

expected = [users.eve, users.bob, users.joe]
const cursor3 = await Roles.getUsersInRoleAsync('admin', { anyScope: true })
actual = cursor3.fetch().map(r => r._id)
const fetched3 = await cursor3.fetchAsync()
actual = fetched3.map(r => r._id)
assert.sameMembers(actual, expected)

const cursor4 = await Roles.getUsersInRoleAsync('admin')
actual = cursor4.fetch().map(r => r._id)
const fetched4 = await cursor4.fetchAsync()
actual = fetched4.map(r => r._id)
assert.sameMembers(actual, [])
})

Expand Down Expand Up @@ -1319,7 +1326,7 @@ describe('roles async', async function () {
await Roles.addUsersToRolesAsync([users.bob, users.joe], ['admin'], 'scope2')

const cursor = await Roles.getUsersInRoleAsync('admin', 'scope1', { fields: { username: 0 }, limit: 1 })
const results = cursor.fetch()
const results = await cursor.fetchAsync()

assert.equal(1, results.length)
assert.isTrue(hasProp(results[0], '_id'))
Expand Down

0 comments on commit 7a7e852

Please sign in to comment.