             done()
 
         after (done) ->
+            dbGetStub.restore()
             addAccessStub.restore()
             dbRemoveStub.restore()
             done()

            (err, res, body) ->
                res.statusCode.should.equal 400
                res.body.error.should.equal "Bad request: body is incomplete"
                done()

        it 'should return an error when the req structure is incorrect: preToken
        is missing or empty', (done) ->
            data = _.cloneDeep answer
            data.preToken = ''
            client.post "services/sharing/sendAnswer/", data,
            (err, res, body) ->
                res.statusCode.should.equal 400
                res.body.error.should.equal "Bad request: body is incomplete"
                done()

        it 'should return an error when the req structure is incorrect: url is
        missing or empty', (done) ->
            data = _.cloneDeep answer
            data.recipientUrl = null
            client.post "services/sharing/sendAnswer/", data,
            (err, res, body) ->
                res.statusCode.should.equal 400
                res.body.error.should.equal "Bad request: body is incomplete"
                done()

        it 'should return an error when the req structure is incorrect:
        sharerUrl is missing or empty', (done) ->
            data = _.cloneDeep answer
            data.sharerUrl = null
            client.post "services/sharing/sendAnswer/", data,
            (err, res, body) ->
                res.statusCode.should.equal 400
                res.body.error.should.equal "Bad request: body is incomplete"
                done()

        it 'should return an error when the req structure is incorrect: rules is
        missing or empty', (done) ->
            data = _.cloneDeep answer
            data.rules = []
            client.post "services/sharing/sendAnswer/", data,
            (err, res, body) ->
                res.statusCode.should.equal 400
                res.body.error.should.equal "Bad request: body is incomplete"
                done()

        it 'should return an error when the req structure is incorrect: a rule
        is missing an id', (done) ->
            data = _.cloneDeep answer
            data.rules = [{id: 1, docType: 'event'},{id: '', docType: 'event'}]
            client.post "services/sharing/sendAnswer/", data,
            (err, res, body) ->
                res.statusCode.should.equal 400
                res.body.error.should.equal "Bad request: incorrect rule
                    detected"
                done()

        it 'should return an error when the req structure is incorrect: a rule
        is missing a docType', (done) ->
            data = _.cloneDeep answer
            data.rules = [{id: 1, docType: 'event'},{id: 2}]
            client.post "services/sharing/sendAnswer/", data,
            (err, res, body) ->
                res.statusCode.should.equal 400
                res.body.error.should.equal "Bad request: incorrect rule
                    detected"
                done()

        it 'should return an error when addAccess failed', (done) ->

        # Correct answer structure expected
        answer =
            id          : 'IdOfTheRecipientShareDocument'
            #shareID     : 'IdOfTheSharerShareDocument'
            accepted    : true
            #preToken    : 'preToken'
            #recipientUrl: 'urlOfTheRecipient'
            #sharerUrl   : 'urlOfTheSharer'
            #rules       : [{id: 1, docType: 'event'}, {id: 2, docType: 'event'}]

        # We stub the addAccess module from lib/token.coffee: we return an
        # error to avoid having our code run entirely if a test fails.
        addAccessStub = {}
        # Same for the remove and get function
        dbRemoveStub  = {}
        dbGetStub = {}

        before (done) ->
            dbGetStub    = sinon.stub db, "get", (id, callback) ->
                callback null, _.cloneDeep answer

            addAccessStub = sinon.stub libToken, "addAccess",
                (access, callback) ->
                    callback new Error "libToken.addAccess"
