Merge pull request #2713 from overleaf/jpa-custom-wsurl-for-beta-users

[misc] custom wsUrl for beta users

GitOrigin-RevId: e731ae7245e9c5586ae82cbc4c6716a74e56f2c9
This commit is contained in:
Jakob Ackermann
2020-04-02 12:01:41 +02:00
committed by Copybot
parent 50d715ea5d
commit 155b22caf9
9 changed files with 109 additions and 15 deletions
@@ -129,6 +129,12 @@ describe('ProjectController', function() {
}
}
])
this.Metrics = {
Timer: class {
done() {}
},
inc: sinon.stub()
}
this.ProjectController = SandboxedModule.require(MODULE_PATH, {
globals: {
@@ -140,12 +146,7 @@ describe('ProjectController', function() {
log() {},
err() {}
},
'metrics-sharelatex': {
Timer: class {
done() {}
},
inc() {}
},
'metrics-sharelatex': this.Metrics,
'@overleaf/o-error/http': HttpErrors,
'./ProjectDeleter': this.ProjectDeleter,
'./ProjectDuplicator': this.ProjectDuplicator,
@@ -1145,6 +1146,81 @@ describe('ProjectController', function() {
}
this.ProjectController.loadEditor(this.req, this.res)
})
describe('wsUrl', function() {
function checkLoadEditorWsMetric(metric) {
it(`should inc metric ${metric}`, function(done) {
this.res.render = () => {
this.Metrics.inc.calledWith(metric).should.equal(true)
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
}
function checkWsFallback(isBeta) {
describe('with ws=fallback', function() {
beforeEach(function() {
this.req.query = {}
this.req.query.ws = 'fallback'
})
it('should unset the wsUrl', function(done) {
this.res.render = (pageName, opts) => {
;(opts.wsUrl || '/socket.io').should.equal('/socket.io')
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
checkLoadEditorWsMetric(
`load-editor-ws${isBeta ? '-beta' : ''}-fallback`
)
})
}
beforeEach(function() {
this.settings.wsUrl = '/other.socket.io'
})
it('should set the custom wsUrl', function(done) {
this.res.render = (pageName, opts) => {
opts.wsUrl.should.equal('/other.socket.io')
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
checkLoadEditorWsMetric('load-editor-ws')
checkWsFallback(false)
describe('beta program', function() {
beforeEach(function() {
this.settings.wsUrlBeta = '/beta.socket.io'
})
describe('for a normal user', function() {
it('should set the normal custom wsUrl', function(done) {
this.res.render = (pageName, opts) => {
opts.wsUrl.should.equal('/other.socket.io')
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
checkLoadEditorWsMetric('load-editor-ws')
checkWsFallback(false)
})
describe('for a beta user', function() {
beforeEach(function() {
this.user.betaProgram = true
})
it('should set the beta wsUrl', function(done) {
this.res.render = (pageName, opts) => {
opts.wsUrl.should.equal('/beta.socket.io')
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
checkLoadEditorWsMetric('load-editor-ws-beta')
checkWsFallback(true)
})
})
})
})
describe('userProjectsJson', function() {