From 94092c905b121d012ed65c031150d5b44e63a1bd Mon Sep 17 00:00:00 2001 From: Simon Detheridge Date: Mon, 9 Nov 2020 10:35:57 +0000 Subject: [PATCH] Merge pull request #3370 from overleaf/jpa-replace-count [misc] replace mongo .count queries GitOrigin-RevId: 7963286b4d84d1f03978f3212e92bb491eec6b74 --- .../Collaborators/CollaboratorsInviteHandler.js | 2 +- services/web/test/acceptance/src/ModelTests.js | 2 +- .../Collaborators/CollaboratorsInviteHandlerTests.js | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.js b/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.js index 64d4e45ce6..7e9bdb41dc 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.js +++ b/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.js @@ -51,7 +51,7 @@ const CollaboratorsInviteHandler = { callback = function(err, count) {} } logger.log({ projectId }, 'counting invites for project') - return ProjectInvite.count({ projectId }, function(err, count) { + return ProjectInvite.countDocuments({ projectId }, function(err, count) { if (err != null) { OError.tag(err, 'error getting invites from mongo', { projectId diff --git a/services/web/test/acceptance/src/ModelTests.js b/services/web/test/acceptance/src/ModelTests.js index f625182da7..25ca8a4790 100644 --- a/services/web/test/acceptance/src/ModelTests.js +++ b/services/web/test/acceptance/src/ModelTests.js @@ -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.count({ email: email })).to.eventually.equal(1) + await expect(User.countDocuments({ email: email })).to.eventually.equal(1) }) }) diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js index fd935685a5..a9feeaa883 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js +++ b/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js @@ -35,7 +35,7 @@ describe('CollaboratorsInviteHandler', function() { this.findOne = sinon.stub() this.find = sinon.stub() this.deleteOne = sinon.stub() - this.count = sinon.stub() + this.countDocuments = sinon.stub() } constructor(options) { if (options == null) { @@ -105,7 +105,7 @@ describe('CollaboratorsInviteHandler', function() { describe('getInviteCount', function() { beforeEach(function() { - this.ProjectInvite.count.callsArgWith(1, null, 2) + this.ProjectInvite.countDocuments.callsArgWith(1, null, 2) return (this.call = callback => { return this.CollaboratorsInviteHandler.getInviteCount( this.projectId, @@ -129,9 +129,12 @@ describe('CollaboratorsInviteHandler', function() { }) }) - describe('when model.count produces an error', function() { + describe('when model.countDocuments produces an error', function() { beforeEach(function() { - return this.ProjectInvite.count.callsArgWith(1, new Error('woops')) + return this.ProjectInvite.countDocuments.callsArgWith( + 1, + new Error('woops') + ) }) it('should produce an error', function(done) {