Просмотр исходного кода

Merge pull request #4254 from overleaf/em-active-projects-expire

Unit test for not expiring active projects

GitOrigin-RevId: 8b2f3d05c7f7e4c4d44e5487041f19d2bff9891a
Eric Mc Sween 5 лет назад
Родитель
Сommit
9820b787a7
1 измененных файлов с 93 добавлено и 51 удалено
  1. 93 51
      services/web/test/unit/src/Project/ProjectDeleterTests.js

+ 93 - 51
services/web/test/unit/src/Project/ProjectDeleterTests.js

@@ -419,70 +419,112 @@ describe('ProjectDeleter', function () {
   })
 
   describe('expireDeletedProject', function () {
-    beforeEach(async function () {
-      for (const deletedProject of this.deletedProjects) {
+    describe('on an inactive project', function () {
+      beforeEach(async function () {
         this.ProjectMock.expects('findById')
-          .withArgs(deletedProject.deleterData.deletedProjectId)
+          .withArgs(this.deletedProjects[0].deleterData.deletedProjectId)
           .chain('exec')
           .resolves(null)
-      }
-      this.DeletedProjectMock.expects('updateOne')
-        .withArgs(
-          {
-            _id: this.deletedProjects[0]._id,
-          },
-          {
-            $set: {
-              'deleterData.deleterIpAddress': null,
-              project: null,
+        this.DeletedProjectMock.expects('updateOne')
+          .withArgs(
+            {
+              _id: this.deletedProjects[0]._id,
             },
-          }
+            {
+              $set: {
+                'deleterData.deleterIpAddress': null,
+                project: null,
+              },
+            }
+          )
+          .chain('exec')
+          .resolves()
+
+        this.DeletedProjectMock.expects('findOne')
+          .withArgs({
+            'deleterData.deletedProjectId': this.deletedProjects[0].project._id,
+          })
+          .chain('exec')
+          .resolves(this.deletedProjects[0])
+
+        await this.ProjectDeleter.promises.expireDeletedProject(
+          this.deletedProjects[0].project._id
         )
-        .chain('exec')
-        .resolves()
+      })
 
-      this.DeletedProjectMock.expects('findOne')
-        .withArgs({
-          'deleterData.deletedProjectId': this.deletedProjects[0].project._id,
-        })
-        .chain('exec')
-        .resolves(this.deletedProjects[0])
+      it('should find the specified deletedProject and remove its project and ip address', function () {
+        this.DeletedProjectMock.verify()
+      })
 
-      await this.ProjectDeleter.promises.expireDeletedProject(
-        this.deletedProjects[0].project._id
-      )
-    })
+      it('should destroy the docs in docstore', function () {
+        expect(
+          this.DocstoreManager.promises.destroyProject
+        ).to.have.been.calledWith(this.deletedProjects[0].project._id)
+      })
 
-    it('should find the specified deletedProject and remove its project and ip address', function () {
-      this.DeletedProjectMock.verify()
-    })
+      it('should delete the project in history', function () {
+        expect(
+          this.HistoryManager.promises.deleteProject
+        ).to.have.been.calledWith(
+          this.deletedProjects[0].project._id,
+          this.deletedProjects[0].project.overleaf.history.id
+        )
+      })
 
-    it('should destroy the docs in docstore', function () {
-      expect(
-        this.DocstoreManager.promises.destroyProject
-      ).to.have.been.calledWith(this.deletedProjects[0].project._id)
-    })
+      it('should destroy the files in filestore', function () {
+        expect(
+          this.FileStoreHandler.promises.deleteProject
+        ).to.have.been.calledWith(this.deletedProjects[0].project._id)
+      })
 
-    it('should delete the project in history', function () {
-      expect(
-        this.HistoryManager.promises.deleteProject
-      ).to.have.been.calledWith(
-        this.deletedProjects[0].project._id,
-        this.deletedProjects[0].project.overleaf.history.id
-      )
+      it('should destroy the files in project-archiver', function () {
+        expect(
+          this.TpdsUpdateSender.promises.deleteProject
+        ).to.have.been.calledWith({
+          project_id: this.deletedProjects[0].project._id,
+        })
+      })
     })
 
-    it('should destroy the files in filestore', function () {
-      expect(
-        this.FileStoreHandler.promises.deleteProject
-      ).to.have.been.calledWith(this.deletedProjects[0].project._id)
-    })
+    describe('on an active project (from an incomplete delete)', function () {
+      beforeEach(async function () {
+        this.ProjectMock.expects('findById')
+          .withArgs(this.deletedProjects[0].deleterData.deletedProjectId)
+          .chain('exec')
+          .resolves(this.deletedProjects[0].project)
+        this.DeletedProjectMock.expects('deleteOne')
+          .withArgs({
+            'deleterData.deletedProjectId': this.deletedProjects[0].project._id,
+          })
+          .chain('exec')
+          .resolves()
+        await this.ProjectDeleter.promises.expireDeletedProject(
+          this.deletedProjects[0].project._id
+        )
+      })
 
-    it('should destroy the files in project-archiver', function () {
-      expect(
-        this.TpdsUpdateSender.promises.deleteProject
-      ).to.have.been.calledWith({
-        project_id: this.deletedProjects[0].project._id,
+      it('should delete the spurious deleted project record', function () {
+        this.DeletedProjectMock.verify()
+      })
+
+      it('should not destroy the docs in docstore', function () {
+        expect(this.DocstoreManager.promises.destroyProject).to.not.have.been
+          .called
+      })
+
+      it('should not delete the project in history', function () {
+        expect(this.HistoryManager.promises.deleteProject).to.not.have.been
+          .called
+      })
+
+      it('should not destroy the files in filestore', function () {
+        expect(this.FileStoreHandler.promises.deleteProject).to.not.have.been
+          .called
+      })
+
+      it('should not destroy the files in project-archiver', function () {
+        expect(this.TpdsUpdateSender.promises.deleteProject).to.not.have.been
+          .called
       })
     })
   })