From e4e6a0fa1b9eac540c9437ef7cc11d06220714f7 Mon Sep 17 00:00:00 2001 From: Ersun Warncke Date: Mon, 3 Sep 2018 04:06:24 -0400 Subject: [PATCH] add new tag methods --- .../coffee/Features/Tags/TagsHandler.coffee | 18 ++++++ .../unit/coffee/Tags/TagsHandlerTests.coffee | 56 ++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/services/web/app/coffee/Features/Tags/TagsHandler.coffee b/services/web/app/coffee/Features/Tags/TagsHandler.coffee index 2dc57608bd..5a0c746295 100644 --- a/services/web/app/coffee/Features/Tags/TagsHandler.coffee +++ b/services/web/app/coffee/Features/Tags/TagsHandler.coffee @@ -39,6 +39,15 @@ module.exports = TagsHandler = request.del {url, timeout: TIMEOUT}, (err, res, body) -> TagsHandler._handleResponse err, res, {url, user_id, tag_id}, callback + updateTagUserIds: (old_user_id, new_user_id, callback) -> + opts = + url: "#{settings.apis.tags.url}/user/#{old_user_id}/tag" + json: + user_id: new_user_id + timeout: TIMEOUT + request.put opts, (err, res, body)-> + TagsHandler._handleResponse err, res, {old_user_id, new_user_id}, callback + removeProjectFromTag: (user_id, tag_id, project_id, callback)-> url = "#{settings.apis.tags.url}/user/#{user_id}/tag/#{tag_id}/project/#{project_id}" request.del {url, timeout: TIMEOUT}, (err, res, body) -> @@ -49,6 +58,15 @@ module.exports = TagsHandler = request.post {url, timeout: TIMEOUT}, (err, res, body) -> TagsHandler._handleResponse err, res, {url, user_id, tag_id, project_id}, callback + addProjectToTagName: (user_id, name, project_id, callback)-> + url = "#{settings.apis.tags.url}/user/#{user_id}/tag/project/#{project_id}" + opts = + json: { name } + timeout: TIMEOUT + url: url + request.post opts, (err, res, body) -> + TagsHandler._handleResponse err, res, {url, user_id, name, project_id}, callback + removeProjectFromAllTags: (user_id, project_id, callback)-> url = "#{settings.apis.tags.url}/user/#{user_id}/project/#{project_id}" opts = diff --git a/services/web/test/unit/coffee/Tags/TagsHandlerTests.coffee b/services/web/test/unit/coffee/Tags/TagsHandlerTests.coffee index df75cf827f..016b025169 100644 --- a/services/web/test/unit/coffee/Tags/TagsHandlerTests.coffee +++ b/services/web/test/unit/coffee/Tags/TagsHandlerTests.coffee @@ -211,4 +211,58 @@ describe 'TagsHandler', -> @handler.addProjectToTag user_id, tag_id, project_id, @callback it "should call the callback with an Error", -> - @callback.calledWith(new Error()).should.equal true \ No newline at end of file + @callback.calledWith(new Error()).should.equal true + + describe "addProjectToTagName", -> + describe "successfully", -> + beforeEach -> + @request.post = sinon.stub().callsArgWith(1, null, {statusCode: 204}, "") + @handler.addProjectToTagName user_id, tag, project_id, @callback + + it "should send a request to the tag backend", -> + @request.post + .calledWith({ + json: + name: tag + url: "#{tagsUrl}/user/#{user_id}/tag/project/#{project_id}" + timeout: 1000 + }) + .should.equal true + + it "should call the callback with no error", -> + @callback.calledWith(null).should.equal true + + describe "with error", -> + beforeEach -> + @request.post = sinon.stub().callsArgWith(1, null, {statusCode: 500}, "") + @handler.addProjectToTagName user_id, tag_id, project_id, @callback + + it "should call the callback with an Error", -> + @callback.calledWith(new Error()).should.equal true + + describe "updateTagUserIds", -> + describe "successfully", -> + beforeEach -> + @request.put = sinon.stub().callsArgWith(1, null, {statusCode: 204}, "") + @handler.updateTagUserIds "old-user-id", "new-user-id", @callback + + it "should send a request to the tag backend", -> + @request.put + .calledWith({ + json: + user_id: "new-user-id" + url: "#{tagsUrl}/user/old-user-id/tag" + timeout: 1000 + }) + .should.equal true + + it "should call the callback with no error", -> + @callback.calledWith(null).should.equal true + + describe "with error", -> + beforeEach -> + @request.put = sinon.stub().callsArgWith(1, null, {statusCode: 500}, "") + @handler.updateTagUserIds "old-user-id", "new-user-id", @callback + + it "should call the callback with an Error", -> + @callback.calledWith(new Error()).should.equal true