From da9f966ff0d5b4f6b21926c04abf5fbb529f636f Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 5 Oct 2020 10:30:15 +0200 Subject: [PATCH] [misc] prepare acceptance tests for mismatching ObjectId types (#3188) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../src/ProjectStructureMongoLockTest.js | 4 ++-- services/web/test/acceptance/src/helpers/User.js | 16 ++++++---------- .../test/acceptance/src/helpers/UserHelper.js | 11 ++++++++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/services/web/test/acceptance/src/ProjectStructureMongoLockTest.js b/services/web/test/acceptance/src/ProjectStructureMongoLockTest.js index 028e5d43b8..5a7d5ea802 100644 --- a/services/web/test/acceptance/src/ProjectStructureMongoLockTest.js +++ b/services/web/test/acceptance/src/ProjectStructureMongoLockTest.js @@ -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() } ) diff --git a/services/web/test/acceptance/src/helpers/User.js b/services/web/test/acceptance/src/helpers/User.js index ce98809dc1..403cad7c9d 100644 --- a/services/web/test/acceptance/src/helpers/User.js +++ b/services/web/test/acceptance/src/helpers/User.js @@ -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 => { - if (error != null) { - return callback(error) - } - this.setExtraAttributes(user) - callback(null, this.password) + this.mongoUpdate({ $set: { emails: this.emails } }, error => { + if (error != null) { + return callback(error) } - ) + callback(null, this.password) + }) } ) }) diff --git a/services/web/test/acceptance/src/helpers/UserHelper.js b/services/web/test/acceptance/src/helpers/UserHelper.js index 52bb7ab899..45c9afe568 100644 --- a/services/web/test/acceptance/src/helpers/UserHelper.js +++ b/services/web/test/acceptance/src/helpers/UserHelper.js @@ -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)