mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #961 from sharelatex/ta-account-sync-affiliations
Add getInstitutionsPlan Function
This commit is contained in:
commit
c74c782cee
2 changed files with 37 additions and 7 deletions
|
@ -5,11 +5,17 @@ logger = require 'logger-sharelatex'
|
||||||
|
|
||||||
module.exports = InstitutionsFeatures =
|
module.exports = InstitutionsFeatures =
|
||||||
getInstitutionsFeatures: (userId, callback = (error, features) ->) ->
|
getInstitutionsFeatures: (userId, callback = (error, features) ->) ->
|
||||||
|
InstitutionsFeatures.getInstitutionsPlan userId, (error, plan) ->
|
||||||
|
return callback error if error?
|
||||||
|
plan = PlansLocator.findLocalPlanInSettings plan
|
||||||
|
callback(null, plan?.features or {})
|
||||||
|
|
||||||
|
|
||||||
|
getInstitutionsPlan: (userId, callback = (error, plan) ->) ->
|
||||||
InstitutionsFeatures.hasLicence userId, (error, hasLicence) ->
|
InstitutionsFeatures.hasLicence userId, (error, hasLicence) ->
|
||||||
return callback error if error?
|
return callback error if error?
|
||||||
return callback(null, {}) unless hasLicence
|
return callback(null, null) unless hasLicence
|
||||||
plan = PlansLocator.findLocalPlanInSettings Settings.institutionPlanCode
|
callback(null, Settings.institutionPlanCode)
|
||||||
callback(null, plan?.features or {})
|
|
||||||
|
|
||||||
|
|
||||||
hasLicence: (userId, callback = (error, hasLicence) ->) ->
|
hasLicence: (userId, callback = (error, hasLicence) ->) ->
|
||||||
|
|
|
@ -61,26 +61,50 @@ describe 'InstitutionsFeatures', ->
|
||||||
|
|
||||||
describe "getInstitutionsFeatures", ->
|
describe "getInstitutionsFeatures", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@InstitutionsFeatures.hasLicence = sinon.stub()
|
@InstitutionsFeatures.getInstitutionsPlan = sinon.stub()
|
||||||
@testFeatures = features: { institution: 'all' }
|
@testFeatures = features: { institution: 'all' }
|
||||||
@PlansLocator.findLocalPlanInSettings.withArgs(@institutionPlanCode).returns(@testFeatures)
|
@PlansLocator.findLocalPlanInSettings.withArgs(@institutionPlanCode).returns(@testFeatures)
|
||||||
|
|
||||||
it 'should handle error', (done)->
|
it 'should handle error', (done)->
|
||||||
@InstitutionsFeatures.hasLicence.yields(new Error('Nope'))
|
@InstitutionsFeatures.getInstitutionsPlan.yields(new Error('Nope'))
|
||||||
@InstitutionsFeatures.getInstitutionsFeatures @userId, (error, features) ->
|
@InstitutionsFeatures.getInstitutionsFeatures @userId, (error, features) ->
|
||||||
expect(error).to.exist
|
expect(error).to.exist
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should return no feaures if user has no plan code', (done) ->
|
it 'should return no feaures if user has no plan code', (done) ->
|
||||||
@InstitutionsFeatures.hasLicence.yields(null, false)
|
@InstitutionsFeatures.getInstitutionsPlan.yields(null, null)
|
||||||
@InstitutionsFeatures.getInstitutionsFeatures @userId, (error, features) ->
|
@InstitutionsFeatures.getInstitutionsFeatures @userId, (error, features) ->
|
||||||
expect(error).to.not.exist
|
expect(error).to.not.exist
|
||||||
expect(features).to.deep.equal {}
|
expect(features).to.deep.equal {}
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should return feaures if user has affiliations plan code', (done) ->
|
it 'should return feaures if user has affiliations plan code', (done) ->
|
||||||
@InstitutionsFeatures.hasLicence.yields(null, true)
|
@InstitutionsFeatures.getInstitutionsPlan.yields(null, @institutionPlanCode)
|
||||||
@InstitutionsFeatures.getInstitutionsFeatures @userId, (error, features) =>
|
@InstitutionsFeatures.getInstitutionsFeatures @userId, (error, features) =>
|
||||||
expect(error).to.not.exist
|
expect(error).to.not.exist
|
||||||
expect(features).to.deep.equal @testFeatures.features
|
expect(features).to.deep.equal @testFeatures.features
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "getInstitutionsPlan", ->
|
||||||
|
beforeEach ->
|
||||||
|
@InstitutionsFeatures.hasLicence = sinon.stub()
|
||||||
|
|
||||||
|
it 'should handle error', (done)->
|
||||||
|
@InstitutionsFeatures.hasLicence.yields(new Error('Nope'))
|
||||||
|
@InstitutionsFeatures.getInstitutionsPlan @userId, (error) ->
|
||||||
|
expect(error).to.exist
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should return no plan if user has no licence', (done) ->
|
||||||
|
@InstitutionsFeatures.hasLicence.yields(null, false)
|
||||||
|
@InstitutionsFeatures.getInstitutionsPlan @userId, (error, plan) ->
|
||||||
|
expect(error).to.not.exist
|
||||||
|
expect(plan).to.equal null
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should return plan if user has licence', (done) ->
|
||||||
|
@InstitutionsFeatures.hasLicence.yields(null, true)
|
||||||
|
@InstitutionsFeatures.getInstitutionsPlan @userId, (error, plan) =>
|
||||||
|
expect(error).to.not.exist
|
||||||
|
expect(plan).to.equal @institutionPlanCode
|
||||||
|
done()
|
||||||
|
|
Loading…
Reference in a new issue