mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Unit tests for tryDeleteUser
This commit is contained in:
parent
7cc26f2207
commit
a4167fcccd
1 changed files with 76 additions and 0 deletions
|
@ -84,6 +84,7 @@ describe "UserController", ->
|
|||
sendStatus: sinon.stub()
|
||||
json: sinon.stub()
|
||||
@next = sinon.stub()
|
||||
|
||||
describe "deleteUser", ->
|
||||
|
||||
it "should delete the user", (done)->
|
||||
|
@ -94,6 +95,81 @@ describe "UserController", ->
|
|||
done()
|
||||
@UserController.deleteUser @req, @res
|
||||
|
||||
describe 'tryDeleteUser', ->
|
||||
|
||||
beforeEach ->
|
||||
@req.body.password = 'wat'
|
||||
@AuthenticationController.getLoggedInUserId = sinon.stub().returns(@user._id)
|
||||
@AuthenticationManager.authenticate = sinon.stub().callsArgWith(2, null, @user)
|
||||
@UserDeleter.deleteUser = sinon.stub().callsArgWith(1, null)
|
||||
|
||||
it 'should send 200', (done) ->
|
||||
@res.sendStatus = (code) =>
|
||||
code.should.equal 200
|
||||
done()
|
||||
@UserController.tryDeleteUser @req, @res, @next
|
||||
|
||||
it 'should try to authenticate user', (done) ->
|
||||
@res.sendStatus = (code) =>
|
||||
@AuthenticationManager.authenticate.callCount.should.equal 1
|
||||
@AuthenticationManager.authenticate.calledWith({_id: @user._id}, @req.body.password).should.equal true
|
||||
done()
|
||||
@UserController.tryDeleteUser @req, @res, @next
|
||||
|
||||
it 'should delete the user', (done) ->
|
||||
@res.sendStatus = (code) =>
|
||||
@UserDeleter.deleteUser.callCount.should.equal 1
|
||||
@UserDeleter.deleteUser.calledWith(@user._id).should.equal true
|
||||
done()
|
||||
@UserController.tryDeleteUser @req, @res, @next
|
||||
|
||||
describe 'when no password is supplied', ->
|
||||
|
||||
beforeEach ->
|
||||
@req.body.password = ''
|
||||
|
||||
it 'should return 403', (done) ->
|
||||
@res.sendStatus = (code) =>
|
||||
code.should.equal 403
|
||||
done()
|
||||
@UserController.tryDeleteUser @req, @res, @next
|
||||
|
||||
describe 'when authenticate produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@AuthenticationManager.authenticate = sinon.stub().callsArgWith(2, new Error('woops'))
|
||||
|
||||
it 'should call next with an error', (done) ->
|
||||
@next = (err) =>
|
||||
expect(err).to.not.equal null
|
||||
expect(err).to.be.instanceof Error
|
||||
done()
|
||||
@UserController.tryDeleteUser @req, @res, @next
|
||||
|
||||
describe 'when authenticate does not produce a user', ->
|
||||
|
||||
beforeEach ->
|
||||
@AuthenticationManager.authenticate = sinon.stub().callsArgWith(2, null, null)
|
||||
|
||||
it 'should return 403', (done) ->
|
||||
@res.sendStatus = (code) =>
|
||||
code.should.equal 403
|
||||
done()
|
||||
@UserController.tryDeleteUser @req, @res, @next
|
||||
|
||||
describe 'when deleteUser produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@UserDeleter.deleteUser = sinon.stub().callsArgWith(1, new Error('woops'))
|
||||
|
||||
it 'should call next with an error', (done) ->
|
||||
@next = (err) =>
|
||||
expect(err).to.not.equal null
|
||||
expect(err).to.be.instanceof Error
|
||||
done()
|
||||
@UserController.tryDeleteUser @req, @res, @next
|
||||
|
||||
|
||||
describe "unsubscribe", ->
|
||||
|
||||
it "should send the user to unsubscribe", (done)->
|
||||
|
|
Loading…
Reference in a new issue