Merge pull request #2118 from overleaf/cmg-convert-array-archiving

New archiving endpoint to convert to array

GitOrigin-RevId: a6f5d3e2363afcbcd5719731261b85a0ae7a1e25
This commit is contained in:
Jessica Lawshe
2019-10-02 14:22:28 +00:00
committed by sharelatex
parent 86d844baf2
commit b5f4e26840
8 changed files with 329 additions and 12 deletions
@@ -38,7 +38,7 @@ describe('ProjectController', function() {
}
this.token = 'some-token'
this.ProjectDeleter = {
archiveProject: sinon.stub().callsArg(1),
legacyArchiveProject: sinon.stub().callsArg(1),
deleteProject: sinon.stub().callsArg(2),
restoreProject: sinon.stub().callsArg(1),
findArchivedProjects: sinon.stub()
@@ -284,7 +284,7 @@ describe('ProjectController', function() {
describe('deleteProject', function() {
it('should tell the project deleter to archive when forever=false', function(done) {
this.res.sendStatus = code => {
this.ProjectDeleter.archiveProject
this.ProjectDeleter.legacyArchiveProject
.calledWith(this.project_id)
.should.equal(true)
code.should.equal(200)
@@ -18,10 +18,22 @@ describe('ProjectDeleter', function() {
_id: this.project_id,
lastUpdated: new Date(),
rootFolder: [],
collaberator_refs: ['collab1', 'collab2'],
readOnly_refs: ['readOnly1', 'readOnly2'],
tokenAccessReadAndWrite_refs: ['tokenCollab1', 'tokenCollab2'],
tokenAccessReadOnly_refs: ['tokenReadOnly1', 'tokenReadOnly2'],
collaberator_refs: [
ObjectId('5b895d372f4189011c2f5afc'),
ObjectId('5b8d40073ead20011caca726')
],
readOnly_refs: [
ObjectId('5b8d4602b2f786011c4fb244'),
ObjectId('5b8d4a57c1cd2b011c39161c')
],
tokenAccessReadAndWrite_refs: [
ObjectId('5b8d5663a26df3035ea0d5a1'),
ObjectId('5b8e8676373c14011c2cad3c')
],
tokenAccessReadOnly_refs: [
ObjectId('5b9b801b5dd22c011ba5d9b3'),
ObjectId('5bc5adae1cad8d011fd4060a')
],
owner_ref: ObjectId('588aaaaaaaaaaaaaaaaaaaaa'),
tokens: {
readOnly: 'wombat',
@@ -111,6 +123,10 @@ describe('ProjectDeleter', function() {
}
}
this.ProjectHelper = {
calculateArchivedArray: sinon.stub()
}
this.db = {
projects: {
insert: sinon.stub().yields()
@@ -128,6 +144,7 @@ describe('ProjectDeleter', function() {
requires: {
'../Editor/EditorController': this.editorController,
'../../models/Project': { Project: Project },
'./ProjectHelper': this.ProjectHelper,
'../../models/DeletedProject': { DeletedProject: DeletedProject },
'../DocumentUpdater/DocumentUpdaterHandler': this
.documentUpdaterHandler,
@@ -409,7 +426,7 @@ describe('ProjectDeleter', function() {
})
})
describe('archiveProject', function() {
describe('legacyArchiveProject', function() {
beforeEach(function() {
this.ProjectMock.expects('update')
.withArgs(
@@ -424,13 +441,61 @@ describe('ProjectDeleter', function() {
})
it('should update the project', function(done) {
this.ProjectDeleter.archiveProject(this.project_id, () => {
this.ProjectDeleter.legacyArchiveProject(this.project_id, () => {
this.ProjectMock.verify()
done()
})
})
})
describe('archiveProject', function() {
beforeEach(function() {
let archived = [ObjectId(this.user._id)]
this.ProjectHelper.calculateArchivedArray.returns(archived)
this.ProjectMock.expects('findOne')
.withArgs({ _id: this.project_id })
.chain('exec')
.resolves(this.project)
this.ProjectMock.expects('update')
.withArgs({ _id: this.project_id }, { $set: { archived: archived } })
.resolves()
})
it('should update the project', async function() {
await this.ProjectDeleter.promises.archiveProject(
this.project_id,
this.user._id
)
this.ProjectMock.verify()
})
})
describe('unarchiveProject', function() {
beforeEach(function() {
let archived = [ObjectId(this.user._id)]
this.ProjectHelper.calculateArchivedArray.returns(archived)
this.ProjectMock.expects('findOne')
.withArgs({ _id: this.project_id })
.chain('exec')
.resolves(this.project)
this.ProjectMock.expects('update')
.withArgs({ _id: this.project_id }, { $set: { archived: archived } })
.resolves()
})
it('should update the project', async function() {
await this.ProjectDeleter.promises.unarchiveProject(
this.project_id,
this.user._id
)
this.ProjectMock.verify()
})
})
describe('restoreProject', function() {
beforeEach(function() {
this.ProjectMock.expects('update')
@@ -107,6 +107,130 @@ describe('ProjectHelper', function() {
})
})
describe('calculateArchivedArray', function() {
describe('project.archived being an array', function() {
it('returns an array adding the current user id when archiving', function() {
const project = { archived: [] }
const result = this.ProjectHelper.calculateArchivedArray(
project,
ObjectId('5c922599cdb09e014aa7d499'),
'ARCHIVE'
)
expect(result).to.deep.equal([ObjectId('5c922599cdb09e014aa7d499')])
})
it('returns an array without the current user id when unarchiving', function() {
const project = { archived: [ObjectId('5c922599cdb09e014aa7d499')] }
const result = this.ProjectHelper.calculateArchivedArray(
project,
ObjectId('5c922599cdb09e014aa7d499'),
'UNARCHIVE'
)
expect(result).to.deep.equal([])
})
})
describe('project.archived being a boolean and being true', function() {
it('returns an array of all associated user ids when archiving', function() {
const project = {
archived: true,
owner_ref: this.user._id,
collaberator_refs: [
ObjectId('4f2cfb341eb5855a5b000f8b'),
ObjectId('5c45f3bd425ead01488675aa')
],
readOnly_refs: [ObjectId('5c92243fcdb09e014aa7d487')],
tokenAccessReadAndWrite_refs: [ObjectId('5c922599cdb09e014aa7d499')],
tokenAccessReadOnly_refs: []
}
const result = this.ProjectHelper.calculateArchivedArray(
project,
this.user._id,
'ARCHIVE'
)
expect(result).to.deep.equal([
this.user._id,
ObjectId('4f2cfb341eb5855a5b000f8b'),
ObjectId('5c45f3bd425ead01488675aa'),
ObjectId('5c92243fcdb09e014aa7d487'),
ObjectId('5c922599cdb09e014aa7d499')
])
})
it('returns an array of all associated users without the current user id when unarchived', function() {
const project = {
archived: true,
owner_ref: this.user._id,
collaberator_refs: [
ObjectId('4f2cfb341eb5855a5b000f8b'),
ObjectId('5c45f3bd425ead01488675aa'),
ObjectId('5c922599cdb09e014aa7d499')
],
readOnly_refs: [ObjectId('5c92243fcdb09e014aa7d487')],
tokenAccessReadAndWrite_refs: [ObjectId('5c922599cdb09e014aa7d499')],
tokenAccessReadOnly_refs: []
}
const result = this.ProjectHelper.calculateArchivedArray(
project,
this.user._id,
'UNARCHIVE'
)
expect(result).to.deep.equal([
ObjectId('4f2cfb341eb5855a5b000f8b'),
ObjectId('5c45f3bd425ead01488675aa'),
ObjectId('5c922599cdb09e014aa7d499'),
ObjectId('5c92243fcdb09e014aa7d487')
])
})
})
describe('project.archived being a boolean and being false', function() {
it('returns an array adding the current user id when archiving', function() {
const project = { archived: false }
const result = this.ProjectHelper.calculateArchivedArray(
project,
ObjectId('5c922599cdb09e014aa7d499'),
'ARCHIVE'
)
expect(result).to.deep.equal([ObjectId('5c922599cdb09e014aa7d499')])
})
it('returns an empty array when unarchiving', function() {
const project = { archived: false }
const result = this.ProjectHelper.calculateArchivedArray(
project,
ObjectId('5c922599cdb09e014aa7d499'),
'UNARCHIVE'
)
expect(result).to.deep.equal([])
})
})
describe('project.archived not being set', function() {
it('returns an array adding the current user id when archiving', function() {
const project = { archived: undefined }
const result = this.ProjectHelper.calculateArchivedArray(
project,
ObjectId('5c922599cdb09e014aa7d499'),
'ARCHIVE'
)
expect(result).to.deep.equal([ObjectId('5c922599cdb09e014aa7d499')])
})
it('returns an empty array when unarchiving', function() {
const project = { archived: undefined }
const result = this.ProjectHelper.calculateArchivedArray(
project,
ObjectId('5c922599cdb09e014aa7d499'),
'UNARCHIVE'
)
expect(result).to.deep.equal([])
})
})
})
describe('compilerFromV1Engine', function() {
it('returns the correct engine for latex_dvipdf', function() {
return expect(