2019-05-29 05:21:06 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
2021-05-18 09:41:10 -04:00
|
|
|
const { expect } = require('chai')
|
2019-05-29 05:21:06 -04:00
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath =
|
|
|
|
'../../../../app/src/Features/Subscription/UserFeaturesUpdater'
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('UserFeaturesUpdater', function () {
|
|
|
|
beforeEach(function () {
|
2021-08-16 09:08:03 -04:00
|
|
|
this.features = {
|
|
|
|
collaborators: 6,
|
|
|
|
dropbox: true,
|
|
|
|
github: true,
|
|
|
|
gitBridge: true,
|
|
|
|
versioning: true,
|
|
|
|
compileTimeout: 180,
|
|
|
|
compileGroup: 'priority',
|
|
|
|
references: true,
|
|
|
|
templates: true,
|
|
|
|
trackChanges: true,
|
|
|
|
referencesSearch: true,
|
|
|
|
zotero: true,
|
|
|
|
mendeley: true,
|
|
|
|
}
|
|
|
|
this.User = {
|
|
|
|
findByIdAndUpdate: sinon.stub().yields(null, { features: this.features }),
|
|
|
|
}
|
2021-05-18 09:41:10 -04:00
|
|
|
this.UserFeaturesUpdater = SandboxedModule.require(modulePath, {
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
|
|
|
'../../models/User': {
|
2021-04-27 03:52:58 -04:00
|
|
|
User: this.User,
|
|
|
|
},
|
|
|
|
},
|
2021-05-18 09:41:10 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('updateFeatures', function () {
|
|
|
|
it('should send the users features', function (done) {
|
2021-05-18 09:41:10 -04:00
|
|
|
const userId = '5208dd34438842e2db000005'
|
2021-08-16 09:08:03 -04:00
|
|
|
const update = {
|
|
|
|
versioning: true,
|
|
|
|
collaborators: 10,
|
|
|
|
}
|
2021-05-18 09:41:10 -04:00
|
|
|
this.UserFeaturesUpdater.updateFeatures(
|
|
|
|
userId,
|
2021-08-16 09:08:03 -04:00
|
|
|
update,
|
2021-05-18 09:41:10 -04:00
|
|
|
(err, features) => {
|
2021-08-16 09:08:03 -04:00
|
|
|
const updateArgs = this.User.findByIdAndUpdate.lastCall.args
|
|
|
|
expect(updateArgs[0]).to.deep.equal(userId)
|
2021-05-18 09:41:10 -04:00
|
|
|
expect(Object.keys(updateArgs[1]).length).to.equal(3)
|
|
|
|
expect(updateArgs[1]['features.versioning']).to.equal(
|
2021-08-16 09:08:03 -04:00
|
|
|
update.versioning
|
2021-05-18 09:41:10 -04:00
|
|
|
)
|
|
|
|
expect(updateArgs[1]['features.collaborators']).to.equal(
|
2021-08-16 09:08:03 -04:00
|
|
|
update.collaborators
|
2021-05-18 09:41:10 -04:00
|
|
|
)
|
|
|
|
expect(updateArgs[1].featuresUpdatedAt instanceof Date).to.be.true
|
2021-08-16 09:08:03 -04:00
|
|
|
features.should.deep.equal(update)
|
2021-05-18 09:41:10 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('overrideFeatures', function () {
|
|
|
|
it('should send the users features', function (done) {
|
|
|
|
const userId = '5208dd34438842e2db000005'
|
2021-08-16 09:08:03 -04:00
|
|
|
const update = Object.assign({}, { mendeley: !this.features.mendeley })
|
|
|
|
this.UserFeaturesUpdater.overrideFeatures(
|
2021-05-18 09:41:10 -04:00
|
|
|
userId,
|
2021-08-16 09:08:03 -04:00
|
|
|
update,
|
|
|
|
(err, featuresChanged) => {
|
|
|
|
const updateArgs = this.User.findByIdAndUpdate.lastCall.args
|
|
|
|
expect(updateArgs[0]).to.equal(userId)
|
|
|
|
expect(Object.keys(updateArgs[1]).length).to.equal(2)
|
|
|
|
expect(updateArgs[1].features).to.deep.equal(update)
|
2021-05-18 09:41:10 -04:00
|
|
|
expect(updateArgs[1].featuresUpdatedAt instanceof Date).to.be.true
|
2021-08-16 09:08:03 -04:00
|
|
|
featuresChanged.should.equal(true)
|
2021-05-18 09:41:10 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
2019-08-07 10:04:04 -04:00
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|