mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 18:20:09 +02:00
Remove user projections in BetaProgramHandler GitOrigin-RevId: 88b7bc3b6f11ae9f8314543ee538c84d25cde7cd
113 lines
2.7 KiB
JavaScript
113 lines
2.7 KiB
JavaScript
const SandboxedModule = require('sandboxed-module')
|
|
const path = require('path')
|
|
const modulePath = path.join(
|
|
__dirname,
|
|
'../../../../app/src/Features/BetaProgram/BetaProgramHandler'
|
|
)
|
|
const sinon = require('sinon')
|
|
const { expect } = require('chai')
|
|
|
|
describe('BetaProgramHandler', function() {
|
|
beforeEach(function() {
|
|
this.user_id = 'some_id'
|
|
this.user = {
|
|
_id: this.user_id,
|
|
email: 'user@example.com',
|
|
features: {},
|
|
betaProgram: false,
|
|
save: sinon.stub().callsArgWith(0, null)
|
|
}
|
|
this.handler = SandboxedModule.require(modulePath, {
|
|
globals: {
|
|
console: console
|
|
},
|
|
requires: {
|
|
'metrics-sharelatex': (this.logger = {
|
|
inc: sinon.stub()
|
|
}),
|
|
'../User/UserUpdater': (this.UserUpdater = {
|
|
promises: {
|
|
updateUser: sinon.stub().resolves()
|
|
}
|
|
})
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('optIn', function() {
|
|
beforeEach(function() {
|
|
this.user.betaProgram = false
|
|
this.call = callback => {
|
|
this.handler.optIn(this.user_id, callback)
|
|
}
|
|
})
|
|
|
|
it('should call userUpdater', function(done) {
|
|
this.call(err => {
|
|
expect(err).to.not.exist
|
|
this.UserUpdater.promises.updateUser.callCount.should.equal(1)
|
|
done()
|
|
})
|
|
})
|
|
|
|
it('should not produce an error', function(done) {
|
|
this.call(err => {
|
|
expect(err).to.not.exist
|
|
done()
|
|
})
|
|
})
|
|
|
|
describe('when userUpdater produces an error', function() {
|
|
beforeEach(function() {
|
|
this.UserUpdater.promises.updateUser.rejects()
|
|
})
|
|
|
|
it('should produce an error', function(done) {
|
|
this.call(err => {
|
|
expect(err).to.exist
|
|
expect(err).to.be.instanceof(Error)
|
|
done()
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('optOut', function() {
|
|
beforeEach(function() {
|
|
this.user.betaProgram = true
|
|
this.call = callback => {
|
|
this.handler.optOut(this.user_id, callback)
|
|
}
|
|
})
|
|
|
|
it('should call userUpdater', function(done) {
|
|
this.call(err => {
|
|
expect(err).to.not.exist
|
|
this.UserUpdater.promises.updateUser.callCount.should.equal(1)
|
|
done()
|
|
})
|
|
})
|
|
|
|
it('should not produce an error', function(done) {
|
|
this.call(err => {
|
|
expect(err).to.not.exist
|
|
done()
|
|
})
|
|
})
|
|
|
|
describe('when userUpdater produces an error', function() {
|
|
beforeEach(function() {
|
|
this.UserUpdater.promises.updateUser.rejects()
|
|
})
|
|
|
|
it('should produce an error', function(done) {
|
|
this.call(err => {
|
|
expect(err).to.exist
|
|
expect(err).to.be.instanceof(Error)
|
|
done()
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|