mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
49e19cad64
Add group and institution membership and management info to subscription dashboard GitOrigin-RevId: 1aba5d5a20cd00ff5090811d0f66dc9c4944dd60
47 lines
1.9 KiB
CoffeeScript
47 lines
1.9 KiB
CoffeeScript
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
|
|
"../UserMembership/UserMembershipHandler": @UserMembershipHandler = {}
|
|
"../UserMembership/UserMembershipEntityConfigs": @UserMembershipEntityConfigs = {}
|
|
'logger-sharelatex':
|
|
log:-> console.log(arguments)
|
|
err:->
|
|
|
|
@userId = '12345abcde'
|
|
|
|
describe "getConfirmedInstitutions", ->
|
|
it 'filters unconfirmed affiliations', (done) ->
|
|
@userEmails = [
|
|
{ confirmedAt: null, affiliation: institution: { id: 123, confirmed: true } }
|
|
{ confirmedAt: new Date(), affiliation: institution: { id: 456, confirmed: true } }
|
|
{ confirmedAt: new Date(), affiliation: null }
|
|
{ confirmedAt: new Date(), affiliation: institution: null }
|
|
{ confirmedAt: new Date(), affiliation: institution: { id: 789, confirmed: false } }
|
|
]
|
|
@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()
|