2018-07-10 05:42:17 -04:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
assert = require('assert')
|
|
|
|
require('chai').should()
|
|
|
|
expect = require('chai').expect
|
|
|
|
sinon = require('sinon')
|
|
|
|
modulePath = require('path').join __dirname, '../../../../app/js/Features/Institutions/InstitutionsFeatures.js'
|
|
|
|
|
|
|
|
describe 'InstitutionsFeatures', ->
|
|
|
|
|
|
|
|
beforeEach ->
|
2018-08-10 07:40:25 -04:00
|
|
|
@InstitutionsGetter = getConfirmedInstitutions: sinon.stub()
|
2018-07-10 05:42:17 -04:00
|
|
|
@PlansLocator = findLocalPlanInSettings: sinon.stub()
|
|
|
|
@institutionPlanCode = 'institution_plan_code'
|
|
|
|
@InstitutionsFeatures = SandboxedModule.require modulePath, requires:
|
2018-08-10 07:40:25 -04:00
|
|
|
'./InstitutionsGetter': @InstitutionsGetter
|
2018-07-10 05:42:17 -04:00
|
|
|
'../Subscription/PlansLocator': @PlansLocator
|
|
|
|
'settings-sharelatex': institutionPlanCode: @institutionPlanCode
|
|
|
|
'logger-sharelatex':
|
|
|
|
log:->
|
|
|
|
err:->
|
|
|
|
|
|
|
|
@userId = '12345abcde'
|
|
|
|
|
|
|
|
describe "hasLicence", ->
|
|
|
|
it 'should handle error', (done)->
|
2018-08-10 07:40:25 -04:00
|
|
|
@InstitutionsGetter.getConfirmedInstitutions.yields(new Error('Nope'))
|
2018-07-10 05:42:17 -04:00
|
|
|
@InstitutionsFeatures.hasLicence @userId, (error, hasLicence) ->
|
|
|
|
expect(error).to.exist
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return false if user has no confirmed affiliations', (done) ->
|
2018-08-10 07:40:25 -04:00
|
|
|
institutions = []
|
|
|
|
@InstitutionsGetter.getConfirmedInstitutions.yields(null, institutions)
|
2018-07-10 05:42:17 -04:00
|
|
|
@InstitutionsFeatures.hasLicence @userId, (error, hasLicence) ->
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(hasLicence).to.be.false
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return false if user has no paid affiliations', (done) ->
|
2018-08-10 07:40:25 -04:00
|
|
|
institutions = [
|
|
|
|
{ licence: 'free' }
|
2018-07-10 05:42:17 -04:00
|
|
|
]
|
2018-08-10 07:40:25 -04:00
|
|
|
@InstitutionsGetter.getConfirmedInstitutions.yields(null, institutions)
|
2018-07-10 05:42:17 -04:00
|
|
|
@InstitutionsFeatures.hasLicence @userId, (error, hasLicence) ->
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(hasLicence).to.be.false
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return true if user has confirmed paid affiliation', (done)->
|
2018-08-10 07:40:25 -04:00
|
|
|
institutions = [
|
|
|
|
{ licence: 'pro_plus' }
|
|
|
|
{ licence: 'free' }
|
|
|
|
{ licence: 'pro' }
|
|
|
|
{ licence: null }
|
2018-07-10 05:42:17 -04:00
|
|
|
]
|
2018-08-10 07:40:25 -04:00
|
|
|
@InstitutionsGetter.getConfirmedInstitutions.yields(null, institutions)
|
2018-07-10 05:42:17 -04:00
|
|
|
@InstitutionsFeatures.hasLicence @userId, (error, hasLicence) ->
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(hasLicence).to.be.true
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "getInstitutionsFeatures", ->
|
|
|
|
beforeEach ->
|
2018-09-24 08:16:31 -04:00
|
|
|
@InstitutionsFeatures.getInstitutionsPlan = sinon.stub()
|
2018-07-10 05:42:17 -04:00
|
|
|
@testFeatures = features: { institution: 'all' }
|
|
|
|
@PlansLocator.findLocalPlanInSettings.withArgs(@institutionPlanCode).returns(@testFeatures)
|
|
|
|
|
|
|
|
it 'should handle error', (done)->
|
2018-09-24 08:16:31 -04:00
|
|
|
@InstitutionsFeatures.getInstitutionsPlan.yields(new Error('Nope'))
|
2018-07-10 05:42:17 -04:00
|
|
|
@InstitutionsFeatures.getInstitutionsFeatures @userId, (error, features) ->
|
|
|
|
expect(error).to.exist
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return no feaures if user has no plan code', (done) ->
|
2018-09-24 08:16:31 -04:00
|
|
|
@InstitutionsFeatures.getInstitutionsPlan.yields(null, null)
|
2018-07-10 05:42:17 -04:00
|
|
|
@InstitutionsFeatures.getInstitutionsFeatures @userId, (error, features) ->
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(features).to.deep.equal {}
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return feaures if user has affiliations plan code', (done) ->
|
2018-09-24 08:16:31 -04:00
|
|
|
@InstitutionsFeatures.getInstitutionsPlan.yields(null, @institutionPlanCode)
|
2018-07-10 05:42:17 -04:00
|
|
|
@InstitutionsFeatures.getInstitutionsFeatures @userId, (error, features) =>
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(features).to.deep.equal @testFeatures.features
|
|
|
|
done()
|
2018-09-24 08:16:31 -04:00
|
|
|
|
|
|
|
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()
|