mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-27 02:51:57 +02:00
Merge pull request #829 from sharelatex/ta-affiliation-empty
Always return an Array when Getting Affiliations
This commit is contained in:
@@ -9,7 +9,7 @@ module.exports = InstitutionsAPI =
|
||||
method: 'GET'
|
||||
path: "/api/v2/institutions/#{institutionId.toString()}/affiliations"
|
||||
defaultErrorMessage: "Couldn't get institution affiliations"
|
||||
}, callback
|
||||
}, (error, body) -> callback(error, body or [])
|
||||
|
||||
|
||||
getUserAffiliations: (userId, callback = (error, body) ->) ->
|
||||
@@ -17,7 +17,7 @@ module.exports = InstitutionsAPI =
|
||||
method: 'GET'
|
||||
path: "/api/v2/users/#{userId.toString()}/affiliations"
|
||||
defaultErrorMessage: "Couldn't get user affiliations"
|
||||
}, callback
|
||||
}, (error, body) -> callback(error, body or [])
|
||||
|
||||
|
||||
addAffiliation: (userId, email, affiliationOptions, callback) ->
|
||||
|
||||
@@ -11,12 +11,12 @@ describe "InstitutionsAPI", ->
|
||||
|
||||
beforeEach ->
|
||||
@logger = err: sinon.stub(), log: ->
|
||||
settings = apis: { v1: { url: 'v1.url', user: '', pass: '' } }
|
||||
@settings = apis: { v1: { url: 'v1.url', user: '', pass: '' } }
|
||||
@request = sinon.stub()
|
||||
@InstitutionsAPI = SandboxedModule.require modulePath, requires:
|
||||
"logger-sharelatex": @logger
|
||||
"metrics-sharelatex": timeAsyncMethod: sinon.stub()
|
||||
'settings-sharelatex': settings
|
||||
'settings-sharelatex': @settings
|
||||
'request': @request
|
||||
|
||||
@stubbedUser =
|
||||
@@ -41,6 +41,14 @@ describe "InstitutionsAPI", ->
|
||||
body.should.equal responseBody
|
||||
done()
|
||||
|
||||
it 'handle empty response', (done)->
|
||||
@settings.apis = null
|
||||
@InstitutionsAPI.getInstitutionAffiliations @institutionId, (err, body) =>
|
||||
should.not.exist(err)
|
||||
expect(body).to.be.a 'Array'
|
||||
body.length.should.equal 0
|
||||
done()
|
||||
|
||||
describe 'getUserAffiliations', ->
|
||||
it 'get affiliations', (done)->
|
||||
responseBody = [{ foo: 'bar' }]
|
||||
@@ -65,6 +73,14 @@ describe "InstitutionsAPI", ->
|
||||
err.message.should.have.string body.errors
|
||||
done()
|
||||
|
||||
it 'handle empty response', (done)->
|
||||
@settings.apis = null
|
||||
@InstitutionsAPI.getUserAffiliations @stubbedUser._id, (err, body) =>
|
||||
should.not.exist(err)
|
||||
expect(body).to.be.a 'Array'
|
||||
body.length.should.equal 0
|
||||
done()
|
||||
|
||||
describe 'addAffiliation', ->
|
||||
beforeEach ->
|
||||
@request.callsArgWith(1, null, { statusCode: 201 })
|
||||
|
||||
Reference in New Issue
Block a user