Copy tags when cloning a project (#14987)

GitOrigin-RevId: 4cdca0ef2f26bf6bba02b675b0ef02ba8da881e2
This commit is contained in:
Alf Eaton
2023-09-29 08:04:14 +00:00
committed by Copybot
parent 04900349e6
commit 15475cdb3c
21 changed files with 315 additions and 21 deletions
@@ -87,6 +87,7 @@ describe('<EditorCloneProjectModalWrapper />', function () {
expect(JSON.parse(options.body)).to.deep.equal({
projectName: 'A Cloned Project',
tags: [],
})
expect(openProject).to.be.calledOnce
@@ -0,0 +1,18 @@
import { Tag } from '../../../../../app/src/Features/Tags/types'
export const tags: Tag[] = [
{
_id: 'tag-1',
name: 'foo',
color: '#f00',
user_id: '624333f147cfd8002622a1d3',
project_ids: ['62f17f594641b405ca2b3264'],
},
{
_id: 'tag-2',
name: 'bar',
color: '#0f0',
user_id: '624333f147cfd8002622a1d3',
project_ids: ['62f17f594641b405ca2b3264'],
},
]
@@ -43,7 +43,7 @@ describe('ProjectController', function () {
findArchivedProjects: sinon.stub(),
}
this.ProjectDuplicator = {
duplicate: sinon.stub().callsArgWith(3, null, { _id: this.project_id }),
duplicate: sinon.stub().callsArgWith(4, null, { _id: this.project_id }),
}
this.ProjectCreationHandler = {
createExampleProject: sinon
@@ -60,7 +60,15 @@ describe('ProjectController', function () {
.stub()
.callsArgWith(1, null, false),
}
this.TagsHandler = { getAllTags: sinon.stub() }
this.TagsHandler = {
getTagsForProject: sinon.stub().callsArgWith(2, null, [
{
name: 'test',
project_ids: [this.project_id],
},
]),
addProjectToTags: sinon.stub(),
}
this.UserModel = { findById: sinon.stub(), updateOne: sinon.stub() }
this.AuthorizationManager = {
getPrivilegeLevelForProject: sinon.stub(),
@@ -143,6 +143,14 @@ describe('ProjectDuplicator', function () {
copyFile: sinon.stub().resolves(this.filestoreUrl),
},
}
this.TagsHandler = {
promises: {
addProjectToTags: sinon.stub().resolves({
_id: 'project-1',
}),
countTagsForProject: sinon.stub().resolves(1),
},
}
this.ProjectCreationHandler = {
promises: {
createBlankProject: sinon.stub().resolves(this.newBlankProject),
@@ -216,6 +224,7 @@ describe('ProjectDuplicator', function () {
'./ProjectLocator': this.ProjectLocator,
'./ProjectOptionsHandler': this.ProjectOptionsHandler,
'../ThirdPartyDataStore/TpdsProjectFlusher': this.TpdsProjectFlusher,
'../Tags/TagsHandler': this.TagsHandler,
},
})
})
@@ -291,6 +291,35 @@ describe('TagsHandler', function () {
})
})
describe('addProjectToTags', function () {
it('should add the project id to each tag', function (done) {
const tagIds = []
this.TagMock.expects('updateMany')
.once()
.withArgs(
{
user_id: this.userId,
_id: { $in: tagIds },
},
{
$addToSet: { project_ids: this.projectId },
}
)
.resolves()
this.TagsHandler.addProjectToTags(
this.userId,
tagIds,
this.projectId,
(err, result) => {
expect(err).to.not.exist
this.TagMock.verify()
done()
}
)
})
})
describe('deleteTag', function () {
describe('with a valid tag_id', function () {
it('should call remove in mongo', function (done) {