2019-05-29 05:21:06 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const { expect } = require('chai')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = '../../../../app/src/Features/Subscription/FeaturesUpdater'
|
2020-09-23 04:49:26 -04:00
|
|
|
const { ObjectId } = require('mongodb')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('FeaturesUpdater', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user_id = ObjectId().toString()
|
|
|
|
|
2021-03-04 09:22:43 -05:00
|
|
|
this.FeaturesUpdater = SandboxedModule.require(modulePath, {
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
|
|
|
'./UserFeaturesUpdater': (this.UserFeaturesUpdater = {}),
|
|
|
|
'./SubscriptionLocator': (this.SubscriptionLocator = {}),
|
|
|
|
'./PlansLocator': (this.PlansLocator = {}),
|
|
|
|
'settings-sharelatex': (this.Settings = {}),
|
|
|
|
'../Referal/ReferalFeatures': (this.ReferalFeatures = {}),
|
|
|
|
'./V1SubscriptionManager': (this.V1SubscriptionManager = {}),
|
2019-10-05 13:43:21 -04:00
|
|
|
'../Institutions/InstitutionsFeatures': (this.InstitutionsFeatures = {}),
|
2020-11-04 04:53:06 -05:00
|
|
|
'../User/UserGetter': (this.UserGetter = {}),
|
|
|
|
'../../infrastructure/Modules': (this.Modules = {
|
2021-04-27 03:52:58 -04:00
|
|
|
hooks: { fire: sinon.stub() },
|
|
|
|
}),
|
|
|
|
},
|
2021-03-04 09:22:43 -05:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('refreshFeatures', function () {
|
|
|
|
beforeEach(function () {
|
2020-11-04 04:53:06 -05:00
|
|
|
this.user = {
|
|
|
|
_id: this.user_id,
|
2021-04-27 03:52:58 -04:00
|
|
|
features: {},
|
2020-11-04 04:53:06 -05:00
|
|
|
}
|
2021-03-10 04:51:50 -05:00
|
|
|
this.UserFeaturesUpdater.updateFeatures = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { some: 'features' }, true)
|
2019-05-29 05:21:06 -04:00
|
|
|
this.FeaturesUpdater._getIndividualFeatures = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { individual: 'features' })
|
|
|
|
this.FeaturesUpdater._getGroupFeatureSets = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, [{ group: 'features' }, { group: 'features2' }])
|
|
|
|
this.InstitutionsFeatures.getInstitutionsFeatures = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { institutions: 'features' })
|
|
|
|
this.FeaturesUpdater._getV1Features = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { v1: 'features' })
|
|
|
|
this.ReferalFeatures.getBonusFeatures = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { bonus: 'features' })
|
|
|
|
this.FeaturesUpdater._mergeFeatures = sinon
|
|
|
|
.stub()
|
|
|
|
.returns({ merged: 'features' })
|
2020-11-04 04:53:06 -05:00
|
|
|
this.UserGetter.getUser = sinon.stub().yields(null, this.user)
|
2021-03-04 09:22:43 -05:00
|
|
|
this.callback = sinon.stub()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2021-03-10 04:51:50 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return features and featuresChanged', function () {
|
2021-03-10 04:51:50 -05:00
|
|
|
this.FeaturesUpdater.refreshFeatures(
|
|
|
|
this.user_id,
|
2021-05-11 10:08:37 -04:00
|
|
|
'test',
|
2021-03-10 04:51:50 -05:00
|
|
|
(err, features, featuresChanged) => {
|
|
|
|
expect(err).to.not.exist
|
|
|
|
expect(features).to.exist
|
|
|
|
expect(featuresChanged).to.exist
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('normally', function () {
|
|
|
|
beforeEach(function () {
|
2021-05-11 10:08:37 -04:00
|
|
|
this.FeaturesUpdater.refreshFeatures(
|
|
|
|
this.user_id,
|
|
|
|
'test',
|
|
|
|
this.callback
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should get the individual features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.FeaturesUpdater._getIndividualFeatures
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.user_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should get the group features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.FeaturesUpdater._getGroupFeatureSets
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.user_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should get the institution features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.InstitutionsFeatures.getInstitutionsFeatures
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.user_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should get the v1 features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.FeaturesUpdater._getV1Features
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.user_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should get the bonus features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.ReferalFeatures.getBonusFeatures
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.user_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should merge from the default features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.FeaturesUpdater._mergeFeatures
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.Settings.defaultFeatures)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should merge the individual features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.FeaturesUpdater._mergeFeatures
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(sinon.match.any, { individual: 'features' })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should merge the group features', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.FeaturesUpdater._mergeFeatures
|
|
|
|
.calledWith(sinon.match.any, { group: 'features' })
|
|
|
|
.should.equal(true)
|
2021-03-04 09:22:43 -05:00
|
|
|
this.FeaturesUpdater._mergeFeatures
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(sinon.match.any, { group: 'features2' })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should merge the institutions features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.FeaturesUpdater._mergeFeatures
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(sinon.match.any, { institutions: 'features' })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should merge the v1 features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.FeaturesUpdater._mergeFeatures
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(sinon.match.any, { v1: 'features' })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should merge the bonus features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.FeaturesUpdater._mergeFeatures
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(sinon.match.any, { bonus: 'features' })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should update the user with the merged features', function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.UserFeaturesUpdater.updateFeatures
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.user_id, { merged: 'features' })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when losing dropbox feature', function () {
|
|
|
|
beforeEach(function () {
|
2020-11-04 04:53:06 -05:00
|
|
|
this.user = {
|
|
|
|
_id: this.user_id,
|
2021-04-27 03:52:58 -04:00
|
|
|
features: { dropbox: true },
|
2020-11-04 04:53:06 -05:00
|
|
|
}
|
|
|
|
this.UserGetter.getUser = sinon.stub().yields(null, this.user)
|
|
|
|
this.FeaturesUpdater._mergeFeatures = sinon
|
|
|
|
.stub()
|
|
|
|
.returns({ dropbox: false })
|
2021-05-11 10:08:37 -04:00
|
|
|
this.FeaturesUpdater.refreshFeatures(
|
|
|
|
this.user_id,
|
|
|
|
'test',
|
|
|
|
this.callback
|
|
|
|
)
|
2020-11-04 04:53:06 -05:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should fire module hook to unlink dropbox', function () {
|
2020-11-04 04:53:06 -05:00
|
|
|
this.Modules.hooks.fire
|
|
|
|
.calledWith('removeDropbox', this.user._id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('_mergeFeatures', function () {
|
|
|
|
it('should prefer priority over standard for compileGroup', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(
|
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'priority',
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'standard',
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'priority',
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
expect(
|
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'standard',
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'priority',
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'priority',
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
expect(
|
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'priority',
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'priority',
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'priority',
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2021-03-04 09:22:43 -05:00
|
|
|
expect(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'standard',
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'standard',
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
compileGroup: 'standard',
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should prefer -1 over any other for collaborators', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(
|
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: -1,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: 10,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: -1,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
expect(
|
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: 10,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: -1,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: -1,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2021-03-04 09:22:43 -05:00
|
|
|
expect(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: 4,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: 10,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: 10,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should prefer the higher of compileTimeout', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(
|
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileTimeout: 20,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileTimeout: 10,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
compileTimeout: 20,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2021-03-04 09:22:43 -05:00
|
|
|
expect(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileTimeout: 10,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
compileTimeout: 20,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
compileTimeout: 20,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should prefer the true over false for other keys', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(
|
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
github: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
github: false,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
github: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
expect(
|
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
github: false,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
github: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
github: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
expect(
|
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
github: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
github: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
github: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2021-03-04 09:22:43 -05:00
|
|
|
expect(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.FeaturesUpdater._mergeFeatures(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
github: false,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
github: false,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).to.deep.equal({
|
2021-04-27 03:52:58 -04:00
|
|
|
github: false,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-02-03 09:12:34 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('doSyncFromV1', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-03 09:12:34 -05:00
|
|
|
this.v1UserId = 1
|
|
|
|
this.user = {
|
|
|
|
_id: this.user_id,
|
|
|
|
email: 'user@example.com',
|
|
|
|
overleaf: {
|
2021-04-27 03:52:58 -04:00
|
|
|
id: this.v1UserId,
|
|
|
|
},
|
2020-02-03 09:12:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, this.user)
|
|
|
|
this.FeaturesUpdater.refreshFeatures = sinon.stub().yields(null)
|
2021-03-04 09:22:43 -05:00
|
|
|
this.call = cb => {
|
|
|
|
this.FeaturesUpdater.doSyncFromV1(this.v1UserId, cb)
|
|
|
|
}
|
2020-02-03 09:12:34 -05:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when all goes well', function () {
|
|
|
|
it('should call getUser', function (done) {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.call(() => {
|
2020-02-03 09:12:34 -05:00
|
|
|
expect(this.UserGetter.getUser.callCount).to.equal(1)
|
|
|
|
expect(
|
|
|
|
this.UserGetter.getUser.calledWith({ 'overleaf.id': this.v1UserId })
|
|
|
|
).to.equal(true)
|
2021-03-04 09:22:43 -05:00
|
|
|
done()
|
2020-02-03 09:12:34 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should call refreshFeatures', function (done) {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.call(() => {
|
2020-02-03 09:12:34 -05:00
|
|
|
expect(this.FeaturesUpdater.refreshFeatures.callCount).to.equal(1)
|
|
|
|
expect(
|
|
|
|
this.FeaturesUpdater.refreshFeatures.calledWith(this.user_id)
|
|
|
|
).to.equal(true)
|
2021-03-04 09:22:43 -05:00
|
|
|
done()
|
2020-02-03 09:12:34 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not produce an error', function (done) {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.call(err => {
|
2020-02-03 09:12:34 -05:00
|
|
|
expect(err).to.not.exist
|
2021-03-04 09:22:43 -05:00
|
|
|
done()
|
2020-02-03 09:12:34 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when getUser produces an error', function () {
|
|
|
|
beforeEach(function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.UserGetter.getUser = sinon
|
2020-02-03 09:12:34 -05:00
|
|
|
.stub()
|
2021-03-04 09:22:43 -05:00
|
|
|
.callsArgWith(2, new Error('woops'))
|
2020-02-03 09:12:34 -05:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not call refreshFeatures', function () {
|
2020-02-03 09:12:34 -05:00
|
|
|
expect(this.FeaturesUpdater.refreshFeatures.callCount).to.equal(0)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should produce an error', function (done) {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.call(err => {
|
2020-02-03 09:12:34 -05:00
|
|
|
expect(err).to.exist
|
2021-03-04 09:22:43 -05:00
|
|
|
done()
|
2020-02-03 09:12:34 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when getUser does not find a user', function () {
|
|
|
|
beforeEach(function () {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, null)
|
2020-02-03 09:12:34 -05:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not call refreshFeatures', function (done) {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.call(() => {
|
2020-02-03 09:12:34 -05:00
|
|
|
expect(this.FeaturesUpdater.refreshFeatures.callCount).to.equal(0)
|
2021-03-04 09:22:43 -05:00
|
|
|
done()
|
2020-02-03 09:12:34 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not produce an error', function (done) {
|
2021-03-04 09:22:43 -05:00
|
|
|
this.call(err => {
|
2020-02-03 09:12:34 -05:00
|
|
|
expect(err).to.not.exist
|
2021-03-04 09:22:43 -05:00
|
|
|
done()
|
2020-02-03 09:12:34 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|