diff --git a/services/web/app/src/Features/User/UserCreator.js b/services/web/app/src/Features/User/UserCreator.js index 2656817fdb..f58350a7fe 100644 --- a/services/web/app/src/Features/User/UserCreator.js +++ b/services/web/app/src/Features/User/UserCreator.js @@ -3,7 +3,7 @@ const util = require('util') const { User } = require('../../models/User') const { addAffiliation } = require('../Institutions/InstitutionsAPI') -async function createNewUser(attributes, options = {}) { +async function createNewUser(attributes) { let user = new User() if (attributes.first_name == null || attributes.first_name === '') { @@ -40,17 +40,14 @@ async function createNewUser(attributes, options = {}) { user = await user.save() - if (!options.skip_affiliation) { - // There is no guarantee this will complete so we must not rely on it - addAffiliation(user._id, user.email, err => { - if (err) { - logger.error( - { userId: user._id, email: user.email }, - "couldn't add affiliation for user on create" - ) - } - }) - } + addAffiliation(user._id, user.email, err => { + if (err) { + logger.error( + { userId: user._id, email: user.email }, + "couldn't add affiliation for user on create" + ) + } + }) return user } diff --git a/services/web/test/acceptance/src/helpers/UserHelper.js b/services/web/test/acceptance/src/helpers/UserHelper.js index 2df1c92ab7..bfb30bbeff 100644 --- a/services/web/test/acceptance/src/helpers/UserHelper.js +++ b/services/web/test/acceptance/src/helpers/UserHelper.js @@ -141,14 +141,10 @@ class UserHelper { * @param {object} options options for UserCreator * @returns {UserHelper} */ - static async createUser(attributes = {}, options = {}) { + static async createUser(attributes = {}) { const userHelper = new UserHelper() attributes = userHelper.getDefaultEmailPassword(attributes) - // skip creating affiliations by default because it requires an - // API call that will usually not be mocked in testing env - if (attributes.skip_affiliation !== false) { - attributes.skip_affiliation = true - } + // hash password and delete plaintext if set if (attributes.password) { attributes.hashedPassword = await AuthenticationManager.promises.hashPassword( @@ -157,10 +153,7 @@ class UserHelper { delete attributes.password } - userHelper.user = await UserCreator.promises.createNewUser( - attributes, - options - ) + userHelper.user = await UserCreator.promises.createNewUser(attributes) return userHelper } diff --git a/services/web/test/unit/src/User/UserCreatorTests.js b/services/web/test/unit/src/User/UserCreatorTests.js index 5dac565971..732f8e0d74 100644 --- a/services/web/test/unit/src/User/UserCreatorTests.js +++ b/services/web/test/unit/src/User/UserCreatorTests.js @@ -123,18 +123,6 @@ describe('UserCreator', function() { done() }) }) - - it('should not add affiliation if skipping', function(done) { - const attributes = { email: this.email } - const options = { skip_affiliation: true } - this.UserCreator.createNewUser(attributes, options, (err, user) => { - assert.ifError(err) - process.nextTick(() => { - sinon.assert.notCalled(this.addAffiliation) - done() - }) - }) - }) }) describe('with promises', function() { @@ -156,13 +144,6 @@ describe('UserCreator', function() { sinon.assert.calledWithMatch(this.addAffiliation, user._id, this.email) }) - it('should not add affiliation if skipping', async function() { - const attributes = { email: this.email } - const opts = { skip_affiliation: true } - await this.UserCreator.promises.createNewUser(attributes, opts) - sinon.assert.notCalled(this.addAffiliation) - }) - it('should include SAML provider ID with email', async function() { const attributes = { email: this.email,