Merge pull request #3348 from overleaf/revert-3298-jpa-re-land-mongoose-latest

Revert "[misc] re-land: remove mongojs and bump mongoose"

GitOrigin-RevId: 45a284435c88898d96769ab258651fb8d6d20ff5
This commit is contained in:
Jakob Ackermann
2020-11-03 03:05:09 +00:00
committed by Copybot
parent 6a837ce457
commit e249a2e5be
60 changed files with 671 additions and 454 deletions
@@ -121,7 +121,7 @@ describe('FeatureUpdater.refreshFeatures', function() {
describe('when the user has bonus features', function() {
beforeEach(function() {
return User.updateOne(
return User.update(
{
_id: this.user._id
},
@@ -193,7 +193,7 @@ describe('FeatureUpdater.refreshFeatures', function() {
describe('when the user is due bonus features and has extra features that no longer apply', function() {
beforeEach(function() {
return User.updateOne(
return User.update(
{
_id: this.user._id
},
@@ -224,7 +224,7 @@ describe('FeatureUpdater.refreshFeatures', function() {
describe('when the user has a v1 plan', function() {
beforeEach(function() {
MockV1Api.setUser(42, { plan_name: 'free' })
return User.updateOne(
return User.update(
{
_id: this.user._id
},
@@ -251,7 +251,7 @@ describe('FeatureUpdater.refreshFeatures', function() {
describe('when the user has a v1 plan and bonus features', function() {
beforeEach(function() {
MockV1Api.setUser(42, { plan_name: 'free' })
return User.updateOne(
return User.update(
{
_id: this.user._id
},
@@ -327,7 +327,7 @@ describe('FeatureUpdater.refreshFeatures', function() {
describe('when the notifyV1Flag is passed', function() {
beforeEach(function() {
return User.updateOne(
return User.update(
{
_id: this.user._id
},
@@ -344,7 +344,7 @@ describe('FeatureUpdater.refreshFeatures', function() {
beforeEach(function() {
const futureDate = new Date()
futureDate.setDate(futureDate.getDate() + 1)
return User.updateOne(
return User.update(
{
_id: this.user._id
},
@@ -18,7 +18,7 @@ describe('mongoose', function() {
it('does not allow the creation of multiple users with the same email', async function() {
await expect(User.create({ email: email })).to.be.fulfilled
await expect(User.create({ email: email })).to.be.rejected
await expect(User.countDocuments({ email: email })).to.eventually.equal(1)
await expect(User.count({ email: email })).to.eventually.equal(1)
})
})
@@ -53,7 +53,7 @@ describe('Project CRUD', function() {
describe('with an array archived state', function() {
it('should mark the project as not archived for the user', async function() {
await Project.updateOne(
await Project.update(
{ _id: this.projectId },
{ $set: { archived: [ObjectId(this.user._id)] } }
).exec()
@@ -72,7 +72,7 @@ describe('Project CRUD', function() {
describe('with a legacy boolean state', function() {
it('should mark the project as not archived for the user', async function() {
await Project.updateOne(
await Project.update(
{ _id: this.projectId },
{ $set: { archived: true } }
).exec()
@@ -92,7 +92,7 @@ describe('Project CRUD', function() {
describe('when untrashing a project', function() {
it('should mark the project as untrashed for the user', async function() {
await Project.updateOne(
await Project.update(
{ _id: this.projectId },
{ trashed: [ObjectId(this.user._id)] }
).exec()
@@ -107,7 +107,7 @@ describe('Project CRUD', function() {
})
it('does nothing if the user has already untrashed the project', async function() {
await Project.updateOne(
await Project.update(
{ _id: this.projectId },
{ trashed: [ObjectId(this.user._id)] }
).exec()
@@ -1107,7 +1107,7 @@ describe('ProjectStructureChanges', function() {
describe('when rootDoc_id matches doc being deleted', function() {
beforeEach(function(done) {
Project.updateOne(
Project.update(
{ _id: this.exampleProjectId },
{ $set: { rootDoc_id: this.exampleDocId } },
done
@@ -1139,7 +1139,7 @@ describe('ProjectStructureChanges', function() {
describe('when rootDoc_id does not match doc being deleted', function() {
beforeEach(function(done) {
this.exampleRootDocId = new ObjectId()
Project.updateOne(
Project.update(
{ _id: this.exampleProjectId },
{ $set: { rootDoc_id: this.exampleRootDocId } },
done
@@ -103,7 +103,7 @@ describe('Subscriptions', function() {
MockRecurlyApi.mockSubscriptions = []
MockRecurlyApi.coupons = {}
MockRecurlyApi.redemptions = {}
Subscription.deleteOne(
Subscription.remove(
{
admin_id: this.user._id
},
@@ -207,7 +207,7 @@ describe('Subscriptions', function() {
})
after(function(done) {
Subscription.deleteOne(
Subscription.remove(
{
admin_id: this.user._id
},
@@ -277,7 +277,7 @@ describe('Subscriptions', function() {
})
after(function(done) {
Subscription.deleteOne(
Subscription.remove(
{
admin_id: this.owner1._id
},
@@ -285,7 +285,7 @@ describe('Subscriptions', function() {
if (error != null) {
return done(error)
}
return Subscription.deleteOne(
return Subscription.remove(
{
admin_id: this.owner2._id
},
@@ -349,7 +349,7 @@ describe('Subscriptions', function() {
})
after(function(done) {
Subscription.deleteOne(
Subscription.remove(
{
admin_id: this.owner1._id
},
@@ -406,7 +406,7 @@ describe('Subscriptions', function() {
})
after(function(done) {
Institution.deleteOne(
Institution.remove(
{
v1Id: this.v1Id
},
@@ -131,20 +131,16 @@ class User {
const value = features[key]
update[`features.${key}`] = value
}
UserModel.updateOne({ _id: this.id }, update, callback)
UserModel.update({ _id: this.id }, update, callback)
}
setFeaturesOverride(featuresOverride, callback) {
const update = { $push: { featuresOverrides: featuresOverride } }
UserModel.updateOne({ _id: this.id }, update, callback)
UserModel.update({ _id: this.id }, update, callback)
}
setOverleafId(overleafId, callback) {
UserModel.updateOne(
{ _id: this.id },
{ 'overleaf.id': overleafId },
callback
)
UserModel.update({ _id: this.id }, { 'overleaf.id': overleafId }, callback)
}
logout(callback) {
@@ -622,7 +618,7 @@ class User {
}
setV1Id(v1Id, callback) {
UserModel.updateOne(
UserModel.update(
{
_id: this._id
},
@@ -99,7 +99,7 @@ describe('CollaboratorsHandler', function() {
})
it('should remove the user from mongo', async function() {
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{
_id: this.project._id
@@ -138,7 +138,7 @@ describe('CollaboratorsHandler', function() {
})
it('should remove the user from mongo', async function() {
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{
_id: this.oldArchivedProject._id
@@ -175,7 +175,7 @@ describe('CollaboratorsHandler', function() {
})
it('should remove the user from mongo', async function() {
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{
_id: this.archivedProject._id
@@ -203,7 +203,7 @@ describe('CollaboratorsHandler', function() {
describe('addUserIdToProject', function() {
describe('as readOnly', function() {
beforeEach(async function() {
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{
_id: this.project._id
@@ -238,7 +238,7 @@ describe('CollaboratorsHandler', function() {
describe('as readAndWrite', function() {
beforeEach(async function() {
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{
_id: this.project._id
@@ -289,7 +289,7 @@ describe('CollaboratorsHandler', function() {
this.userId,
'readAndWrite'
)
// Project.updateOne() should not be called. If it is, it will fail because
// Project.update() should not be called. If it is, it will fail because
// the mock is not set up.
})
})
@@ -348,7 +348,7 @@ describe('CollaboratorsHandler', function() {
.chain('exec')
.resolves({ _id: projectId })
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{
_id: projectId
@@ -394,46 +394,51 @@ describe('CollaboratorsHandler', function() {
})
.chain('exec')
.resolves(this.projects)
this.ProjectMock.expects('updateMany')
this.ProjectMock.expects('update')
.withArgs(
{ owner_ref: this.fromUserId },
{ $set: { owner_ref: this.toUserId } }
{ $set: { owner_ref: this.toUserId } },
{ multi: true }
)
.chain('exec')
.resolves()
this.ProjectMock.expects('updateMany')
this.ProjectMock.expects('update')
.withArgs(
{ collaberator_refs: this.fromUserId },
{
$addToSet: { collaberator_refs: this.toUserId }
}
},
{ multi: true }
)
.chain('exec')
.resolves()
this.ProjectMock.expects('updateMany')
this.ProjectMock.expects('update')
.withArgs(
{ collaberator_refs: this.fromUserId },
{
$pull: { collaberator_refs: this.fromUserId }
}
},
{ multi: true }
)
.chain('exec')
.resolves()
this.ProjectMock.expects('updateMany')
this.ProjectMock.expects('update')
.withArgs(
{ readOnly_refs: this.fromUserId },
{
$addToSet: { readOnly_refs: this.toUserId }
}
},
{ multi: true }
)
.chain('exec')
.resolves()
this.ProjectMock.expects('updateMany')
this.ProjectMock.expects('update')
.withArgs(
{ readOnly_refs: this.fromUserId },
{
$pull: { readOnly_refs: this.fromUserId }
}
},
{ multi: true }
)
.chain('exec')
.resolves()
@@ -34,8 +34,8 @@ describe('CollaboratorsInviteHandler', function() {
this.prototype.save = sinon.stub()
this.findOne = sinon.stub()
this.find = sinon.stub()
this.deleteOne = sinon.stub()
this.countDocuments = sinon.stub()
this.remove = sinon.stub()
this.count = sinon.stub()
}
constructor(options) {
if (options == null) {
@@ -105,7 +105,7 @@ describe('CollaboratorsInviteHandler', function() {
describe('getInviteCount', function() {
beforeEach(function() {
this.ProjectInvite.countDocuments.callsArgWith(1, null, 2)
this.ProjectInvite.count.callsArgWith(1, null, 2)
return (this.call = callback => {
return this.CollaboratorsInviteHandler.getInviteCount(
this.projectId,
@@ -129,12 +129,9 @@ describe('CollaboratorsInviteHandler', function() {
})
})
describe('when model.countDocuments produces an error', function() {
describe('when model.count produces an error', function() {
beforeEach(function() {
return this.ProjectInvite.countDocuments.callsArgWith(
1,
new Error('woops')
)
return this.ProjectInvite.count.callsArgWith(1, new Error('woops'))
})
it('should produce an error', function(done) {
@@ -394,7 +391,7 @@ describe('CollaboratorsInviteHandler', function() {
describe('revokeInvite', function() {
beforeEach(function() {
this.ProjectInvite.deleteOne.callsArgWith(1, null)
this.ProjectInvite.remove.callsArgWith(1, null)
this.CollaboratorsInviteHandler._tryCancelInviteNotification = sinon
.stub()
.callsArgWith(1, null)
@@ -418,10 +415,10 @@ describe('CollaboratorsInviteHandler', function() {
})
})
it('should call ProjectInvite.deleteOne', function(done) {
it('should call ProjectInvite.remove', function(done) {
return this.call(err => {
this.ProjectInvite.deleteOne.callCount.should.equal(1)
this.ProjectInvite.deleteOne
this.ProjectInvite.remove.callCount.should.equal(1)
this.ProjectInvite.remove
.calledWith({ projectId: this.projectId, _id: this.inviteId })
.should.equal(true)
return done()
@@ -443,7 +440,7 @@ describe('CollaboratorsInviteHandler', function() {
describe('when remove produces an error', function() {
beforeEach(function() {
return this.ProjectInvite.deleteOne.callsArgWith(1, new Error('woops'))
return this.ProjectInvite.remove.callsArgWith(1, new Error('woops'))
})
it('should produce an error', function(done) {
@@ -644,7 +641,7 @@ describe('CollaboratorsInviteHandler', function() {
this.CollaboratorsInviteHandler._tryCancelInviteNotification = sinon
.stub()
.callsArgWith(1, null)
this.ProjectInvite.deleteOne.callsArgWith(1, null)
this.ProjectInvite.remove.callsArgWith(1, null)
return (this.call = callback => {
return this.CollaboratorsInviteHandler.acceptInvite(
this.projectId,
@@ -695,10 +692,10 @@ describe('CollaboratorsInviteHandler', function() {
})
})
it('should have called ProjectInvite.deleteOne', function(done) {
it('should have called ProjectInvite.remove', function(done) {
return this.call(err => {
this.ProjectInvite.deleteOne.callCount.should.equal(1)
this.ProjectInvite.deleteOne
this.ProjectInvite.remove.callCount.should.equal(1)
this.ProjectInvite.remove
.calledWith({ _id: this.inviteId })
.should.equal(true)
return done()
@@ -766,9 +763,9 @@ describe('CollaboratorsInviteHandler', function() {
})
})
it('should not have called ProjectInvite.deleteOne', function(done) {
it('should not have called ProjectInvite.remove', function(done) {
return this.call(err => {
this.ProjectInvite.deleteOne.callCount.should.equal(0)
this.ProjectInvite.remove.callCount.should.equal(0)
return done()
})
})
@@ -803,9 +800,9 @@ describe('CollaboratorsInviteHandler', function() {
})
})
it('should not have called ProjectInvite.deleteOne', function(done) {
it('should not have called ProjectInvite.remove', function(done) {
return this.call(err => {
this.ProjectInvite.deleteOne.callCount.should.equal(0)
this.ProjectInvite.remove.callCount.should.equal(0)
return done()
})
})
@@ -851,17 +848,17 @@ describe('CollaboratorsInviteHandler', function() {
})
})
it('should not have called ProjectInvite.deleteOne', function(done) {
it('should not have called ProjectInvite.remove', function(done) {
return this.call(err => {
this.ProjectInvite.deleteOne.callCount.should.equal(0)
this.ProjectInvite.remove.callCount.should.equal(0)
return done()
})
})
})
describe('when ProjectInvite.deleteOne produces an error', function() {
describe('when ProjectInvite.remove produces an error', function() {
beforeEach(function() {
return this.ProjectInvite.deleteOne.callsArgWith(1, new Error('woops'))
return this.ProjectInvite.remove.callsArgWith(1, new Error('woops'))
})
it('should produce an error', function(done) {
@@ -896,9 +893,9 @@ describe('CollaboratorsInviteHandler', function() {
})
})
it('should have called ProjectInvite.deleteOne', function(done) {
it('should have called ProjectInvite.remove', function(done) {
return this.call(err => {
this.ProjectInvite.deleteOne.callCount.should.equal(1)
this.ProjectInvite.remove.callCount.should.equal(1)
return done()
})
})
@@ -24,7 +24,7 @@ describe('OwnershipTransferHandler', function() {
}
}
this.ProjectModel = {
updateOne: sinon.stub().returns({
update: sinon.stub().returns({
exec: sinon.stub().resolves()
})
}
@@ -129,7 +129,7 @@ describe('OwnershipTransferHandler', function() {
this.project._id,
this.collaborator._id
)
expect(this.ProjectModel.updateOne).to.have.been.calledWith(
expect(this.ProjectModel.update).to.have.been.calledWith(
{ _id: this.project._id },
sinon.match({ $set: { owner_ref: this.collaborator._id } })
)
@@ -140,7 +140,7 @@ describe('OwnershipTransferHandler', function() {
this.project._id,
this.user._id
)
expect(this.ProjectModel.updateOne).not.to.have.been.called
expect(this.ProjectModel.update).not.to.have.been.called
})
it("should remove the user from the project's collaborators", async function() {
@@ -49,7 +49,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('initializeCollabratecProject', function() {
describe('when update succeeds', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub().yields()
this.ProjectModel.update = sinon.stub().yields()
return this.ProjectCollabratecDetailsHandler.initializeCollabratecProject(
this.projectId,
this.userId,
@@ -71,7 +71,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
]
}
}
return expect(this.ProjectModel.updateOne).to.have.been.calledWith(
return expect(this.ProjectModel.update).to.have.been.calledWith(
{ _id: this.projectId },
update,
this.callback
@@ -81,7 +81,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('when update has error', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub().yields('error')
this.ProjectModel.update = sinon.stub().yields('error')
return this.ProjectCollabratecDetailsHandler.initializeCollabratecProject(
this.projectId,
this.userId,
@@ -98,7 +98,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('with invalid args', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub()
this.ProjectModel.update = sinon.stub()
return this.ProjectCollabratecDetailsHandler.initializeCollabratecProject(
'bad-project-id',
'bad-user-id',
@@ -109,7 +109,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
})
it('should not update', function() {
return expect(this.ProjectModel.updateOne).not.to.have.been.called
return expect(this.ProjectModel.update).not.to.have.been.called
})
it('should callback with error', function() {
@@ -206,7 +206,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('linkCollabratecUserProject', function() {
describe('when update succeeds', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub().yields()
this.ProjectModel.update = sinon.stub().yields()
return this.ProjectCollabratecDetailsHandler.linkCollabratecUserProject(
this.projectId,
this.userId,
@@ -235,7 +235,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
}
}
}
return expect(this.ProjectModel.updateOne).to.have.been.calledWith(
return expect(this.ProjectModel.update).to.have.been.calledWith(
query,
update,
this.callback
@@ -245,7 +245,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('when update has error', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub().yields('error')
this.ProjectModel.update = sinon.stub().yields('error')
return this.ProjectCollabratecDetailsHandler.linkCollabratecUserProject(
this.projectId,
this.userId,
@@ -261,7 +261,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('with invalid args', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub()
this.ProjectModel.update = sinon.stub()
return this.ProjectCollabratecDetailsHandler.linkCollabratecUserProject(
'bad-project-id',
'bad-user-id',
@@ -271,7 +271,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
})
it('should not update', function() {
return expect(this.ProjectModel.updateOne).not.to.have.been.called
return expect(this.ProjectModel.update).not.to.have.been.called
})
it('should callback with error', function() {
@@ -298,7 +298,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('when update succeeds', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub().yields()
this.ProjectModel.update = sinon.stub().yields()
return this.ProjectCollabratecDetailsHandler.setCollabratecUsers(
this.projectId,
this.collabratecUsers,
@@ -312,7 +312,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
collabratecUsers: this.collabratecUsers
}
}
return expect(this.ProjectModel.updateOne).to.have.been.calledWith(
return expect(this.ProjectModel.update).to.have.been.calledWith(
{ _id: this.projectId },
update,
this.callback
@@ -322,7 +322,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('when update has error', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub().yields('error')
this.ProjectModel.update = sinon.stub().yields('error')
return this.ProjectCollabratecDetailsHandler.setCollabratecUsers(
this.projectId,
this.collabratecUsers,
@@ -337,7 +337,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('with invalid project_id', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub()
this.ProjectModel.update = sinon.stub()
return this.ProjectCollabratecDetailsHandler.setCollabratecUsers(
'bad-project-id',
this.collabratecUsers,
@@ -346,7 +346,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
})
it('should not update', function() {
return expect(this.ProjectModel.updateOne).not.to.have.been.called
return expect(this.ProjectModel.update).not.to.have.been.called
})
it('should callback with error', function() {
@@ -357,7 +357,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('with invalid user_id', function() {
beforeEach(function() {
this.collabratecUsers[1].user_id = 'bad-user-id'
this.ProjectModel.updateOne = sinon.stub()
this.ProjectModel.update = sinon.stub()
return this.ProjectCollabratecDetailsHandler.setCollabratecUsers(
this.projectId,
this.collabratecUsers,
@@ -366,7 +366,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
})
it('should not update', function() {
return expect(this.ProjectModel.updateOne).not.to.have.been.called
return expect(this.ProjectModel.update).not.to.have.been.called
})
it('should callback with error', function() {
@@ -378,7 +378,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('unlinkCollabratecUserProject', function() {
describe('when update succeeds', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub().yields()
this.ProjectModel.update = sinon.stub().yields()
return this.ProjectCollabratecDetailsHandler.unlinkCollabratecUserProject(
this.projectId,
this.userId,
@@ -395,7 +395,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
}
}
}
return expect(this.ProjectModel.updateOne).to.have.been.calledWith(
return expect(this.ProjectModel.update).to.have.been.calledWith(
query,
update,
this.callback
@@ -405,7 +405,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('when update has error', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub().yields('error')
this.ProjectModel.update = sinon.stub().yields('error')
return this.ProjectCollabratecDetailsHandler.unlinkCollabratecUserProject(
this.projectId,
this.userId,
@@ -420,7 +420,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('with invalid args', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub()
this.ProjectModel.update = sinon.stub()
return this.ProjectCollabratecDetailsHandler.unlinkCollabratecUserProject(
'bad-project-id',
'bad-user-id',
@@ -429,7 +429,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
})
it('should not update', function() {
return expect(this.ProjectModel.updateOne).not.to.have.been.called
return expect(this.ProjectModel.update).not.to.have.been.called
})
it('should callback with error', function() {
@@ -441,7 +441,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('updateCollabratecUserIds', function() {
describe('when update succeeds', function() {
beforeEach(function() {
this.ProjectModel.updateMany = sinon.stub().yields()
this.ProjectModel.update = sinon.stub().yields()
return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds(
this.userId,
this.userId2,
@@ -450,9 +450,10 @@ describe('ProjectCollabratecDetailsHandler', function() {
})
it('should update project model', function() {
return expect(this.ProjectModel.updateMany).to.have.been.calledWith(
return expect(this.ProjectModel.update).to.have.been.calledWith(
{ 'collabratecUsers.user_id': this.userId },
{ $set: { 'collabratecUsers.$.user_id': this.userId2 } },
{ multi: true },
this.callback
)
})
@@ -460,7 +461,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('when update has error', function() {
beforeEach(function() {
this.ProjectModel.updateMany = sinon.stub().yields('error')
this.ProjectModel.update = sinon.stub().yields('error')
return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds(
this.userId,
this.userId2,
@@ -475,7 +476,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('with invalid old_user_id', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub()
this.ProjectModel.update = sinon.stub()
return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds(
'bad-user-id',
this.userId2,
@@ -484,7 +485,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
})
it('should not update', function() {
return expect(this.ProjectModel.updateOne).not.to.have.been.called
return expect(this.ProjectModel.update).not.to.have.been.called
})
it('should callback with error', function() {
@@ -494,7 +495,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
describe('with invalid new_user_id', function() {
beforeEach(function() {
this.ProjectModel.updateOne = sinon.stub()
this.ProjectModel.update = sinon.stub()
return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds(
this.userId,
'bad-user-id',
@@ -503,7 +504,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
})
it('should not update', function() {
return expect(this.ProjectModel.updateOne).not.to.have.been.called
return expect(this.ProjectModel.update).not.to.have.been.called
})
it('should callback with error', function() {
@@ -162,7 +162,7 @@ describe('ProjectDeleter', function() {
describe('mark as deleted by external source', function() {
beforeEach(function() {
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{ _id: this.project._id },
{ deletedByExternalDataSource: true }
@@ -191,7 +191,7 @@ describe('ProjectDeleter', function() {
describe('unmarkAsDeletedByExternalSource', function() {
beforeEach(async function() {
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{ _id: this.project._id },
{ deletedByExternalDataSource: false }
@@ -220,11 +220,11 @@ describe('ProjectDeleter', function() {
.withArgs({ _id: project._id })
.chain('exec')
.resolves(project)
this.ProjectMock.expects('deleteOne')
this.ProjectMock.expects('remove')
.withArgs({ _id: project._id })
.chain('exec')
.resolves()
this.DeletedProjectMock.expects('updateOne')
this.DeletedProjectMock.expects('update')
.withArgs(
{ 'deleterData.deletedProjectId': project._id },
{
@@ -284,10 +284,10 @@ describe('ProjectDeleter', function() {
this.deleterData.deleterIpAddress = this.ip
this.deleterData.deleterId = this.user._id
this.ProjectMock.expects('deleteOne')
this.ProjectMock.expects('remove')
.chain('exec')
.resolves()
this.DeletedProjectMock.expects('updateOne')
this.DeletedProjectMock.expects('update')
.withArgs(
{ 'deleterData.deletedProjectId': this.project._id },
{
@@ -306,10 +306,10 @@ describe('ProjectDeleter', function() {
})
it('should flushProjectToMongoAndDelete in doc updater', async function() {
this.ProjectMock.expects('deleteOne')
this.ProjectMock.expects('remove')
.chain('exec')
.resolves()
this.DeletedProjectMock.expects('updateOne').resolves()
this.DeletedProjectMock.expects('update').resolves()
await this.ProjectDeleter.promises.deleteProject(this.project._id, {
deleterUser: this.user,
@@ -321,10 +321,10 @@ describe('ProjectDeleter', function() {
})
it('should removeProjectFromAllTags', async function() {
this.ProjectMock.expects('deleteOne')
this.ProjectMock.expects('remove')
.chain('exec')
.resolves()
this.DeletedProjectMock.expects('updateOne').resolves()
this.DeletedProjectMock.expects('update').resolves()
await this.ProjectDeleter.promises.deleteProject(this.project._id)
sinon.assert.calledWith(
@@ -340,11 +340,11 @@ describe('ProjectDeleter', function() {
})
it('should remove the project from Mongo', async function() {
this.ProjectMock.expects('deleteOne')
this.ProjectMock.expects('remove')
.withArgs({ _id: this.project._id })
.chain('exec')
.resolves()
this.DeletedProjectMock.expects('updateOne').resolves()
this.DeletedProjectMock.expects('update').resolves()
await this.ProjectDeleter.promises.deleteProject(this.project._id)
this.ProjectMock.verify()
@@ -372,7 +372,7 @@ describe('ProjectDeleter', function() {
})
.chain('exec')
.resolves(deletedProject)
this.DeletedProjectMock.expects('updateOne')
this.DeletedProjectMock.expects('update')
.withArgs(
{
_id: deletedProject._id
@@ -398,7 +398,7 @@ describe('ProjectDeleter', function() {
describe('expireDeletedProject', function() {
beforeEach(async function() {
this.DeletedProjectMock.expects('updateOne')
this.DeletedProjectMock.expects('update')
.withArgs(
{
_id: this.deletedProjects[0]._id
@@ -458,7 +458,7 @@ describe('ProjectDeleter', function() {
.chain('exec')
.resolves(this.project)
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{ _id: this.project._id },
{
@@ -500,7 +500,7 @@ describe('ProjectDeleter', function() {
.chain('exec')
.resolves(this.project)
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs({ _id: this.project._id }, { $set: { archived: archived } })
.resolves()
})
@@ -536,7 +536,7 @@ describe('ProjectDeleter', function() {
.chain('exec')
.resolves(this.project)
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{ _id: this.project._id },
{
@@ -575,7 +575,7 @@ describe('ProjectDeleter', function() {
.chain('exec')
.resolves(this.project)
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{ _id: this.project._id },
{ $pull: { trashed: ObjectId(this.user._id) } }
@@ -594,7 +594,7 @@ describe('ProjectDeleter', function() {
describe('restoreProject', function() {
beforeEach(function() {
this.ProjectMock.expects('updateOne')
this.ProjectMock.expects('update')
.withArgs(
{
_id: this.project._id
@@ -43,7 +43,7 @@ describe('ProjectDetailsHandler', function() {
exec: sinon.stub().resolves()
}
this.ProjectModel = {
updateOne: sinon.stub().returns(this.ProjectModelUpdateQuery)
update: sinon.stub().returns(this.ProjectModelUpdateQuery)
}
this.UserGetter = {
promises: {
@@ -156,7 +156,7 @@ describe('ProjectDetailsHandler', function() {
this.project._id,
this.description
)
expect(this.ProjectModel.updateOne).to.have.been.calledWith(
expect(this.ProjectModel.update).to.have.been.calledWith(
{ _id: this.project._id },
{ description: this.description }
)
@@ -170,7 +170,7 @@ describe('ProjectDetailsHandler', function() {
it('should update the project with the new name', async function() {
await this.handler.promises.renameProject(this.project._id, this.newName)
expect(this.ProjectModel.updateOne).to.have.been.calledWith(
expect(this.ProjectModel.update).to.have.been.calledWith(
{ _id: this.project._id },
{ name: this.newName }
)
@@ -191,7 +191,7 @@ describe('ProjectDetailsHandler', function() {
await expect(this.handler.promises.renameProject(this.project._id)).to.be
.rejected
expect(this.TpdsUpdateSender.promises.moveEntity).not.to.have.been.called
expect(this.ProjectModel.updateOne).not.to.have.been.called
expect(this.ProjectModel.update).not.to.have.been.called
})
})
@@ -401,7 +401,7 @@ describe('ProjectDetailsHandler', function() {
this.project._id,
this.accessLevel
)
expect(this.ProjectModel.updateOne).to.have.been.calledWith(
expect(this.ProjectModel.update).to.have.been.calledWith(
{ _id: this.project._id },
{ publicAccesLevel: this.accessLevel }
)
@@ -459,7 +459,7 @@ describe('ProjectDetailsHandler', function() {
it('should not update the project with new tokens', async function() {
await this.handler.promises.ensureTokensArePresent(this.project._id)
expect(this.ProjectModel.updateOne).not.to.have.been.called
expect(this.ProjectModel.update).not.to.have.been.called
})
it('should produce the tokens without error', async function() {
@@ -503,8 +503,8 @@ describe('ProjectDetailsHandler', function() {
.to.have.been.calledOnce
expect(this.ProjectTokenGenerator.readAndWriteToken).to.have.been
.calledOnce
expect(this.ProjectModel.updateOne).to.have.been.calledOnce
expect(this.ProjectModel.updateOne).to.have.been.calledWith(
expect(this.ProjectModel.update).to.have.been.calledOnce
expect(this.ProjectModel.update).to.have.been.calledWith(
{ _id: this.project._id },
{
$set: {
@@ -534,7 +534,7 @@ describe('ProjectDetailsHandler', function() {
describe('clearTokens', function() {
it('clears the tokens from the project', async function() {
await this.handler.promises.clearTokens(this.project._id)
expect(this.ProjectModel.updateOne).to.have.been.calledWith(
expect(this.ProjectModel.update).to.have.been.calledWith(
{ _id: this.project._id },
{ $unset: { tokens: 1 }, $set: { publicAccesLevel: 'private' } }
)
@@ -96,7 +96,7 @@ describe('ProjectEntityUpdateHandler', function() {
)
}
this.ProjectModel = {
updateOne: sinon.stub()
update: sinon.stub()
}
this.ProjectGetter = {
getProject: sinon.stub(),
@@ -385,7 +385,7 @@ describe('ProjectEntityUpdateHandler', function() {
this.rootDocId = 'root-doc-id-123123'
})
it('should call Project.updateOne when the doc exists and has a valid extension', function() {
it('should call Project.update when the doc exists and has a valid extension', function() {
this.ProjectEntityHandler.getDocPathByProjectIdAndDocId.yields(
null,
`/main.tex`
@@ -396,12 +396,12 @@ describe('ProjectEntityUpdateHandler', function() {
this.rootDocId,
() => {}
)
this.ProjectModel.updateOne
this.ProjectModel.update
.calledWith({ _id: projectId }, { rootDoc_id: this.rootDocId })
.should.equal(true)
})
it("should not call Project.updateOne when the doc doesn't exist", function() {
it("should not call Project.update when the doc doesn't exist", function() {
this.ProjectEntityHandler.getDocPathByProjectIdAndDocId.yields(
Errors.NotFoundError
)
@@ -411,7 +411,7 @@ describe('ProjectEntityUpdateHandler', function() {
this.rootDocId,
() => {}
)
this.ProjectModel.updateOne
this.ProjectModel.update
.calledWith({ _id: projectId }, { rootDoc_id: this.rootDocId })
.should.equal(false)
})
@@ -434,9 +434,9 @@ describe('ProjectEntityUpdateHandler', function() {
})
describe('unsetRootDoc', function() {
it('should call Project.updateOne', function() {
it('should call Project.update', function() {
this.ProjectEntityUpdateHandler.unsetRootDoc(projectId)
this.ProjectModel.updateOne
this.ProjectModel.update
.calledWith({ _id: projectId }, { $unset: { rootDoc_id: true } })
.should.equal(true)
})
@@ -83,9 +83,7 @@ describe('ProjectHistoryHandler', function() {
.stub()
.withArgs(project_id)
.callsArgWith(1, null, this.project)
this.ProjectModel.updateOne = sinon
.stub()
.callsArgWith(2, null, { n: 1 })
this.ProjectModel.update = sinon.stub().callsArgWith(2, null, { n: 1 })
return this.ProjectHistoryHandler.ensureHistoryExistsForProject(
project_id,
this.callback
@@ -103,7 +101,7 @@ describe('ProjectHistoryHandler', function() {
})
it('should set the new history id on the project', function() {
return this.ProjectModel.updateOne
return this.ProjectModel.update
.calledWith(
{ _id: project_id, 'overleaf.history.id': { $exists: false } },
{ 'overleaf.history.id': this.newHistoryId }
@@ -135,7 +133,7 @@ describe('ProjectHistoryHandler', function() {
.stub()
.withArgs(project_id)
.callsArgWith(1, null, this.project)
this.ProjectModel.updateOne = sinon.stub()
this.ProjectModel.update = sinon.stub()
return this.ProjectHistoryHandler.ensureHistoryExistsForProject(
project_id,
this.callback
@@ -153,7 +151,7 @@ describe('ProjectHistoryHandler', function() {
})
it('should not set the new history id on the project', function() {
return this.ProjectModel.updateOne.called.should.equal(false)
return this.ProjectModel.update.called.should.equal(false)
})
it('should not resync the project history', function() {
@@ -29,7 +29,7 @@ describe('ProjectOptionsHandler', function() {
this.projectModel = Project = class Project {
constructor(options) {}
}
this.projectModel.updateOne = sinon.stub().yields()
this.projectModel.update = sinon.stub().yields()
this.handler = SandboxedModule.require(modulePath, {
globals: {
@@ -59,7 +59,7 @@ describe('ProjectOptionsHandler', function() {
describe('Setting the compiler', function() {
it('should perform and update on mongo', function(done) {
this.handler.setCompiler(project_id, 'xeLaTeX', err => {
const args = this.projectModel.updateOne.args[0]
const args = this.projectModel.update.args[0]
args[0]._id.should.equal(project_id)
args[1].compiler.should.equal('xelatex')
done()
@@ -68,7 +68,7 @@ describe('ProjectOptionsHandler', function() {
it('should not perform and update on mongo if it is not a recognised compiler', function(done) {
this.handler.setCompiler(project_id, 'something', err => {
this.projectModel.updateOne.called.should.equal(false)
this.projectModel.update.called.should.equal(false)
done()
})
})
@@ -77,7 +77,7 @@ describe('ProjectOptionsHandler', function() {
it('should callback with null', function(done) {
this.handler.setCompiler(project_id, null, err => {
expect(err).to.be.undefined
this.projectModel.updateOne.callCount.should.equal(0)
this.projectModel.update.callCount.should.equal(0)
done()
})
})
@@ -85,7 +85,7 @@ describe('ProjectOptionsHandler', function() {
describe('when mongo update error occurs', function() {
beforeEach(function() {
this.projectModel.updateOne = sinon.stub().yields('error')
this.projectModel.update = sinon.stub().yields('error')
})
it('should callback with error', function(done) {
@@ -100,7 +100,7 @@ describe('ProjectOptionsHandler', function() {
describe('Setting the imageName', function() {
it('should perform and update on mongo', function(done) {
this.handler.setImageName(project_id, 'texlive-1234.5', err => {
const args = this.projectModel.updateOne.args[0]
const args = this.projectModel.update.args[0]
args[0]._id.should.equal(project_id)
args[1].imageName.should.equal('docker-repo/subdir/texlive-1234.5')
done()
@@ -109,7 +109,7 @@ describe('ProjectOptionsHandler', function() {
it('should not perform and update on mongo if it is not a reconised compiler', function(done) {
this.handler.setImageName(project_id, 'something', err => {
this.projectModel.updateOne.called.should.equal(false)
this.projectModel.update.called.should.equal(false)
done()
})
})
@@ -118,7 +118,7 @@ describe('ProjectOptionsHandler', function() {
it('should callback with null', function(done) {
this.handler.setImageName(project_id, null, err => {
expect(err).to.be.undefined
this.projectModel.updateOne.callCount.should.equal(0)
this.projectModel.update.callCount.should.equal(0)
done()
})
})
@@ -126,7 +126,7 @@ describe('ProjectOptionsHandler', function() {
describe('when mongo update error occurs', function() {
beforeEach(function() {
this.projectModel.updateOne = sinon.stub().yields('error')
this.projectModel.update = sinon.stub().yields('error')
})
it('should callback with error', function(done) {
@@ -141,7 +141,7 @@ describe('ProjectOptionsHandler', function() {
describe('setting the spellCheckLanguage', function() {
it('should perform and update on mongo', function(done) {
this.handler.setSpellCheckLanguage(project_id, 'fr', err => {
const args = this.projectModel.updateOne.args[0]
const args = this.projectModel.update.args[0]
args[0]._id.should.equal(project_id)
args[1].spellCheckLanguage.should.equal('fr')
done()
@@ -150,21 +150,21 @@ describe('ProjectOptionsHandler', function() {
it('should not perform and update on mongo if it is not a reconised compiler', function(done) {
this.handler.setSpellCheckLanguage(project_id, 'no a lang', err => {
this.projectModel.updateOne.called.should.equal(false)
this.projectModel.update.called.should.equal(false)
done()
})
})
it('should perform and update on mongo if the language is blank (means turn it off)', function(done) {
this.handler.setSpellCheckLanguage(project_id, '', err => {
this.projectModel.updateOne.called.should.equal(true)
this.projectModel.update.called.should.equal(true)
done()
})
})
describe('when mongo update error occurs', function() {
beforeEach(function() {
this.projectModel.updateOne = sinon.stub().yields('error')
this.projectModel.update = sinon.stub().yields('error')
})
it('should callback with error', function(done) {
@@ -179,7 +179,7 @@ describe('ProjectOptionsHandler', function() {
describe('setting the brandVariationId', function() {
it('should perform and update on mongo', function(done) {
this.handler.setBrandVariationId(project_id, '123', err => {
const args = this.projectModel.updateOne.args[0]
const args = this.projectModel.update.args[0]
args[0]._id.should.equal(project_id)
args[1].brandVariationId.should.equal('123')
done()
@@ -188,21 +188,21 @@ describe('ProjectOptionsHandler', function() {
it('should not perform and update on mongo if there is no brand variation', function(done) {
this.handler.setBrandVariationId(project_id, null, err => {
this.projectModel.updateOne.called.should.equal(false)
this.projectModel.update.called.should.equal(false)
done()
})
})
it('should not perform and update on mongo if brand variation is an empty string', function(done) {
this.handler.setBrandVariationId(project_id, '', err => {
this.projectModel.updateOne.called.should.equal(false)
this.projectModel.update.called.should.equal(false)
done()
})
})
describe('when mongo update error occurs', function() {
beforeEach(function() {
this.projectModel.updateOne = sinon.stub().yields('error')
this.projectModel.update = sinon.stub().yields('error')
})
it('should callback with error', function(done) {
@@ -217,7 +217,7 @@ describe('ProjectOptionsHandler', function() {
describe('unsetting the brandVariationId', function() {
it('should perform and update on mongo', function(done) {
this.handler.unsetBrandVariationId(project_id, err => {
const args = this.projectModel.updateOne.args[0]
const args = this.projectModel.update.args[0]
args[0]._id.should.equal(project_id)
expect(args[1]).to.deep.equal({ $unset: { brandVariationId: 1 } })
done()
@@ -226,7 +226,7 @@ describe('ProjectOptionsHandler', function() {
describe('when mongo update error occurs', function() {
beforeEach(function() {
this.projectModel.updateOne = sinon.stub().yields('error')
this.projectModel.update = sinon.stub().yields('error')
})
it('should callback with error', function(done) {
@@ -27,7 +27,7 @@ describe('ProjectUpdateHandler', function() {
beforeEach(function() {
let Project
this.ProjectModel = Project = class Project {}
this.ProjectModel.updateOne = sinon.stub().callsArg(3)
this.ProjectModel.update = sinon.stub().callsArg(3)
return (this.handler = SandboxedModule.require(modulePath, {
globals: {
console: console
@@ -53,7 +53,7 @@ describe('ProjectUpdateHandler', function() {
this.lastUpdatedBy,
err => {
sinon.assert.calledWith(
this.ProjectModel.updateOne,
this.ProjectModel.update,
{
_id: this.project_id,
lastUpdated: { $lt: this.lastUpdatedAt }
@@ -71,7 +71,7 @@ describe('ProjectUpdateHandler', function() {
it('should set smart fallbacks', function(done) {
return this.handler.markAsUpdated(this.project_id, null, null, err => {
sinon.assert.calledWithMatch(
this.ProjectModel.updateOne,
this.ProjectModel.update,
{
_id: this.project_id,
lastUpdated: { $lt: this.fakeTime }
@@ -90,7 +90,7 @@ describe('ProjectUpdateHandler', function() {
it('should send an update to mongo', function(done) {
const project_id = 'project_id'
return this.handler.markAsOpened(project_id, err => {
const args = this.ProjectModel.updateOne.args[0]
const args = this.ProjectModel.update.args[0]
args[0]._id.should.equal(project_id)
const date = args[1].lastOpened + ''
const now = Date.now() + ''
@@ -104,7 +104,7 @@ describe('ProjectUpdateHandler', function() {
it('should send an update to mongo', function(done) {
const project_id = 'project_id'
return this.handler.markAsInactive(project_id, err => {
const args = this.ProjectModel.updateOne.args[0]
const args = this.ProjectModel.update.args[0]
args[0]._id.should.equal(project_id)
args[1].active.should.equal(false)
return done()
@@ -116,7 +116,7 @@ describe('ProjectUpdateHandler', function() {
it('should send an update to mongo', function(done) {
const project_id = 'project_id'
return this.handler.markAsActive(project_id, err => {
const args = this.ProjectModel.updateOne.args[0]
const args = this.ProjectModel.update.args[0]
args[0]._id.should.equal(project_id)
args[1].active.should.equal(true)
return done()
@@ -30,7 +30,7 @@ describe('ReferalAllocator', function() {
this.user_id = 'user-id-123'
this.new_user_id = 'new-user-id-123'
this.FeaturesUpdater.refreshFeatures = sinon.stub().yields()
this.User.updateOne = sinon.stub().callsArgWith(3, null)
this.User.update = sinon.stub().callsArgWith(3, null)
this.User.findOne = sinon
.stub()
.callsArgWith(2, null, { _id: this.user_id })
@@ -50,7 +50,7 @@ describe('ReferalAllocator', function() {
})
it('should update the referring user with the refered users id', function() {
this.User.updateOne
this.User.update
.calledWith(
{
referal_id: this.referal_id
@@ -105,7 +105,7 @@ describe('ReferalAllocator', function() {
})
it('should not update the referring user with the refered users id', function() {
this.User.updateOne.called.should.equal(false)
this.User.update.called.should.equal(false)
})
it('should not assign the user a bonus', function() {
@@ -130,7 +130,7 @@ describe('ReferalAllocator', function() {
})
it('should not update the referring user with the refered users id', function() {
this.User.updateOne.called.should.equal(false)
this.User.update.called.should.equal(false)
})
it('find the referring users id', function() {
@@ -68,8 +68,7 @@ describe('SubscriptionGroupHandler', function() {
this.EmailHandler = { sendEmail: sinon.stub() }
this.Subscription = {
updateOne: sinon.stub().yields(),
updateMany: sinon.stub().yields(),
update: sinon.stub().yields(),
findOne: sinon.stub().yields()
}
@@ -144,36 +143,38 @@ describe('SubscriptionGroupHandler', function() {
})
it('replaces the admin_id', function() {
return this.Subscription.updateOne
return this.Subscription.update
.calledWith({ admin_id: this.oldId }, { admin_id: this.newId })
.should.equal(true)
})
it('replaces the manager_ids', function() {
this.Subscription.updateMany
this.Subscription.update
.calledWith(
{ manager_ids: 'ba5eba11' },
{ $addToSet: { manager_ids: '5ca1ab1e' } }
{ $addToSet: { manager_ids: '5ca1ab1e' } },
{ multi: true }
)
.should.equal(true)
return this.Subscription.updateMany
return this.Subscription.update
.calledWith(
{ manager_ids: 'ba5eba11' },
{ $pull: { manager_ids: 'ba5eba11' } }
{ $pull: { manager_ids: 'ba5eba11' } },
{ multi: true }
)
.should.equal(true)
})
it('replaces the member ids', function() {
this.Subscription.updateMany
this.Subscription.update
.calledWith(
{ member_ids: this.oldId },
{ $addToSet: { member_ids: this.newId } }
)
.should.equal(true)
return this.Subscription.updateMany
return this.Subscription.update
.calledWith(
{ member_ids: this.oldId },
{ $pull: { member_ids: this.oldId } }
@@ -40,6 +40,9 @@ describe('SubscriptionUpdater', function() {
this.updateStub = sinon.stub().callsArgWith(2, null)
this.updateManyStub = sinon.stub().callsArgWith(2, null)
this.findAndModifyStub = sinon
.stub()
.callsArgWith(2, null, this.subscription)
this.findOneAndUpdateStub = sinon
.stub()
.callsArgWith(2, null, this.subscription)
@@ -53,9 +56,10 @@ describe('SubscriptionUpdater', function() {
return subscription
}
}
this.SubscriptionModel.deleteOne = sinon.stub().yields()
this.SubscriptionModel.updateOne = this.updateStub
this.SubscriptionModel.remove = sinon.stub().yields()
this.SubscriptionModel.update = this.updateStub
this.SubscriptionModel.updateMany = this.updateManyStub
this.SubscriptionModel.findAndModify = this.findAndModifyStub
this.SubscriptionModel.findOneAndUpdate = this.findOneAndUpdateStub
this.SubscriptionLocator = {
@@ -134,8 +138,8 @@ describe('SubscriptionUpdater', function() {
$set: { admin_id: ObjectId(this.otherUserId) },
$addToSet: { manager_ids: ObjectId(this.otherUserId) }
}
this.SubscriptionModel.updateOne.should.have.been.calledOnce
this.SubscriptionModel.updateOne.should.have.been.calledWith(
this.SubscriptionModel.update.should.have.been.calledOnce
this.SubscriptionModel.update.should.have.been.calledWith(
query,
update
)
@@ -162,8 +166,8 @@ describe('SubscriptionUpdater', function() {
manager_ids: [ObjectId(this.otherUserId)]
}
}
this.SubscriptionModel.updateOne.should.have.been.calledOnce
this.SubscriptionModel.updateOne.should.have.been.calledWith(
this.SubscriptionModel.update.should.have.been.calledOnce
this.SubscriptionModel.update.should.have.been.calledWith(
query,
update
)
@@ -398,7 +402,7 @@ describe('SubscriptionUpdater', function() {
const insertOperation = {
$addToSet: { member_ids: { $each: [this.otherUserId] } }
}
this.updateStub
this.findAndModifyStub
.calledWith(searchOps, insertOperation)
.should.equal(true)
done()
@@ -485,7 +489,7 @@ describe('SubscriptionUpdater', function() {
})
it('should remove the subscription', function() {
this.SubscriptionModel.deleteOne
this.SubscriptionModel.remove
.calledWith({ _id: this.subscription._id })
.should.equal(true)
})
@@ -54,7 +54,7 @@ describe('TeamInvitesHandler', function() {
this.Subscription = {
findOne: sinon.stub().yields(),
updateOne: sinon.stub().yields()
update: sinon.stub().yields()
}
this.EmailHandler = {
@@ -201,7 +201,7 @@ describe('TeamInvitesHandler', function() {
this.subscription,
'John.Snow@example.com',
(err, invite) => {
this.Subscription.updateOne
this.Subscription.update
.calledWith(
{ _id: new ObjectId('55153a8014829a865bbf700d') },
{ $pull: { invited_emails: 'john.snow@example.com' } }
@@ -293,7 +293,7 @@ describe('TeamInvitesHandler', function() {
it('removes the invite from the subscription', function(done) {
this.TeamInvitesHandler.acceptInvite('dddddddd', this.user.id, () => {
this.Subscription.updateOne
this.Subscription.update
.calledWith(
{ _id: new ObjectId('55153a8014829a865bbf700d') },
{ $pull: { teamInvites: { email: 'john.snow@example.com' } } }
@@ -311,14 +311,14 @@ describe('TeamInvitesHandler', function() {
this.subscription,
'jorah@example.com',
() => {
this.Subscription.updateOne
this.Subscription.update
.calledWith(
{ _id: new ObjectId('55153a8014829a865bbf700d') },
{ $pull: { teamInvites: { email: 'jorah@example.com' } } }
)
.should.eq(true)
this.Subscription.updateOne
this.Subscription.update
.calledWith(
{ _id: new ObjectId('55153a8014829a865bbf700d') },
{ $pull: { invited_emails: 'jorah@example.com' } }
@@ -21,7 +21,7 @@ const { assert } = require('chai')
describe('UserFeaturesUpdater', function() {
beforeEach(function() {
this.User = { updateOne: sinon.stub().callsArgWith(2) }
this.User = { update: sinon.stub().callsArgWith(2) }
return (this.UserFeaturesUpdater = SandboxedModule.require(modulePath, {
globals: {
console: console
@@ -49,7 +49,7 @@ describe('UserFeaturesUpdater', function() {
'features.versioning': true,
'features.collaborators': 10
}
this.User.updateOne
this.User.update
.calledWith({ _id: user_id }, update)
.should.equal(true)
features.should.deep.equal(this.features)
@@ -53,12 +53,12 @@ describe('SystemMessageManager', function() {
describe('clearMessages', function() {
beforeEach(function() {
this.SystemMessage.deleteMany = sinon.stub().callsArg(1)
this.SystemMessage.remove = sinon.stub().callsArg(1)
return this.SystemMessageManager.clearMessages(this.callback)
})
it('should remove the messages from the database', function() {
return this.SystemMessage.deleteMany.calledWith({}).should.equal(true)
return this.SystemMessage.remove.calledWith({}).should.equal(true)
})
it('should return the callback', function() {
@@ -124,7 +124,7 @@ describe('TagsHandler', function() {
describe('addProjectToTagName', function() {
it('should call update in mongo', function(done) {
this.TagMock.expects('updateOne')
this.TagMock.expects('update')
.once()
.withArgs(
{ name: this.tag.name, user_id: this.tag.userId },
@@ -148,11 +148,12 @@ describe('TagsHandler', function() {
describe('updateTagUserIds', function() {
it('should call update in mongo', function(done) {
this.newUserId = ObjectId().toString()
this.TagMock.expects('updateMany')
this.TagMock.expects('update')
.once()
.withArgs(
{ user_id: this.userId },
{ $set: { user_id: this.newUserId } }
{ $set: { user_id: this.newUserId } },
{ multi: true }
)
.yields()
this.TagsHandler.updateTagUserIds(this.userId, this.newUserId, err => {
@@ -166,7 +167,7 @@ describe('TagsHandler', function() {
describe('removeProjectFromTag', function() {
describe('with a valid tag_id', function() {
it('should call update in mongo', function(done) {
this.TagMock.expects('updateOne')
this.TagMock.expects('update')
.once()
.withArgs(
{
@@ -194,7 +195,7 @@ describe('TagsHandler', function() {
describe('removeProjectFromAllTags', function() {
it('should pull the project id from the tag', function(done) {
this.TagMock.expects('updateMany')
this.TagMock.expects('update')
.once()
.withArgs(
{
@@ -220,7 +221,7 @@ describe('TagsHandler', function() {
describe('deleteTag', function() {
describe('with a valid tag_id', function() {
it('should call remove in mongo', function(done) {
this.TagMock.expects('deleteOne')
this.TagMock.expects('remove')
.once()
.withArgs({ _id: this.tagId, user_id: this.userId })
.yields()
@@ -237,7 +238,7 @@ describe('TagsHandler', function() {
describe('with a valid tag_id', function() {
it('should call remove in mongo', function(done) {
this.newName = 'new name'
this.TagMock.expects('updateOne')
this.TagMock.expects('update')
.once()
.withArgs(
{ _id: this.tagId, user_id: this.userId },
@@ -62,7 +62,7 @@ describe('TemplatesManager', function() {
getProjectDescription: sinon.stub(),
fixProjectName: sinon.stub().returns(this.templateName)
}
this.Project = { updateOne: sinon.stub().callsArgWith(3, null) }
this.Project = { update: sinon.stub().callsArgWith(3, null) }
this.FileWriter = { ensureDumpFolderExists: sinon.stub().callsArg(0) }
this.TemplatesManager = SandboxedModule.require(modulePath, {
globals: {
@@ -174,7 +174,7 @@ describe('TemplatesManager', function() {
})
it('should update project', function() {
return this.Project.updateOne.should.have.been.calledWithMatch(
return this.Project.update.should.have.been.calledWithMatch(
{ _id: this.project_id },
{
fromV1TemplateId: this.templateId,
@@ -123,22 +123,22 @@ describe('TokenAccessHandler', function() {
describe('addReadOnlyUserToProject', function() {
beforeEach(function() {
return (this.Project.updateOne = sinon.stub().callsArgWith(2, null))
return (this.Project.update = sinon.stub().callsArgWith(2, null))
})
it('should call Project.updateOne', function(done) {
it('should call Project.update', function(done) {
return this.TokenAccessHandler.addReadOnlyUserToProject(
this.userId,
this.projectId,
err => {
expect(this.Project.updateOne.callCount).to.equal(1)
expect(this.Project.update.callCount).to.equal(1)
expect(
this.Project.updateOne.calledWith({
this.Project.update.calledWith({
_id: this.projectId
})
).to.equal(true)
expect(
this.Project.updateOne.lastCall.args[1].$addToSet
this.Project.update.lastCall.args[1]['$addToSet']
).to.have.keys('tokenAccessReadOnly_refs')
return done()
}
@@ -156,9 +156,9 @@ describe('TokenAccessHandler', function() {
)
})
describe('when Project.updateOne produces an error', function() {
describe('when Project.update produces an error', function() {
beforeEach(function() {
return (this.Project.updateOne = sinon
return (this.Project.update = sinon
.stub()
.callsArgWith(2, new Error('woops')))
})
@@ -178,22 +178,22 @@ describe('TokenAccessHandler', function() {
describe('addReadAndWriteUserToProject', function() {
beforeEach(function() {
return (this.Project.updateOne = sinon.stub().callsArgWith(2, null))
return (this.Project.update = sinon.stub().callsArgWith(2, null))
})
it('should call Project.updateOne', function(done) {
it('should call Project.update', function(done) {
return this.TokenAccessHandler.addReadAndWriteUserToProject(
this.userId,
this.projectId,
err => {
expect(this.Project.updateOne.callCount).to.equal(1)
expect(this.Project.update.callCount).to.equal(1)
expect(
this.Project.updateOne.calledWith({
this.Project.update.calledWith({
_id: this.projectId
})
).to.equal(true)
expect(
this.Project.updateOne.lastCall.args[1].$addToSet
this.Project.update.lastCall.args[1]['$addToSet']
).to.have.keys('tokenAccessReadAndWrite_refs')
return done()
}
@@ -211,9 +211,9 @@ describe('TokenAccessHandler', function() {
)
})
describe('when Project.updateOne produces an error', function() {
describe('when Project.update produces an error', function() {
beforeEach(function() {
return (this.Project.updateOne = sinon
return (this.Project.update = sinon
.stub()
.callsArgWith(2, new Error('woops')))
})
@@ -78,7 +78,7 @@ describe('SAMLIdentityManager', function() {
findOne: sinon.stub().returns({
exec: sinon.stub().resolves()
}),
updateOne: sinon.stub().returns({
update: sinon.stub().returns({
exec: sinon.stub().resolves()
})
})
@@ -226,7 +226,7 @@ describe('SAMLIdentityManager', function() {
expect(error).to.exist
expect(error).to.equal(anError)
expect(this.EmailHandler.sendEmail).to.not.have.been.called
expect(this.User.updateOne).to.not.have.been.called
expect(this.User.update).to.not.have.been.called
}
})
})
@@ -275,7 +275,7 @@ describe('SAMLIdentityManager', function() {
ipAddress: '0:0:0:0'
},
() => {
expect(this.User.updateOne).to.have.been.called
expect(this.User.update).to.have.been.called
expect(this.EmailHandler.sendEmail).to.have.been.calledOnce
const emailArgs = this.EmailHandler.sendEmail.lastCall.args
expect(emailArgs[0]).to.equal('securityAlert')
@@ -332,7 +332,7 @@ describe('SAMLIdentityManager', function() {
}
}
}
expect(this.User.updateOne).to.have.been.calledOnce.and.calledWithMatch(
expect(this.User.update).to.have.been.calledOnce.and.calledWithMatch(
query,
update
)
@@ -346,7 +346,7 @@ describe('SAMLIdentityManager', function() {
'Overleaf University',
this.auditLog
)
expect(this.User.updateOne).to.have.been.called
expect(this.User.update).to.have.been.called
expect(this.EmailHandler.sendEmail).to.have.been.calledOnce
const emailArgs = this.EmailHandler.sendEmail.lastCall.args
expect(emailArgs[0]).to.equal('securityAlert')
@@ -376,7 +376,7 @@ describe('SAMLIdentityManager', function() {
expect(error).to.exist
expect(error).to.equal(anError)
expect(this.EmailHandler.sendEmail).to.not.have.been.called
expect(this.User.updateOne).to.not.have.been.called
expect(this.User.update).to.not.have.been.called
}
})
})
@@ -147,7 +147,7 @@ describe('UserDeleter', function() {
describe('when no options are passed', function() {
beforeEach(function() {
this.DeletedUserMock.expects('updateOne')
this.DeletedUserMock.expects('update')
.withArgs(
{ 'deleterData.deletedUserId': this.userId },
this.deletedUser,
@@ -274,7 +274,7 @@ describe('UserDeleter', function() {
this.deletedUser.deleterData.deleterIpAddress = this.ipAddress
this.deletedUser.deleterData.deleterId = this.deleterId
this.DeletedUserMock.expects('updateOne')
this.DeletedUserMock.expects('update')
.withArgs(
{ 'deleterData.deletedUserId': this.userId },
this.deletedUser,
@@ -26,7 +26,7 @@ const EmailHelper = require('../../../../app/src/Features/Helpers/EmailHelper')
describe('UserRegistrationHandler', function() {
beforeEach(function() {
this.user = { _id: (this.user_id = '31j2lk21kjl') }
this.User = { updateOne: sinon.stub().callsArgWith(2) }
this.User = { update: sinon.stub().callsArgWith(2) }
this.UserGetter = { getUserByAnyEmail: sinon.stub() }
this.UserCreator = {
createNewUser: sinon.stub().callsArgWith(2, null, this.user)
@@ -129,7 +129,7 @@ describe('UserRegistrationHandler', function() {
it('should set holding account to false', function(done) {
return this.handler.registerNewUser(this.passingRequest, err => {
const update = this.User.updateOne.args[0]
const update = this.User.update.args[0]
assert.deepEqual(update[0], { _id: this.user._id })
assert.deepEqual(update[1], { $set: { holdingAccount: false } })
return done()
@@ -43,13 +43,13 @@ describe('UserMembershipHandler', function() {
_id: 'mock-institution-id',
v1Id: 123,
managerIds: [ObjectId(), ObjectId(), ObjectId()],
updateOne: sinon.stub().yields(null)
update: sinon.stub().yields(null)
}
this.publisher = {
_id: 'mock-publisher-id',
slug: 'slug',
managerIds: [ObjectId(), ObjectId()],
updateOne: sinon.stub().yields(null)
update: sinon.stub().yields(null)
}
this.UserMembershipViewModel = {
@@ -228,7 +228,7 @@ describe('UserMembershipHandler', function() {
EntityConfigs.institution,
this.email,
(error, user) => {
assertCalledWith(this.institution.updateOne, {
assertCalledWith(this.institution.update, {
$addToSet: { managerIds: this.newUser._id }
})
return done()
@@ -258,8 +258,8 @@ describe('UserMembershipHandler', function() {
EntityConfigs.institution,
this.newUser._id,
(error, user) => {
const { lastCall } = this.institution.updateOne
assertCalledWith(this.institution.updateOne, {
const { lastCall } = this.institution.update
assertCalledWith(this.institution.update, {
$pull: { managerIds: this.newUser._id }
})
return done()