|
@@ -16,6 +16,7 @@ describe('TagsHandler', function () {
|
|
|
this.tag = { user_id: this.userId, name: 'some name', color: '#3399CC' }
|
|
this.tag = { user_id: this.userId, name: 'some name', color: '#3399CC' }
|
|
|
this.tagId = ObjectId().toString()
|
|
this.tagId = ObjectId().toString()
|
|
|
this.projectId = ObjectId().toString()
|
|
this.projectId = ObjectId().toString()
|
|
|
|
|
+ this.projectIds = [ObjectId().toString(), ObjectId().toString()]
|
|
|
|
|
|
|
|
this.mongodb = { ObjectId }
|
|
this.mongodb = { ObjectId }
|
|
|
this.TagMock = sinon.mock(Tag)
|
|
this.TagMock = sinon.mock(Tag)
|
|
@@ -34,7 +35,7 @@ describe('TagsHandler', function () {
|
|
|
this.TagMock.expects('find')
|
|
this.TagMock.expects('find')
|
|
|
.once()
|
|
.once()
|
|
|
.withArgs({ user_id: this.userId })
|
|
.withArgs({ user_id: this.userId })
|
|
|
- .yields(null, stubbedTags)
|
|
|
|
|
|
|
+ .resolves(stubbedTags)
|
|
|
this.TagsHandler.getAllTags(this.userId, (err, result) => {
|
|
this.TagsHandler.getAllTags(this.userId, (err, result) => {
|
|
|
expect(err).to.not.exist
|
|
expect(err).to.not.exist
|
|
|
this.TagMock.verify()
|
|
this.TagMock.verify()
|
|
@@ -50,7 +51,7 @@ describe('TagsHandler', function () {
|
|
|
this.TagMock.expects('create')
|
|
this.TagMock.expects('create')
|
|
|
.withArgs(this.tag)
|
|
.withArgs(this.tag)
|
|
|
.once()
|
|
.once()
|
|
|
- .yields(null, this.tag)
|
|
|
|
|
|
|
+ .resolves(this.tag)
|
|
|
this.TagsHandler.createTag(
|
|
this.TagsHandler.createTag(
|
|
|
this.tag.user_id,
|
|
this.tag.user_id,
|
|
|
this.tag.name,
|
|
this.tag.name,
|
|
@@ -74,7 +75,7 @@ describe('TagsHandler', function () {
|
|
|
this.TagMock.expects('create')
|
|
this.TagMock.expects('create')
|
|
|
.withArgs(this.tag)
|
|
.withArgs(this.tag)
|
|
|
.once()
|
|
.once()
|
|
|
- .yields(null, this.tag)
|
|
|
|
|
|
|
+ .resolves(this.tag)
|
|
|
this.TagsHandler.createTag(
|
|
this.TagsHandler.createTag(
|
|
|
this.tag.user_id,
|
|
this.tag.user_id,
|
|
|
// Pass this too-long name
|
|
// Pass this too-long name
|
|
@@ -114,11 +115,11 @@ describe('TagsHandler', function () {
|
|
|
this.TagMock.expects('create')
|
|
this.TagMock.expects('create')
|
|
|
.withArgs(this.tag)
|
|
.withArgs(this.tag)
|
|
|
.once()
|
|
.once()
|
|
|
- .yields(this.duplicateKeyError)
|
|
|
|
|
|
|
+ .throws(this.duplicateKeyError)
|
|
|
this.TagMock.expects('findOne')
|
|
this.TagMock.expects('findOne')
|
|
|
.withArgs({ user_id: this.tag.user_id, name: this.tag.name })
|
|
.withArgs({ user_id: this.tag.user_id, name: this.tag.name })
|
|
|
.once()
|
|
.once()
|
|
|
- .yields(null, this.tag)
|
|
|
|
|
|
|
+ .resolves(this.tag)
|
|
|
this.TagsHandler.createTag(
|
|
this.TagsHandler.createTag(
|
|
|
this.tag.user_id,
|
|
this.tag.user_id,
|
|
|
this.tag.name,
|
|
this.tag.name,
|
|
@@ -138,8 +139,6 @@ describe('TagsHandler', function () {
|
|
|
|
|
|
|
|
describe('addProjectToTag', function () {
|
|
describe('addProjectToTag', function () {
|
|
|
describe('with a valid tag_id', function () {
|
|
describe('with a valid tag_id', function () {
|
|
|
- beforeEach(function () {})
|
|
|
|
|
-
|
|
|
|
|
it('should call update in mongo', function (done) {
|
|
it('should call update in mongo', function (done) {
|
|
|
this.TagMock.expects('findOneAndUpdate')
|
|
this.TagMock.expects('findOneAndUpdate')
|
|
|
.once()
|
|
.once()
|
|
@@ -147,7 +146,7 @@ describe('TagsHandler', function () {
|
|
|
{ _id: this.tagId, user_id: this.userId },
|
|
{ _id: this.tagId, user_id: this.userId },
|
|
|
{ $addToSet: { project_ids: this.projectId } }
|
|
{ $addToSet: { project_ids: this.projectId } }
|
|
|
)
|
|
)
|
|
|
- .yields()
|
|
|
|
|
|
|
+ .resolves()
|
|
|
this.TagsHandler.addProjectToTag(
|
|
this.TagsHandler.addProjectToTag(
|
|
|
this.userId,
|
|
this.userId,
|
|
|
this.tagId,
|
|
this.tagId,
|
|
@@ -162,6 +161,30 @@ describe('TagsHandler', function () {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ describe('addProjectsToTag', function () {
|
|
|
|
|
+ describe('with a valid tag_id', function () {
|
|
|
|
|
+ it('should call update in mongo', function (done) {
|
|
|
|
|
+ this.TagMock.expects('findOneAndUpdate')
|
|
|
|
|
+ .once()
|
|
|
|
|
+ .withArgs(
|
|
|
|
|
+ { _id: this.tagId, user_id: this.userId },
|
|
|
|
|
+ { $addToSet: { project_ids: { $each: this.projectIds } } }
|
|
|
|
|
+ )
|
|
|
|
|
+ .resolves()
|
|
|
|
|
+ this.TagsHandler.addProjectsToTag(
|
|
|
|
|
+ this.userId,
|
|
|
|
|
+ this.tagId,
|
|
|
|
|
+ this.projectIds,
|
|
|
|
|
+ err => {
|
|
|
|
|
+ expect(err).to.not.exist
|
|
|
|
|
+ this.TagMock.verify()
|
|
|
|
|
+ done()
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
describe('addProjectToTagName', function () {
|
|
describe('addProjectToTagName', function () {
|
|
|
it('should call update in mongo', function (done) {
|
|
it('should call update in mongo', function (done) {
|
|
|
this.TagMock.expects('updateOne')
|
|
this.TagMock.expects('updateOne')
|
|
@@ -171,7 +194,7 @@ describe('TagsHandler', function () {
|
|
|
{ $addToSet: { project_ids: this.projectId } },
|
|
{ $addToSet: { project_ids: this.projectId } },
|
|
|
{ upsert: true }
|
|
{ upsert: true }
|
|
|
)
|
|
)
|
|
|
- .yields()
|
|
|
|
|
|
|
+ .resolves()
|
|
|
this.TagsHandler.addProjectToTagName(
|
|
this.TagsHandler.addProjectToTagName(
|
|
|
this.tag.userId,
|
|
this.tag.userId,
|
|
|
this.tag.name,
|
|
this.tag.name,
|
|
@@ -185,25 +208,36 @@ describe('TagsHandler', function () {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('updateTagUserIds', function () {
|
|
|
|
|
- it('should call update in mongo', function (done) {
|
|
|
|
|
- this.newUserId = ObjectId().toString()
|
|
|
|
|
- this.TagMock.expects('updateMany')
|
|
|
|
|
- .once()
|
|
|
|
|
- .withArgs(
|
|
|
|
|
- { user_id: this.userId },
|
|
|
|
|
- { $set: { user_id: this.newUserId } }
|
|
|
|
|
|
|
+ describe('removeProjectFromTag', function () {
|
|
|
|
|
+ describe('with a valid tag_id', function () {
|
|
|
|
|
+ it('should call update in mongo', function (done) {
|
|
|
|
|
+ this.TagMock.expects('updateOne')
|
|
|
|
|
+ .once()
|
|
|
|
|
+ .withArgs(
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: this.tagId,
|
|
|
|
|
+ user_id: this.userId,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ $pull: { project_ids: this.projectId },
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ .resolves()
|
|
|
|
|
+ this.TagsHandler.removeProjectFromTag(
|
|
|
|
|
+ this.userId,
|
|
|
|
|
+ this.tagId,
|
|
|
|
|
+ this.projectId,
|
|
|
|
|
+ err => {
|
|
|
|
|
+ expect(err).to.not.exist
|
|
|
|
|
+ this.TagMock.verify()
|
|
|
|
|
+ done()
|
|
|
|
|
+ }
|
|
|
)
|
|
)
|
|
|
- .yields()
|
|
|
|
|
- this.TagsHandler.updateTagUserIds(this.userId, this.newUserId, err => {
|
|
|
|
|
- expect(err).to.not.exist
|
|
|
|
|
- this.TagMock.verify()
|
|
|
|
|
- done()
|
|
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('removeProjectFromTag', function () {
|
|
|
|
|
|
|
+ describe('removeProjectsFromTag', function () {
|
|
|
describe('with a valid tag_id', function () {
|
|
describe('with a valid tag_id', function () {
|
|
|
it('should call update in mongo', function (done) {
|
|
it('should call update in mongo', function (done) {
|
|
|
this.TagMock.expects('updateOne')
|
|
this.TagMock.expects('updateOne')
|
|
@@ -214,14 +248,14 @@ describe('TagsHandler', function () {
|
|
|
user_id: this.userId,
|
|
user_id: this.userId,
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- $pull: { project_ids: this.projectId },
|
|
|
|
|
|
|
+ $pullAll: { project_ids: this.projectIds },
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- .yields()
|
|
|
|
|
- this.TagsHandler.removeProjectFromTag(
|
|
|
|
|
|
|
+ .resolves()
|
|
|
|
|
+ this.TagsHandler.removeProjectsFromTag(
|
|
|
this.userId,
|
|
this.userId,
|
|
|
this.tagId,
|
|
this.tagId,
|
|
|
- this.projectId,
|
|
|
|
|
|
|
+ this.projectIds,
|
|
|
err => {
|
|
err => {
|
|
|
expect(err).to.not.exist
|
|
expect(err).to.not.exist
|
|
|
this.TagMock.verify()
|
|
this.TagMock.verify()
|
|
@@ -244,7 +278,7 @@ describe('TagsHandler', function () {
|
|
|
$pull: { project_ids: this.projectId },
|
|
$pull: { project_ids: this.projectId },
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- .yields()
|
|
|
|
|
|
|
+ .resolves()
|
|
|
this.TagsHandler.removeProjectFromAllTags(
|
|
this.TagsHandler.removeProjectFromAllTags(
|
|
|
this.userId,
|
|
this.userId,
|
|
|
this.projectId,
|
|
this.projectId,
|
|
@@ -263,7 +297,7 @@ describe('TagsHandler', function () {
|
|
|
this.TagMock.expects('deleteOne')
|
|
this.TagMock.expects('deleteOne')
|
|
|
.once()
|
|
.once()
|
|
|
.withArgs({ _id: this.tagId, user_id: this.userId })
|
|
.withArgs({ _id: this.tagId, user_id: this.userId })
|
|
|
- .yields()
|
|
|
|
|
|
|
+ .resolves()
|
|
|
this.TagsHandler.deleteTag(this.userId, this.tagId, err => {
|
|
this.TagsHandler.deleteTag(this.userId, this.tagId, err => {
|
|
|
expect(err).to.not.exist
|
|
expect(err).to.not.exist
|
|
|
this.TagMock.verify()
|
|
this.TagMock.verify()
|
|
@@ -283,7 +317,7 @@ describe('TagsHandler', function () {
|
|
|
{ _id: this.tagId, user_id: this.userId },
|
|
{ _id: this.tagId, user_id: this.userId },
|
|
|
{ $set: { name: this.newName } }
|
|
{ $set: { name: this.newName } }
|
|
|
)
|
|
)
|
|
|
- .yields()
|
|
|
|
|
|
|
+ .resolves()
|
|
|
this.TagsHandler.renameTag(
|
|
this.TagsHandler.renameTag(
|
|
|
this.userId,
|
|
this.userId,
|
|
|
this.tagId,
|
|
this.tagId,
|