Skip to content

Should we have no-db versions of these functions too? #6

Description

@alanning

In our unit tests, we do a ton of creating user objects, saving them to the db, setting their roles, and reading the record back from db.

We could also support just operating on the user object itself and not touching the db. The programmer would be responsible for storing the resulting user object in the db.

Current usage in unit tests:

// create employee object
let testUser = createEmployee(testChannel.channelId)

// write to db record
const db = await createDb()
const usersColl = db.collection<UserAccount>('users')
await usersColl.insertOne(testUser)

// add roles to db record
const updateManyFunc = usersColl.updateMany.bind(usersColl)
await addUsersToRoles(updateManyFunc, testUser._id, [Permission.MANAGE_PRICING, Permission.MANAGE_USERS], testChannel.channelId)

// retrieve db record with roles
testUser = await usersColl.findOne({ _id: testUser._id }) as EmployeeAccount

Proposed usage:

// create employee object
const testUser = createEmployee(testChannel.channelId)

// add roles to user object
await addUsersToRoles(testUser, [Permission.MANAGE_PRICING, Permission.MANAGE_USERS], testChannel.channelId)

// write to db record
const db = await createDb()
const usersColl = db.collection<UserAccount>('users')
await usersColl.insertOne(testUser)

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions