mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
add new tag methods
This commit is contained in:
parent
5025b54c9c
commit
e4e6a0fa1b
2 changed files with 73 additions and 1 deletions
|
@ -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 =
|
||||
|
|
|
@ -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
|
||||
@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
|
||||
|
|
Loading…
Reference in a new issue