Merge pull request #8730 from overleaf/jpa-refactor-pdf-caching

[web] refactor pdf caching

GitOrigin-RevId: af6b871fad652f757d8c465085b33a79b955cd6b
This commit is contained in:
Jakob Ackermann
2022-07-06 12:06:53 +01:00
committed by Copybot
parent a447bd6aa8
commit cfa4df0c77
18 changed files with 683 additions and 534 deletions
@@ -2,6 +2,7 @@ const sinon = require('sinon')
const { expect } = require('chai')
const modulePath = '../../../../app/src/Features/Compile/ClsiManager.js'
const SandboxedModule = require('sandboxed-module')
const tk = require('timekeeper')
describe('ClsiManager', function () {
beforeEach(function () {
@@ -72,6 +73,11 @@ describe('ClsiManager', function () {
this.project_id = 'project-id'
this.user_id = 'user-id'
this.callback = sinon.stub()
tk.freeze(Date.now())
})
after(function () {
tk.reset()
})
describe('sendRequest', function () {
@@ -136,9 +142,10 @@ describe('ClsiManager', function () {
path: 'output.pdf',
type: 'pdf',
build: 1234,
ranges: [],
createdAt: new Date(),
// gets dropped by JSON.stringify
contentId: undefined,
ranges: undefined,
size: undefined,
},
{
@@ -146,10 +153,6 @@ describe('ClsiManager', function () {
path: 'output.log',
type: 'log',
build: 1234,
// gets dropped by JSON.stringify
contentId: undefined,
ranges: undefined,
size: undefined,
},
]
this.callback
@@ -207,16 +210,13 @@ describe('ClsiManager', function () {
contentId: '123-321',
ranges: [{ start: 1, end: 42, hash: 'foo' }],
size: 42,
createdAt: new Date(),
},
{
url: `/project/${this.project_id}/user/${this.user_id}/build/1234/output/output.log`,
path: 'output.log',
type: 'log',
build: 1234,
// gets dropped by JSON.stringify
contentId: undefined,
ranges: undefined,
size: undefined,
},
]
const validationError = undefined
@@ -417,9 +417,10 @@ describe('ClsiManager', function () {
path: 'output.pdf',
type: 'pdf',
build: 1234,
ranges: [],
createdAt: new Date(),
// gets dropped by JSON.stringify
contentId: undefined,
ranges: undefined,
size: undefined,
},
{
@@ -427,15 +428,13 @@ describe('ClsiManager', function () {
path: 'output.log',
type: 'log',
build: 1234,
// gets dropped by JSON.stringify
contentId: undefined,
ranges: undefined,
size: undefined,
},
]
this.callback
.calledWith(null, this.status, outputFiles)
.should.equal(true)
this.callback.should.have.been.calledWith(
null,
this.status,
outputFiles
)
})
})
@@ -1136,10 +1136,10 @@ describe('ProjectController', function () {
this.ProjectController.loadEditor(this.req, this.res)
})
}
function expectPDFCachingEnabled() {
function expectPDFCachingEnabled(mode) {
it('should enable pdf caching', function (done) {
this.res.render = (pageName, opts) => {
expect(opts.enablePdfCaching).to.equal(true)
expect(opts.pdfCachingMode).to.equal(mode)
done()
}
this.ProjectController.loadEditor(this.req, this.res)
@@ -1157,7 +1157,7 @@ describe('ProjectController', function () {
function expectPDFCachingDisabled() {
it('should disable pdf caching', function (done) {
this.res.render = (pageName, opts) => {
expect(opts.enablePdfCaching).to.equal(false)
expect(opts.pdfCachingMode).to.equal('')
done()
}
this.ProjectController.loadEditor(this.req, this.res)
@@ -1174,20 +1174,32 @@ describe('ProjectController', function () {
expectPDFCachingDisabled()
})
describe('with enable_pdf_caching=false', function () {
describe('with track-pdf-download=false', function () {
beforeEach(function () {
this.req.query.enable_pdf_caching = 'false'
this.req.query['track-pdf-download'] = 'false'
})
expectBandwidthTrackingDisabled()
expectPDFCachingDisabled()
})
describe('with enable_pdf_caching=true', function () {
describe('with track-pdf-download=true', function () {
beforeEach(function () {
this.req.query.enable_pdf_caching = 'true'
this.req.query['track-pdf-download'] = 'true'
})
expectBandwidthTrackingEnabled()
expectPDFCachingEnabled()
})
describe('with pdf-caching-mode=no-service-worker', function () {
beforeEach(function () {
this.req.query['pdf-caching-mode'] = 'no-service-worker'
})
expectPDFCachingEnabled('no-service-worker')
})
describe('with pdf-caching-mode=service-worker', function () {
beforeEach(function () {
this.req.query['pdf-caching-mode'] = 'service-worker'
})
expectPDFCachingEnabled('service-worker')
})
})
})