Merge pull request #2081 from overleaf/cmg-per-user-trash
Add per-user trashed state to project model GitOrigin-RevId: 16a753702d3503eee011dd2adca5dc8df3da87f4
This commit is contained in:
committed by
sharelatex
parent
c1f8ac8de1
commit
6f2b4d3da3
@@ -80,7 +80,9 @@ describe('ProjectController', function() {
|
||||
getProject: sinon.stub()
|
||||
}
|
||||
this.ProjectHelper = {
|
||||
isArchived: sinon.stub()
|
||||
isArchived: sinon.stub(),
|
||||
isTrashed: sinon.stub(),
|
||||
isArchivedOrTrashed: sinon.stub()
|
||||
}
|
||||
this.AuthenticationController = {
|
||||
getLoggedInUser: sinon.stub().callsArgWith(1, null, this.user),
|
||||
@@ -878,6 +880,7 @@ describe('ProjectController', function() {
|
||||
const projects = [
|
||||
{
|
||||
archived: true,
|
||||
trashed: true,
|
||||
id: 'a',
|
||||
name: 'A',
|
||||
accessLevel: 'a',
|
||||
@@ -892,6 +895,7 @@ describe('ProjectController', function() {
|
||||
},
|
||||
{
|
||||
archived: false,
|
||||
trashed: true,
|
||||
id: 'c',
|
||||
name: 'C',
|
||||
accessLevel: 'c',
|
||||
@@ -899,6 +903,7 @@ describe('ProjectController', function() {
|
||||
},
|
||||
{
|
||||
archived: false,
|
||||
trashed: false,
|
||||
id: 'd',
|
||||
name: 'D',
|
||||
accessLevel: 'd',
|
||||
@@ -906,16 +911,16 @@ describe('ProjectController', function() {
|
||||
}
|
||||
]
|
||||
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects[0], this.user._id)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects[1], this.user._id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects[2], this.user._id)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects[3], this.user._id)
|
||||
.returns(false)
|
||||
|
||||
@@ -934,7 +939,6 @@ describe('ProjectController', function() {
|
||||
expect(data).to.deep.equal({
|
||||
projects: [
|
||||
{ _id: 'b', name: 'B', accessLevel: 'b' },
|
||||
{ _id: 'c', name: 'C', accessLevel: 'c' },
|
||||
{ _id: 'd', name: 'D', accessLevel: 'd' }
|
||||
]
|
||||
})
|
||||
|
||||
@@ -68,6 +68,43 @@ describe('ProjectHelper', function() {
|
||||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('project.archived being undefined', function() {
|
||||
it('returns false if archived is undefined', function() {
|
||||
this.project.archived = undefined
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('isTrashed', function() {
|
||||
it('returns true if user id is found', function() {
|
||||
this.project.trashed = [
|
||||
ObjectId('588f3ddae8ebc1bac07c9fa4'),
|
||||
ObjectId('5c41deb2b4ca500153340809')
|
||||
]
|
||||
expect(
|
||||
this.ProjectHelper.isTrashed(this.project, this.user._id)
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('returns false if user id is not found', function() {
|
||||
this.project.trashed = []
|
||||
expect(
|
||||
this.ProjectHelper.isTrashed(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
|
||||
describe('project.trashed being undefined', function() {
|
||||
it('returns false if trashed is undefined', function() {
|
||||
this.project.trashed = undefined
|
||||
expect(
|
||||
this.ProjectHelper.isTrashed(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('compilerFromV1Engine', function() {
|
||||
|
||||
@@ -47,7 +47,9 @@ describe('ProjectLocator', function() {
|
||||
getProject: sinon.stub().callsArgWith(2, null, project)
|
||||
}
|
||||
this.ProjectHelper = {
|
||||
isArchived: sinon.stub()
|
||||
isArchived: sinon.stub(),
|
||||
isTrashed: sinon.stub(),
|
||||
isArchivedOrTrashed: sinon.stub()
|
||||
}
|
||||
this.locator = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
@@ -602,31 +604,31 @@ describe('ProjectLocator', function() {
|
||||
owned: [
|
||||
{ name: 'notThis' },
|
||||
{ name: 'wellll' },
|
||||
{ name: 'findThis', archived: true },
|
||||
{ name: 'findThis', archived: true, trashed: true },
|
||||
stubbedProject,
|
||||
{ name: 'findThis', archived: true },
|
||||
{ name: 'Noooo' }
|
||||
{ name: 'findThis', archived: true, trashed: false },
|
||||
{ name: 'Noooo', trashed: true }
|
||||
]
|
||||
}
|
||||
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[0], userId)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[1], userId)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[2], userId)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[3], userId)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[4], userId)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
this.ProjectHelper.isArchivedOrTrashed
|
||||
.withArgs(projects.owned[5], userId)
|
||||
.returns(false)
|
||||
.returns(true)
|
||||
|
||||
this.ProjectGetter.findAllUsersProjects = sinon
|
||||
.stub()
|
||||
|
||||
Reference in New Issue
Block a user