|
@@ -1,39 +1,29 @@
|
|
|
-/* eslint-disable
|
|
|
|
|
- n/handle-callback-err,
|
|
|
|
|
- max-len,
|
|
|
|
|
- no-return-assign,
|
|
|
|
|
- no-unused-vars,
|
|
|
|
|
-*/
|
|
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
|
|
-/*
|
|
|
|
|
- * decaffeinate suggestions:
|
|
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
|
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
|
- */
|
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
-const assert = require('assert')
|
|
|
|
|
const path = require('path')
|
|
const path = require('path')
|
|
|
const sinon = require('sinon')
|
|
const sinon = require('sinon')
|
|
|
const modulePath = path.join(
|
|
const modulePath = path.join(
|
|
|
__dirname,
|
|
__dirname,
|
|
|
'../../../../app/src/Features/InactiveData/InactiveProjectManager'
|
|
'../../../../app/src/Features/InactiveData/InactiveProjectManager'
|
|
|
)
|
|
)
|
|
|
-const { expect } = require('chai')
|
|
|
|
|
const { ObjectId, ReadPreference } = require('mongodb')
|
|
const { ObjectId, ReadPreference } = require('mongodb')
|
|
|
|
|
+const { expect } = require('chai')
|
|
|
|
|
|
|
|
describe('InactiveProjectManager', function () {
|
|
describe('InactiveProjectManager', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
this.settings = {}
|
|
this.settings = {}
|
|
|
this.DocstoreManager = {
|
|
this.DocstoreManager = {
|
|
|
- unarchiveProject: sinon.stub(),
|
|
|
|
|
- archiveProject: sinon.stub(),
|
|
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ unarchiveProject: sinon.stub(),
|
|
|
|
|
+ archiveProject: sinon.stub(),
|
|
|
|
|
+ },
|
|
|
}
|
|
}
|
|
|
this.ProjectUpdateHandler = {
|
|
this.ProjectUpdateHandler = {
|
|
|
- markAsActive: sinon.stub(),
|
|
|
|
|
- markAsInactive: sinon.stub(),
|
|
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ markAsActive: sinon.stub(),
|
|
|
|
|
+ markAsInactive: sinon.stub(),
|
|
|
|
|
+ },
|
|
|
}
|
|
}
|
|
|
- this.ProjectGetter = { getProject: sinon.stub() }
|
|
|
|
|
|
|
+ this.ProjectGetter = { promises: { getProject: sinon.stub() } }
|
|
|
this.InactiveProjectManager = SandboxedModule.require(modulePath, {
|
|
this.InactiveProjectManager = SandboxedModule.require(modulePath, {
|
|
|
requires: {
|
|
requires: {
|
|
|
mongodb: { ObjectId },
|
|
mongodb: { ObjectId },
|
|
@@ -48,106 +38,90 @@ describe('InactiveProjectManager', function () {
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
- return (this.project_id = '1234')
|
|
|
|
|
|
|
+ this.project_id = '1234'
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('reactivateProjectIfRequired', function () {
|
|
describe('reactivateProjectIfRequired', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
this.project = { active: false }
|
|
this.project = { active: false }
|
|
|
- this.ProjectGetter.getProject.callsArgWith(2, null, this.project)
|
|
|
|
|
- return this.ProjectUpdateHandler.markAsActive.callsArgWith(1)
|
|
|
|
|
|
|
+ this.ProjectGetter.promises.getProject.resolves(this.project)
|
|
|
|
|
+ this.ProjectUpdateHandler.promises.markAsActive.resolves()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should call unarchiveProject', function (done) {
|
|
|
|
|
- this.DocstoreManager.unarchiveProject.callsArgWith(1)
|
|
|
|
|
- return this.InactiveProjectManager.reactivateProjectIfRequired(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- err => {
|
|
|
|
|
- this.DocstoreManager.unarchiveProject
|
|
|
|
|
- .calledWith(this.project_id)
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- this.ProjectUpdateHandler.markAsActive
|
|
|
|
|
- .calledWith(this.project_id)
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ it('should call unarchiveProject', async function () {
|
|
|
|
|
+ this.DocstoreManager.promises.unarchiveProject.resolves()
|
|
|
|
|
+ await this.InactiveProjectManager.promises.reactivateProjectIfRequired(
|
|
|
|
|
+ this.project_id
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
|
|
+ this.DocstoreManager.promises.unarchiveProject
|
|
|
|
|
+ .calledWith(this.project_id)
|
|
|
|
|
+ .should.equal(true)
|
|
|
|
|
+ this.ProjectUpdateHandler.promises.markAsActive
|
|
|
|
|
+ .calledWith(this.project_id)
|
|
|
|
|
+ .should.equal(true)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should not mark project as active if error with unarchiving', function (done) {
|
|
|
|
|
- const error = new Error('error')
|
|
|
|
|
- this.DocstoreManager.unarchiveProject.callsArgWith(1, error)
|
|
|
|
|
- return this.InactiveProjectManager.reactivateProjectIfRequired(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- err => {
|
|
|
|
|
- err.should.equal(error)
|
|
|
|
|
- this.DocstoreManager.unarchiveProject
|
|
|
|
|
- .calledWith(this.project_id)
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- this.ProjectUpdateHandler.markAsActive
|
|
|
|
|
- .calledWith(this.project_id)
|
|
|
|
|
- .should.equal(false)
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ it('should not mark project as active if error with unarchiving', async function () {
|
|
|
|
|
+ this.DocstoreManager.promises.unarchiveProject.rejects()
|
|
|
|
|
+ await expect(
|
|
|
|
|
+ this.InactiveProjectManager.promises.reactivateProjectIfRequired(
|
|
|
|
|
+ this.project_id
|
|
|
|
|
+ )
|
|
|
|
|
+ ).to.be.rejected
|
|
|
|
|
+
|
|
|
|
|
+ this.DocstoreManager.promises.unarchiveProject
|
|
|
|
|
+ .calledWith(this.project_id)
|
|
|
|
|
+ .should.equal(true)
|
|
|
|
|
+ this.ProjectUpdateHandler.promises.markAsActive
|
|
|
|
|
+ .calledWith(this.project_id)
|
|
|
|
|
+ .should.equal(false)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should not call unarchiveProject if it is active', function (done) {
|
|
|
|
|
|
|
+ it('should not call unarchiveProject if it is active', async function () {
|
|
|
this.project.active = true
|
|
this.project.active = true
|
|
|
- this.DocstoreManager.unarchiveProject.callsArgWith(1)
|
|
|
|
|
- return this.InactiveProjectManager.reactivateProjectIfRequired(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- err => {
|
|
|
|
|
- this.DocstoreManager.unarchiveProject
|
|
|
|
|
- .calledWith(this.project_id)
|
|
|
|
|
- .should.equal(false)
|
|
|
|
|
- this.ProjectUpdateHandler.markAsActive
|
|
|
|
|
- .calledWith(this.project_id)
|
|
|
|
|
- .should.equal(false)
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.DocstoreManager.promises.unarchiveProject.resolves()
|
|
|
|
|
+ await this.InactiveProjectManager.promises.reactivateProjectIfRequired(
|
|
|
|
|
+ this.project_id
|
|
|
)
|
|
)
|
|
|
|
|
+ this.DocstoreManager.promises.unarchiveProject
|
|
|
|
|
+ .calledWith(this.project_id)
|
|
|
|
|
+ .should.equal(false)
|
|
|
|
|
+ this.ProjectUpdateHandler.promises.markAsActive
|
|
|
|
|
+ .calledWith(this.project_id)
|
|
|
|
|
+ .should.equal(false)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('deactivateProject', function () {
|
|
describe('deactivateProject', function () {
|
|
|
- it('should call unarchiveProject and markAsInactive', function (done) {
|
|
|
|
|
- this.DocstoreManager.archiveProject.callsArgWith(1)
|
|
|
|
|
-
|
|
|
|
|
- this.ProjectUpdateHandler.markAsInactive.callsArgWith(1)
|
|
|
|
|
|
|
+ it('should call unarchiveProject and markAsInactive', async function () {
|
|
|
|
|
+ this.DocstoreManager.promises.archiveProject.resolves()
|
|
|
|
|
+ this.ProjectUpdateHandler.promises.markAsInactive.resolves()
|
|
|
|
|
|
|
|
- return this.InactiveProjectManager.deactivateProject(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- err => {
|
|
|
|
|
- this.DocstoreManager.archiveProject
|
|
|
|
|
- .calledWith(this.project_id)
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- this.ProjectUpdateHandler.markAsInactive
|
|
|
|
|
- .calledWith(this.project_id)
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await this.InactiveProjectManager.promises.deactivateProject(
|
|
|
|
|
+ this.project_id
|
|
|
)
|
|
)
|
|
|
|
|
+ this.DocstoreManager.promises.archiveProject
|
|
|
|
|
+ .calledWith(this.project_id)
|
|
|
|
|
+ .should.equal(true)
|
|
|
|
|
+ this.ProjectUpdateHandler.promises.markAsInactive
|
|
|
|
|
+ .calledWith(this.project_id)
|
|
|
|
|
+ .should.equal(true)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should not call markAsInactive if there was a problem archiving in docstore', function (done) {
|
|
|
|
|
- this.DocstoreManager.archiveProject.callsArgWith(1, 'errorrr')
|
|
|
|
|
|
|
+ it('should not call markAsInactive if there was a problem archiving in docstore', async function () {
|
|
|
|
|
+ this.DocstoreManager.promises.archiveProject.rejects()
|
|
|
|
|
+ this.ProjectUpdateHandler.promises.markAsInactive.resolves()
|
|
|
|
|
|
|
|
- this.ProjectUpdateHandler.markAsInactive.callsArgWith(1)
|
|
|
|
|
-
|
|
|
|
|
- return this.InactiveProjectManager.deactivateProject(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- err => {
|
|
|
|
|
- err.should.equal('errorrr')
|
|
|
|
|
- this.DocstoreManager.archiveProject
|
|
|
|
|
- .calledWith(this.project_id)
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- this.ProjectUpdateHandler.markAsInactive
|
|
|
|
|
- .calledWith(this.project_id)
|
|
|
|
|
- .should.equal(false)
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ await expect(
|
|
|
|
|
+ this.InactiveProjectManager.promises.deactivateProject(this.project_id)
|
|
|
|
|
+ ).to.be.rejected
|
|
|
|
|
+ this.DocstoreManager.promises.archiveProject
|
|
|
|
|
+ .calledWith(this.project_id)
|
|
|
|
|
+ .should.equal(true)
|
|
|
|
|
+ this.ProjectUpdateHandler.promises.markAsInactive
|
|
|
|
|
+ .calledWith(this.project_id)
|
|
|
|
|
+ .should.equal(false)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|