Przeglądaj źródła

add new tag methods

Ersun Warncke 8 lat temu
rodzic
commit
e4e6a0fa1b

+ 18 - 0
services/web/app/coffee/Features/Tags/TagsHandler.coffee

@@ -39,6 +39,15 @@ module.exports = TagsHandler =
 		request.del {url, timeout: TIMEOUT}, (err, res, body) ->
 		request.del {url, timeout: TIMEOUT}, (err, res, body) ->
 			TagsHandler._handleResponse err, res, {url, user_id, tag_id}, callback
 			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)->
 	removeProjectFromTag: (user_id, tag_id, project_id, callback)->
 		url = "#{settings.apis.tags.url}/user/#{user_id}/tag/#{tag_id}/project/#{project_id}"
 		url = "#{settings.apis.tags.url}/user/#{user_id}/tag/#{tag_id}/project/#{project_id}"
 		request.del {url, timeout: TIMEOUT}, (err, res, body) ->
 		request.del {url, timeout: TIMEOUT}, (err, res, body) ->
@@ -49,6 +58,15 @@ module.exports = TagsHandler =
 		request.post {url, timeout: TIMEOUT}, (err, res, body) ->
 		request.post {url, timeout: TIMEOUT}, (err, res, body) ->
 			TagsHandler._handleResponse err, res, {url, user_id, tag_id, project_id}, callback
 			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)->
 	removeProjectFromAllTags: (user_id, project_id, callback)->
 		url = "#{settings.apis.tags.url}/user/#{user_id}/project/#{project_id}"
 		url = "#{settings.apis.tags.url}/user/#{user_id}/project/#{project_id}"
 		opts =
 		opts =

+ 55 - 1
services/web/test/unit/coffee/Tags/TagsHandlerTests.coffee

@@ -211,4 +211,58 @@ describe 'TagsHandler', ->
 				@handler.addProjectToTag user_id, tag_id, project_id, @callback
 				@handler.addProjectToTag user_id, tag_id, project_id, @callback
 			
 			
 			it "should call the callback with an Error", ->
 			it "should call the callback with an Error", ->
-				@callback.calledWith(new Error()).should.equal true
+				@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