mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #4102 from overleaf/jpa-fix-pdf-caching-feature-flags
[ProjectController] fix pdf caching feature flags and add tests GitOrigin-RevId: bab312f20dd98414aab92931dd6a1ec85e4bafd2
This commit is contained in:
parent
687d87b2dd
commit
52961250aa
2 changed files with 133 additions and 5 deletions
|
@ -890,7 +890,7 @@ const ProjectController = {
|
|||
}
|
||||
|
||||
Promise.all([
|
||||
async () => {
|
||||
(async () => {
|
||||
if (Settings.enablePdfCaching) {
|
||||
if (user.alphaProgram) {
|
||||
trackPdfDownload = true
|
||||
|
@ -904,8 +904,8 @@ const ProjectController = {
|
|||
testSegmentation.variant === 'enabled'
|
||||
}
|
||||
}
|
||||
},
|
||||
async () => {
|
||||
})(),
|
||||
(async () => {
|
||||
if (Settings.enablePdfCaching) {
|
||||
if (user.alphaProgram) {
|
||||
enablePdfCaching = shouldDisplayFeature(
|
||||
|
@ -917,14 +917,19 @@ const ProjectController = {
|
|||
userId,
|
||||
'enable_pdf_caching'
|
||||
)
|
||||
trackPdfDownload = shouldDisplayFeature(
|
||||
enablePdfCaching = shouldDisplayFeature(
|
||||
'enable_pdf_caching',
|
||||
testSegmentation.enabled &&
|
||||
testSegmentation.variant === 'enabled'
|
||||
)
|
||||
} else {
|
||||
enablePdfCaching = shouldDisplayFeature(
|
||||
'enable_pdf_caching',
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
})(),
|
||||
])
|
||||
.then(() => {
|
||||
render()
|
||||
|
|
|
@ -125,6 +125,9 @@ describe('ProjectController', function () {
|
|||
.returns({ newLogsUI: false, subvariant: null }),
|
||||
}
|
||||
this.SplitTestHandler = {
|
||||
promises: {
|
||||
getTestSegmentation: sinon.stub().resolves({ enabled: false }),
|
||||
},
|
||||
getTestSegmentation: sinon.stub().returns({ enabled: false }),
|
||||
}
|
||||
|
||||
|
@ -172,6 +175,7 @@ describe('ProjectController', function () {
|
|||
|
||||
this.projectName = '£12321jkj9ujkljds'
|
||||
this.req = {
|
||||
query: {},
|
||||
params: {
|
||||
Project_id: this.project_id,
|
||||
},
|
||||
|
@ -1071,6 +1075,125 @@ describe('ProjectController', function () {
|
|||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
describe('pdf caching feature flags', function () {
|
||||
function expectBandwidthTrackingEnabled() {
|
||||
it('should track pdf bandwidth', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.trackPdfDownload).to.equal(true)
|
||||
done()
|
||||
}
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
}
|
||||
function expectPDFCachingEnabled() {
|
||||
it('should enable pdf caching', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.enablePdfCaching).to.equal(true)
|
||||
done()
|
||||
}
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
}
|
||||
function expectBandwidthTrackingDisabled() {
|
||||
it('should not track pdf bandwidth', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.trackPdfDownload).to.equal(false)
|
||||
done()
|
||||
}
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
}
|
||||
function expectPDFCachingDisabled() {
|
||||
it('should disable pdf caching', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.enablePdfCaching).to.equal(false)
|
||||
done()
|
||||
}
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
this.settings.enablePdfCaching = true
|
||||
})
|
||||
|
||||
describe('regular user', function () {
|
||||
describe('with no query', function () {
|
||||
expectBandwidthTrackingDisabled()
|
||||
expectPDFCachingDisabled()
|
||||
})
|
||||
|
||||
describe('with enable_pdf_caching=false', function () {
|
||||
beforeEach(function () {
|
||||
this.req.query.enable_pdf_caching = 'false'
|
||||
})
|
||||
expectBandwidthTrackingDisabled()
|
||||
expectPDFCachingDisabled()
|
||||
})
|
||||
|
||||
describe('with enable_pdf_caching=true', function () {
|
||||
beforeEach(function () {
|
||||
this.req.query.enable_pdf_caching = 'true'
|
||||
})
|
||||
expectBandwidthTrackingDisabled()
|
||||
expectPDFCachingEnabled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('alpha user', function () {
|
||||
beforeEach(function () {
|
||||
this.user.alphaProgram = true
|
||||
})
|
||||
describe('with no query', function () {
|
||||
expectBandwidthTrackingEnabled()
|
||||
expectPDFCachingEnabled()
|
||||
})
|
||||
|
||||
describe('with enable_pdf_caching=false', function () {
|
||||
beforeEach(function () {
|
||||
this.req.query.enable_pdf_caching = 'false'
|
||||
})
|
||||
expectBandwidthTrackingEnabled()
|
||||
expectPDFCachingDisabled()
|
||||
})
|
||||
|
||||
describe('with enable_pdf_caching=true', function () {
|
||||
beforeEach(function () {
|
||||
this.req.query.enable_pdf_caching = 'true'
|
||||
})
|
||||
expectBandwidthTrackingEnabled()
|
||||
expectPDFCachingEnabled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('beta user', function () {
|
||||
beforeEach(function () {
|
||||
this.user.betaProgram = true
|
||||
})
|
||||
|
||||
describe('with no query', function () {
|
||||
expectBandwidthTrackingDisabled()
|
||||
expectPDFCachingDisabled()
|
||||
})
|
||||
|
||||
describe('with enable_pdf_caching=false', function () {
|
||||
beforeEach(function () {
|
||||
this.req.query.enable_pdf_caching = 'false'
|
||||
})
|
||||
expectBandwidthTrackingDisabled()
|
||||
expectPDFCachingDisabled()
|
||||
})
|
||||
|
||||
describe('with enable_pdf_caching=true', function () {
|
||||
beforeEach(function () {
|
||||
this.req.query.enable_pdf_caching = 'true'
|
||||
})
|
||||
expectBandwidthTrackingDisabled()
|
||||
expectPDFCachingEnabled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('wsUrl', function () {
|
||||
function checkLoadEditorWsMetric(metric) {
|
||||
it(`should inc metric ${metric}`, function (done) {
|
||||
|
|
Loading…
Reference in a new issue