Merge pull request #1948 from overleaf/cmg-allow-array-archiving
Make checking for project.archived array-friendly GitOrigin-RevId: 2902a12fb4611a5786d4b10feba534b1cd29668b
This commit is contained in:
committed by
sharelatex
parent
c8140f9641
commit
3422c17dc4
@@ -79,6 +79,9 @@ describe('ProjectController', function() {
|
||||
findAllUsersProjects: sinon.stub(),
|
||||
getProject: sinon.stub()
|
||||
}
|
||||
this.ProjectHelper = {
|
||||
isArchived: sinon.stub()
|
||||
}
|
||||
this.AuthenticationController = {
|
||||
getLoggedInUser: sinon.stub().callsArgWith(1, null, this.user),
|
||||
getLoggedInUserId: sinon.stub().returns(this.user._id),
|
||||
@@ -136,6 +139,7 @@ describe('ProjectController', function() {
|
||||
'./ProjectDuplicator': this.ProjectDuplicator,
|
||||
'./ProjectCreationHandler': this.ProjectCreationHandler,
|
||||
'../Editor/EditorController': this.EditorController,
|
||||
'./ProjectHelper': this.ProjectHelper,
|
||||
'../Subscription/SubscriptionLocator': this.SubscriptionLocator,
|
||||
'../Subscription/LimitationsManager': this.LimitationsManager,
|
||||
'../Tags/TagsHandler': this.TagsHandler,
|
||||
@@ -897,13 +901,27 @@ describe('ProjectController', function() {
|
||||
somethingElse: 1
|
||||
}
|
||||
]
|
||||
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects[0], this.user._id)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects[1], this.user._id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects[2], this.user._id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects[3], this.user._id)
|
||||
.returns(false)
|
||||
|
||||
this.ProjectGetter.findAllUsersProjects = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, [])
|
||||
this.ProjectController._buildProjectList = sinon.stub().returns(projects)
|
||||
this.AuthenticationController.getLoggedInUserId = sinon
|
||||
.stub()
|
||||
.returns('abc')
|
||||
.returns(this.user._id)
|
||||
return done()
|
||||
})
|
||||
|
||||
|
||||
@@ -16,12 +16,60 @@ const should = chai.should()
|
||||
const { expect } = chai
|
||||
const modulePath = '../../../../app/src/Features/Project/ProjectHelper.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { ObjectId } = require('mongojs')
|
||||
|
||||
describe('ProjectHelper', function() {
|
||||
beforeEach(function() {
|
||||
this.project = {
|
||||
_id: '123213jlkj9kdlsaj'
|
||||
}
|
||||
|
||||
this.user = {
|
||||
_id: '588f3ddae8ebc1bac07c9fa4',
|
||||
first_name: 'bjkdsjfk',
|
||||
features: {}
|
||||
}
|
||||
|
||||
return (this.ProjectHelper = SandboxedModule.require(modulePath))
|
||||
})
|
||||
|
||||
describe('isArchived', function() {
|
||||
describe('project.archived being an array', function() {
|
||||
it('returns true if user id is found', function() {
|
||||
this.project.archived = [
|
||||
ObjectId('588f3ddae8ebc1bac07c9fa4'),
|
||||
ObjectId('5c41deb2b4ca500153340809')
|
||||
]
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('returns false if user id is not found', function() {
|
||||
this.project.archived = []
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('project.archived being a boolean', function() {
|
||||
it('returns true if archived is true', function() {
|
||||
this.project.archived = true
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('returns false if archived is false', function() {
|
||||
this.project.archived = false
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('compilerFromV1Engine', function() {
|
||||
it('returns the correct engine for latex_dvipdf', function() {
|
||||
return expect(
|
||||
|
||||
@@ -65,6 +65,9 @@ describe('ProjectLocator', function() {
|
||||
this.ProjectGetter = {
|
||||
getProject: sinon.stub().callsArgWith(2, null, project)
|
||||
}
|
||||
this.ProjectHelper = {
|
||||
isArchived: sinon.stub()
|
||||
}
|
||||
return (this.locator = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
console: console
|
||||
@@ -73,6 +76,7 @@ describe('ProjectLocator', function() {
|
||||
'../../models/Project': { Project },
|
||||
'../../models/User': { User: this.User },
|
||||
'./ProjectGetter': this.ProjectGetter,
|
||||
'./ProjectHelper': this.ProjectHelper,
|
||||
'logger-sharelatex': {
|
||||
log() {},
|
||||
err() {},
|
||||
@@ -562,6 +566,26 @@ describe('ProjectLocator', function() {
|
||||
{ name: 'Noooo' }
|
||||
]
|
||||
}
|
||||
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[0], user_id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[1], user_id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[2], user_id)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[3], user_id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[4], user_id)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[5], user_id)
|
||||
.returns(false)
|
||||
|
||||
this.ProjectGetter.findAllUsersProjects = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, projects)
|
||||
|
||||
Reference in New Issue
Block a user