2020-02-19 06:16:07 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-path-concat,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-19 06:16:00 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-19 06:16:14 -05:00
|
|
|
const Client = require('./helpers/Client')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const ClsiApp = require('./helpers/ClsiApp')
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:14 -05:00
|
|
|
const host = 'localhost'
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:00 -05:00
|
|
|
const Server = {
|
2020-02-19 06:16:14 -05:00
|
|
|
run() {
|
|
|
|
const express = require('express')
|
|
|
|
const app = express()
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:14 -05:00
|
|
|
const staticServer = express.static(__dirname + '/../fixtures/')
|
|
|
|
app.get('/:random_id/*', (req, res, next) => {
|
|
|
|
this.getFile(req.url)
|
|
|
|
req.url = `/${req.params[0]}`
|
|
|
|
return staticServer(req, res, next)
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:14 -05:00
|
|
|
return app.listen(31415, host)
|
|
|
|
},
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:14 -05:00
|
|
|
getFile() {},
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:14 -05:00
|
|
|
randomId() {
|
2020-08-10 12:01:11 -04:00
|
|
|
return Math.random().toString(16).slice(2)
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-02-19 06:16:14 -05:00
|
|
|
}
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:14 -05:00
|
|
|
Server.run()
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('Url Caching', function () {
|
|
|
|
describe('Downloading an image for the first time', function () {
|
|
|
|
before(function (done) {
|
2020-02-19 06:16:14 -05:00
|
|
|
this.project_id = Client.randomId()
|
|
|
|
this.file = `${Server.randomId()}/lion.png`
|
|
|
|
this.request = {
|
|
|
|
resources: [
|
|
|
|
{
|
|
|
|
path: 'main.tex',
|
|
|
|
content: `\
|
2020-02-19 06:16:00 -05:00
|
|
|
\\documentclass{article}
|
|
|
|
\\usepackage{graphicx}
|
|
|
|
\\begin{document}
|
|
|
|
\\includegraphics{lion.png}
|
|
|
|
\\end{document}\
|
2021-07-13 07:04:48 -04:00
|
|
|
`,
|
2020-02-19 06:16:14 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'lion.png',
|
2021-07-13 07:04:48 -04:00
|
|
|
url: `http://${host}:31415/${this.file}`,
|
|
|
|
},
|
|
|
|
],
|
2020-02-19 06:16:14 -05:00
|
|
|
}
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:14 -05:00
|
|
|
sinon.spy(Server, 'getFile')
|
|
|
|
return ClsiApp.ensureRunning(() => {
|
|
|
|
return Client.compile(
|
|
|
|
this.project_id,
|
|
|
|
this.request,
|
|
|
|
(error, res, body) => {
|
|
|
|
this.error = error
|
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
afterEach(function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.restore()
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should download the image', function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.calledWith(`/${this.file}`).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('When an image is in the cache and the last modified date is unchanged', function () {
|
|
|
|
before(function (done) {
|
2020-02-19 06:16:14 -05:00
|
|
|
this.project_id = Client.randomId()
|
|
|
|
this.file = `${Server.randomId()}/lion.png`
|
|
|
|
this.request = {
|
|
|
|
resources: [
|
|
|
|
{
|
|
|
|
path: 'main.tex',
|
|
|
|
content: `\
|
2020-02-19 06:16:00 -05:00
|
|
|
\\documentclass{article}
|
|
|
|
\\usepackage{graphicx}
|
|
|
|
\\begin{document}
|
|
|
|
\\includegraphics{lion.png}
|
|
|
|
\\end{document}\
|
2021-07-13 07:04:48 -04:00
|
|
|
`,
|
2020-02-19 06:16:14 -05:00
|
|
|
},
|
|
|
|
(this.image_resource = {
|
|
|
|
path: 'lion.png',
|
|
|
|
url: `http://${host}:31415/${this.file}`,
|
2021-07-13 07:04:48 -04:00
|
|
|
modified: Date.now(),
|
|
|
|
}),
|
|
|
|
],
|
2020-02-19 06:16:14 -05:00
|
|
|
}
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:14 -05:00
|
|
|
return Client.compile(
|
|
|
|
this.project_id,
|
|
|
|
this.request,
|
|
|
|
(error, res, body) => {
|
|
|
|
this.error = error
|
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
sinon.spy(Server, 'getFile')
|
|
|
|
return Client.compile(
|
|
|
|
this.project_id,
|
|
|
|
this.request,
|
|
|
|
(error1, res1, body1) => {
|
|
|
|
this.error = error1
|
|
|
|
this.res = res1
|
|
|
|
this.body = body1
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
after(function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.restore()
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should not download the image again', function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.called.should.equal(false)
|
|
|
|
})
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('When an image is in the cache and the last modified date is advanced', function () {
|
|
|
|
before(function (done) {
|
2020-02-19 06:16:14 -05:00
|
|
|
this.project_id = Client.randomId()
|
|
|
|
this.file = `${Server.randomId()}/lion.png`
|
|
|
|
this.request = {
|
|
|
|
resources: [
|
|
|
|
{
|
|
|
|
path: 'main.tex',
|
|
|
|
content: `\
|
2020-02-19 06:16:00 -05:00
|
|
|
\\documentclass{article}
|
|
|
|
\\usepackage{graphicx}
|
|
|
|
\\begin{document}
|
|
|
|
\\includegraphics{lion.png}
|
|
|
|
\\end{document}\
|
2021-07-13 07:04:48 -04:00
|
|
|
`,
|
2020-02-19 06:16:14 -05:00
|
|
|
},
|
|
|
|
(this.image_resource = {
|
|
|
|
path: 'lion.png',
|
|
|
|
url: `http://${host}:31415/${this.file}`,
|
2021-07-13 07:04:48 -04:00
|
|
|
modified: (this.last_modified = Date.now()),
|
|
|
|
}),
|
|
|
|
],
|
2020-02-19 06:16:14 -05:00
|
|
|
}
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:14 -05:00
|
|
|
return Client.compile(
|
|
|
|
this.project_id,
|
|
|
|
this.request,
|
|
|
|
(error, res, body) => {
|
|
|
|
this.error = error
|
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
sinon.spy(Server, 'getFile')
|
|
|
|
this.image_resource.modified = new Date(this.last_modified + 3000)
|
|
|
|
return Client.compile(
|
|
|
|
this.project_id,
|
|
|
|
this.request,
|
|
|
|
(error1, res1, body1) => {
|
|
|
|
this.error = error1
|
|
|
|
this.res = res1
|
|
|
|
this.body = body1
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
afterEach(function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.restore()
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should download the image again', function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.called.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('When an image is in the cache and the last modified date is further in the past', function () {
|
|
|
|
before(function (done) {
|
2020-02-19 06:16:14 -05:00
|
|
|
this.project_id = Client.randomId()
|
|
|
|
this.file = `${Server.randomId()}/lion.png`
|
|
|
|
this.request = {
|
|
|
|
resources: [
|
|
|
|
{
|
|
|
|
path: 'main.tex',
|
|
|
|
content: `\
|
2020-02-19 06:16:00 -05:00
|
|
|
\\documentclass{article}
|
|
|
|
\\usepackage{graphicx}
|
|
|
|
\\begin{document}
|
|
|
|
\\includegraphics{lion.png}
|
|
|
|
\\end{document}\
|
2021-07-13 07:04:48 -04:00
|
|
|
`,
|
2020-02-19 06:16:14 -05:00
|
|
|
},
|
|
|
|
(this.image_resource = {
|
|
|
|
path: 'lion.png',
|
|
|
|
url: `http://${host}:31415/${this.file}`,
|
2021-07-13 07:04:48 -04:00
|
|
|
modified: (this.last_modified = Date.now()),
|
|
|
|
}),
|
|
|
|
],
|
2020-02-19 06:16:14 -05:00
|
|
|
}
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-02-19 06:16:14 -05:00
|
|
|
return Client.compile(
|
|
|
|
this.project_id,
|
|
|
|
this.request,
|
|
|
|
(error, res, body) => {
|
|
|
|
this.error = error
|
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
sinon.spy(Server, 'getFile')
|
|
|
|
this.image_resource.modified = new Date(this.last_modified - 3000)
|
|
|
|
return Client.compile(
|
|
|
|
this.project_id,
|
|
|
|
this.request,
|
|
|
|
(error1, res1, body1) => {
|
|
|
|
this.error = error1
|
|
|
|
this.res = res1
|
|
|
|
this.body = body1
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
afterEach(function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.restore()
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should not download the image again', function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.called.should.equal(false)
|
|
|
|
})
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('When an image is in the cache and the last modified date is not specified', function () {
|
|
|
|
before(function (done) {
|
2020-02-19 06:16:14 -05:00
|
|
|
this.project_id = Client.randomId()
|
|
|
|
this.file = `${Server.randomId()}/lion.png`
|
|
|
|
this.request = {
|
|
|
|
resources: [
|
|
|
|
{
|
|
|
|
path: 'main.tex',
|
|
|
|
content: `\
|
2020-02-19 06:16:00 -05:00
|
|
|
\\documentclass{article}
|
|
|
|
\\usepackage{graphicx}
|
|
|
|
\\begin{document}
|
|
|
|
\\includegraphics{lion.png}
|
|
|
|
\\end{document}\
|
2021-07-13 07:04:48 -04:00
|
|
|
`,
|
2020-02-19 06:16:14 -05:00
|
|
|
},
|
|
|
|
(this.image_resource = {
|
|
|
|
path: 'lion.png',
|
|
|
|
url: `http://${host}:31415/${this.file}`,
|
2021-07-13 07:04:48 -04:00
|
|
|
modified: (this.last_modified = Date.now()),
|
|
|
|
}),
|
|
|
|
],
|
2020-02-19 06:16:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return Client.compile(
|
|
|
|
this.project_id,
|
|
|
|
this.request,
|
|
|
|
(error, res, body) => {
|
|
|
|
this.error = error
|
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
sinon.spy(Server, 'getFile')
|
|
|
|
delete this.image_resource.modified
|
|
|
|
return Client.compile(
|
|
|
|
this.project_id,
|
|
|
|
this.request,
|
|
|
|
(error1, res1, body1) => {
|
|
|
|
this.error = error1
|
|
|
|
this.res = res1
|
|
|
|
this.body = body1
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
afterEach(function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.restore()
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should download the image again', function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.called.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe('After clearing the cache', function () {
|
|
|
|
before(function (done) {
|
2020-02-19 06:16:14 -05:00
|
|
|
this.project_id = Client.randomId()
|
|
|
|
this.file = `${Server.randomId()}/lion.png`
|
|
|
|
this.request = {
|
|
|
|
resources: [
|
|
|
|
{
|
|
|
|
path: 'main.tex',
|
|
|
|
content: `\
|
2020-02-19 06:16:00 -05:00
|
|
|
\\documentclass{article}
|
|
|
|
\\usepackage{graphicx}
|
|
|
|
\\begin{document}
|
|
|
|
\\includegraphics{lion.png}
|
|
|
|
\\end{document}\
|
2021-07-13 07:04:48 -04:00
|
|
|
`,
|
2020-02-19 06:16:14 -05:00
|
|
|
},
|
|
|
|
(this.image_resource = {
|
|
|
|
path: 'lion.png',
|
|
|
|
url: `http://${host}:31415/${this.file}`,
|
2021-07-13 07:04:48 -04:00
|
|
|
modified: (this.last_modified = Date.now()),
|
|
|
|
}),
|
|
|
|
],
|
2020-02-19 06:16:14 -05:00
|
|
|
}
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2021-07-13 07:04:48 -04:00
|
|
|
return Client.compile(this.project_id, this.request, error => {
|
2020-02-19 06:16:14 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return Client.clearCache(this.project_id, (error, res, body) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
sinon.spy(Server, 'getFile')
|
|
|
|
return Client.compile(
|
|
|
|
this.project_id,
|
|
|
|
this.request,
|
|
|
|
(error1, res1, body1) => {
|
|
|
|
this.error = error1
|
|
|
|
this.res = res1
|
|
|
|
this.body = body1
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
afterEach(function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.restore()
|
|
|
|
})
|
2018-03-02 12:59:37 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should download the image again', function () {
|
2020-02-19 06:16:14 -05:00
|
|
|
return Server.getFile.called.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|