mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
[misc] prepare acceptance tests for mismatching ObjectId types (#3188)
- helpers/User: UserUpdater cannot handle foreign ObjectIds. Instead use `mongoUpdate`, which in turn uses the user id which `setExtraAttributes` sets -- hence the reordering of calls. - CollabratecTests: use chaId for id comparison. - ProjectStructureMongoLockTest: use chaId for id comparison. - UserHelper: less generic updateUser -- wrap the passed ObjectId GitOrigin-RevId: b16e2b66dcb3dd5f0a842ca5e55fa661abe9035f
This commit is contained in:
parent
ad52f7dc01
commit
da9f966ff0
3 changed files with 16 additions and 15 deletions
|
@ -127,7 +127,7 @@ describe('ProjectStructureMongoLock', function() {
|
|||
{ _id: true },
|
||||
(err, project) => {
|
||||
expect(err).to.equal(null)
|
||||
expect(project._id).to.deep.equal(this.locked_project._id)
|
||||
expect(project).to.have.same.id(this.locked_project)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
|
@ -167,7 +167,7 @@ describe('ProjectStructureMongoLock', function() {
|
|||
this.unlocked_project._id,
|
||||
(err, project) => {
|
||||
expect(err).to.equal(null)
|
||||
expect(project._id).to.deep.equal(this.unlocked_project._id)
|
||||
expect(project).to.have.same.id(this.unlocked_project)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
|
|
|
@ -110,6 +110,7 @@ class User {
|
|||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
this.setExtraAttributes(user)
|
||||
AuthenticationManager.setUserPasswordInV2(
|
||||
user._id,
|
||||
this.password,
|
||||
|
@ -117,17 +118,12 @@ class User {
|
|||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
UserUpdater.updateUser(
|
||||
user._id,
|
||||
{ $set: { emails: this.emails } },
|
||||
error => {
|
||||
this.mongoUpdate({ $set: { emails: this.emails } }, error => {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
this.setExtraAttributes(user)
|
||||
callback(null, this.password)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
|
|
@ -5,6 +5,7 @@ const UserCreator = require('../../../../app/src/Features/User/UserCreator')
|
|||
const UserGetter = require('../../../../app/src/Features/User/UserGetter')
|
||||
const UserUpdater = require('../../../../app/src/Features/User/UserUpdater')
|
||||
const request = require('request-promise-native')
|
||||
const { ObjectId } = require('mongodb')
|
||||
|
||||
let globalUserNum = 1
|
||||
|
||||
|
@ -200,11 +201,15 @@ class UserHelper {
|
|||
* All args passed to UserUpdater.getUser.
|
||||
* @returns {UserHelper}
|
||||
*/
|
||||
static async updateUser(...args) {
|
||||
const user = await UserUpdater.promises.updateUser(...args)
|
||||
static async updateUser(userId, update) {
|
||||
// TODO(das7pad): revert back to args pass-through after mongo upgrades
|
||||
const user = await UserUpdater.promises.updateUser(
|
||||
{ _id: ObjectId(userId) },
|
||||
update
|
||||
)
|
||||
|
||||
if (!user) {
|
||||
throw new Error(`no user found for args: ${JSON.stringify([...args])}`)
|
||||
throw new Error(`no user found for args: ${JSON.stringify([userId])}`)
|
||||
}
|
||||
|
||||
return new UserHelper(user)
|
||||
|
|
Loading…
Reference in a new issue