2018-08-10 07:40:25 -04:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
require('chai').should()
|
|
|
|
expect = require('chai').expect
|
|
|
|
sinon = require('sinon')
|
|
|
|
modulePath = require('path').join __dirname, '../../../../app/js/Features/Institutions/InstitutionsGetter.js'
|
|
|
|
|
|
|
|
describe 'InstitutionsGetter', ->
|
|
|
|
beforeEach ->
|
|
|
|
@UserGetter = getUserFullEmails: sinon.stub()
|
|
|
|
@InstitutionsGetter = SandboxedModule.require modulePath, requires:
|
|
|
|
'../User/UserGetter': @UserGetter
|
|
|
|
'logger-sharelatex':
|
|
|
|
log:-> console.log(arguments)
|
|
|
|
err:->
|
|
|
|
|
|
|
|
@userId = '12345abcde'
|
|
|
|
|
|
|
|
describe "getConfirmedInstitutions", ->
|
2018-08-27 05:37:59 -04:00
|
|
|
it 'filters unconfirmed affiliations', (done) ->
|
2018-08-10 07:40:25 -04:00
|
|
|
@userEmails = [
|
2018-08-27 05:37:59 -04:00
|
|
|
{ confirmedAt: null, affiliation: institution: { id: 123, confirmed: true } }
|
|
|
|
{ confirmedAt: new Date(), affiliation: institution: { id: 456, confirmed: true } }
|
2018-08-10 07:40:25 -04:00
|
|
|
{ confirmedAt: new Date(), affiliation: null }
|
|
|
|
{ confirmedAt: new Date(), affiliation: institution: null }
|
2018-08-27 05:37:59 -04:00
|
|
|
{ confirmedAt: new Date(), affiliation: institution: { id: 789, confirmed: false } }
|
2018-08-10 07:40:25 -04:00
|
|
|
]
|
|
|
|
@UserGetter.getUserFullEmails.yields(null, @userEmails)
|
|
|
|
@InstitutionsGetter.getConfirmedInstitutions @userId, (error, institutions) ->
|
|
|
|
expect(error).to.not.exist
|
|
|
|
institutions.length.should.equal 1
|
|
|
|
institutions[0].id.should.equal 456
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should handle empty response', (done) ->
|
|
|
|
@UserGetter.getUserFullEmails.yields(null, [])
|
|
|
|
@InstitutionsGetter.getConfirmedInstitutions @userId, (error, institutions) ->
|
|
|
|
expect(error).to.not.exist
|
|
|
|
institutions.length.should.equal 0
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should handle error', (done) ->
|
|
|
|
@UserGetter.getUserFullEmails.yields(new Error('Nope'))
|
|
|
|
@InstitutionsGetter.getConfirmedInstitutions @userId, (error, institutions) ->
|
|
|
|
expect(error).to.exist
|
|
|
|
done()
|