Explicitly create tags and get their id
This commit is contained in:
@@ -16,6 +16,7 @@ describe 'TagsController', ->
|
||||
removeProjectFromTag: sinon.stub().callsArgWith(3)
|
||||
deleteTag: sinon.stub().callsArg(2)
|
||||
renameTag: sinon.stub().callsArg(3)
|
||||
createTag: sinon.stub()
|
||||
@controller = SandboxedModule.require modulePath, requires:
|
||||
"./TagsHandler":@handler
|
||||
'logger-sharelatex':
|
||||
@@ -31,15 +32,31 @@ describe 'TagsController', ->
|
||||
@res = {}
|
||||
@res.status = sinon.stub().returns @res
|
||||
@res.end = sinon.stub()
|
||||
@res.json = sinon.stub()
|
||||
|
||||
describe "getAllTags", ->
|
||||
it 'should ask the handler for all tags', (done)->
|
||||
allTags = [{name:"tag", projects:["123423","423423"]}]
|
||||
@handler.getAllTags = sinon.stub().callsArgWith(1, null, allTags)
|
||||
@controller.getAllTags @req, send:(body)=>
|
||||
@controller.getAllTags @req, json:(body)=>
|
||||
body.should.equal allTags
|
||||
@handler.getAllTags.calledWith(user_id).should.equal true
|
||||
done()
|
||||
|
||||
describe "createTag", ->
|
||||
beforeEach ->
|
||||
@handler.createTag.callsArgWith(2, null, @tag = {"mock": "tag"})
|
||||
@req.session.user._id = @user_id = "user-id-123"
|
||||
@req.body = name: @name = "tag-name"
|
||||
@controller.createTag @req, @res
|
||||
|
||||
it "should create the tag in the backend", ->
|
||||
@handler.createTag
|
||||
.calledWith(@user_id, @name)
|
||||
.should.equal true
|
||||
|
||||
it "should return the tag", ->
|
||||
@res.json.calledWith(@tag).should.equal true
|
||||
|
||||
describe "deleteTag", ->
|
||||
beforeEach ->
|
||||
|
||||
@@ -29,10 +29,10 @@ describe 'TagsHandler', ->
|
||||
describe "removeProjectFromAllTags", ->
|
||||
it 'should tell the tags api to remove the project_id from all the users tags', (done)->
|
||||
@handler.removeProjectFromAllTags user_id, project_id, =>
|
||||
@request.del.calledWith({uri:"#{tagsUrl}/user/#{user_id}/project/#{project_id}", timeout:1000}).should.equal true
|
||||
@request.del.calledWith({url:"#{tagsUrl}/user/#{user_id}/project/#{project_id}", timeout:1000}).should.equal true
|
||||
done()
|
||||
|
||||
describe "groupTagsByProject", ->
|
||||
describe "_groupTagsByProject", ->
|
||||
it 'should group the tags by project_id', (done)->
|
||||
rawTags = [
|
||||
{name:"class101", project_ids:["1234", "51db33e31a55afd212000007"]}
|
||||
@@ -41,35 +41,35 @@ describe 'TagsHandler', ->
|
||||
{name:"different", project_ids:["1234", "e2c39a2f09000100"]}
|
||||
]
|
||||
|
||||
@handler.groupTagsByProject rawTags, (err, tags)->
|
||||
@handler._groupTagsByProject rawTags, (err, tags)->
|
||||
_.size(tags).should.equal 7
|
||||
done()
|
||||
|
||||
describe "requestTags", ->
|
||||
describe "_requestTags", ->
|
||||
it 'should return an err and empty array on error', (done)->
|
||||
@request.get.callsArgWith(1, {something:"wrong"}, {statusCode:200}, [])
|
||||
@handler.requestTags user_id, (err, allTags)=>
|
||||
@handler._requestTags user_id, (err, allTags)=>
|
||||
allTags.length.should.equal 0
|
||||
assert.isDefined err
|
||||
done()
|
||||
|
||||
it 'should return an err and empty array on no body', (done)->
|
||||
@request.get.callsArgWith(1, {something:"wrong"}, {statusCode:200}, undefined)
|
||||
@handler.requestTags user_id, (err, allTags)=>
|
||||
@handler._requestTags user_id, (err, allTags)=>
|
||||
allTags.length.should.equal 0
|
||||
assert.isDefined err
|
||||
done()
|
||||
|
||||
it 'should return an err and empty array on non 200 response', (done)->
|
||||
@request.get.callsArgWith(1, null, {statusCode:201}, [])
|
||||
@handler.requestTags user_id, (err, allTags)=>
|
||||
@handler._requestTags user_id, (err, allTags)=>
|
||||
allTags.length.should.equal 0
|
||||
assert.isDefined err
|
||||
done()
|
||||
|
||||
it 'should return an err and empty array on no body and no response', (done)->
|
||||
@request.get.callsArgWith(1, {something:"wrong"}, undefined, undefined)
|
||||
@handler.requestTags user_id, (err, allTags)=>
|
||||
@handler._requestTags user_id, (err, allTags)=>
|
||||
allTags.length.should.equal 0
|
||||
assert.isDefined err
|
||||
done()
|
||||
@@ -93,6 +93,24 @@ describe 'TagsHandler', ->
|
||||
allTags.length.should.equal 0
|
||||
_.size(projectGroupedTags).should.equal 0
|
||||
|
||||
describe "createTag", ->
|
||||
beforeEach ->
|
||||
@request.post = sinon.stub().callsArgWith(1, null, {statusCode: 204}, "")
|
||||
@handler.createTag user_id, @name = "tag_name", @callback
|
||||
|
||||
it "should send a request to the tag backend", ->
|
||||
@request.post
|
||||
.calledWith({
|
||||
url: "#{tagsUrl}/user/#{user_id}/tag"
|
||||
json:
|
||||
name: @name
|
||||
timeout: 1000
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback with no error", ->
|
||||
@callback.calledWith(null).should.equal true
|
||||
|
||||
describe "deleteTag", ->
|
||||
describe "successfully", ->
|
||||
beforeEach ->
|
||||
|
||||
Reference in New Issue
Block a user