Merge pull request #2594 from overleaf/jel-flag-affiliation-when-registering
Flag unchecked affiliation when registering GitOrigin-RevId: c9da12ceb5a1712c8c477222f967fb54eceef252
This commit is contained in:
@@ -15,9 +15,6 @@ describe('UserCreator', function() {
|
||||
return self.user
|
||||
}
|
||||
}
|
||||
|
||||
this.UserGetter = { getUserByMainEmail: sinon.stub() }
|
||||
this.addAffiliation = sinon.stub().yields()
|
||||
this.UserCreator = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
console: console
|
||||
@@ -26,11 +23,26 @@ describe('UserCreator', function() {
|
||||
'../../models/User': {
|
||||
User: this.UserModel
|
||||
},
|
||||
'logger-sharelatex': { log: sinon.stub(), err: sinon.stub() },
|
||||
'logger-sharelatex': {
|
||||
error: sinon.stub()
|
||||
},
|
||||
'metrics-sharelatex': { timeAsyncMethod() {} },
|
||||
'../Institutions/InstitutionsAPI': {
|
||||
addAffiliation: this.addAffiliation
|
||||
}
|
||||
'../../infrastructure/Features': (this.Features = {
|
||||
hasFeature: sinon.stub().returns(false)
|
||||
}),
|
||||
'./UserGetter': (this.UserGetter = {
|
||||
promises: {
|
||||
getUser: sinon.stub().resolves(this.user)
|
||||
}
|
||||
}),
|
||||
'./UserUpdater': (this.UserUpdater = {
|
||||
promises: {
|
||||
addAffiliationForNewUser: sinon
|
||||
.stub()
|
||||
.resolves({ n: 1, nModified: 1, ok: 1 }),
|
||||
updateUser: sinon.stub().resolves()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -110,15 +122,76 @@ describe('UserCreator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should add affiliation', function(done) {
|
||||
it('should not add affiliation', function() {})
|
||||
|
||||
describe('with affiliations feature', function() {
|
||||
let attributes, user
|
||||
beforeEach(function() {
|
||||
attributes = { email: this.email }
|
||||
this.Features.hasFeature = sinon
|
||||
.stub()
|
||||
.withArgs('affiliations')
|
||||
.returns(true)
|
||||
})
|
||||
describe('when v1 affiliations API does not return an error', function() {
|
||||
beforeEach(function(done) {
|
||||
this.UserCreator.createNewUser(attributes, (err, createdUser) => {
|
||||
user = createdUser
|
||||
assert.ifError(err)
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('should flag that affiliation is unchecked', function() {
|
||||
user.emails[0].affiliationUnchecked.should.equal(true)
|
||||
})
|
||||
it('should try to add affiliation to v1', function() {
|
||||
sinon.assert.calledOnce(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser
|
||||
)
|
||||
sinon.assert.calledWithMatch(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser,
|
||||
user._id,
|
||||
this.email
|
||||
)
|
||||
})
|
||||
it('should query for updated user data', function() {
|
||||
sinon.assert.calledOnce(this.UserGetter.promises.getUser)
|
||||
})
|
||||
})
|
||||
describe('when v1 affiliations API does return an error', function() {
|
||||
beforeEach(function(done) {
|
||||
this.UserUpdater.promises.addAffiliationForNewUser.rejects()
|
||||
this.UserCreator.createNewUser(attributes, (error, createdUser) => {
|
||||
user = createdUser
|
||||
assert.ifError(error)
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('should flag that affiliation is unchecked', function() {
|
||||
user.emails[0].affiliationUnchecked.should.equal(true)
|
||||
})
|
||||
it('should try to add affiliation to v1', function() {
|
||||
sinon.assert.calledOnce(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser
|
||||
)
|
||||
sinon.assert.calledWithMatch(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser,
|
||||
user._id,
|
||||
this.email
|
||||
)
|
||||
})
|
||||
it('should query for updated user data', function() {
|
||||
sinon.assert.calledOnce(this.UserGetter.promises.getUser)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should not add affiliation when without affiliation feature', function(done) {
|
||||
const attributes = { email: this.email }
|
||||
this.UserCreator.createNewUser(attributes, (err, user) => {
|
||||
assert.ifError(err)
|
||||
sinon.assert.calledOnce(this.addAffiliation)
|
||||
sinon.assert.calledWithMatch(
|
||||
this.addAffiliation,
|
||||
user._id,
|
||||
this.email
|
||||
sinon.assert.notCalled(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser
|
||||
)
|
||||
done()
|
||||
})
|
||||
@@ -137,11 +210,30 @@ describe('UserCreator', function() {
|
||||
assert.equal(user.first_name, 'bob.oswald')
|
||||
})
|
||||
|
||||
it('should add affiliation', async function() {
|
||||
it('should add affiliation when with affiliation feature', async function() {
|
||||
this.Features.hasFeature = sinon
|
||||
.stub()
|
||||
.withArgs('affiliations')
|
||||
.returns(true)
|
||||
const attributes = { email: this.email }
|
||||
const user = await this.UserCreator.promises.createNewUser(attributes)
|
||||
sinon.assert.calledOnce(this.addAffiliation)
|
||||
sinon.assert.calledWithMatch(this.addAffiliation, user._id, this.email)
|
||||
sinon.assert.calledOnce(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser
|
||||
)
|
||||
sinon.assert.calledWithMatch(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser,
|
||||
user._id,
|
||||
this.email
|
||||
)
|
||||
})
|
||||
|
||||
it('should not add affiliation when without affiliation feature', async function() {
|
||||
this.Features.hasFeature = sinon.stub().returns(false)
|
||||
const attributes = { email: this.email }
|
||||
await this.UserCreator.promises.createNewUser(attributes)
|
||||
sinon.assert.notCalled(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser
|
||||
)
|
||||
})
|
||||
|
||||
it('should include SAML provider ID with email', async function() {
|
||||
|
||||
Reference in New Issue
Block a user