[history-v1] add endpoint for downloading latest zip (#33181)
* [history-v1] add endpoint for downloading latest zip * [web] address review feedback * [web] tests: do not overwrite db.projects.overleaf, extend it * [web] set includeReferer flag from downloading zip GitOrigin-RevId: e63e549f004230086f82eccf03b43fd62bde6071
This commit is contained in:
@@ -73,6 +73,14 @@ describe('ProjectDownloadsController', function () {
|
||||
}),
|
||||
})
|
||||
)
|
||||
vi.doMock(
|
||||
'../../../../app/src/Features/SplitTests/SplitTestHandler.mjs',
|
||||
() => ({
|
||||
default: (ctx.SplitTestHandler = {
|
||||
featureFlagEnabled: sinon.stub().yields(null, false),
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
vi.doMock('@overleaf/settings', () => ({
|
||||
default: (ctx.Settings = {
|
||||
@@ -92,7 +100,7 @@ describe('ProjectDownloadsController', function () {
|
||||
ctx.stream = { pipe: sinon.stub() }
|
||||
ctx.ProjectZipStreamManager.createZipStreamForProject = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, ctx.stream)
|
||||
.yields(null, ctx.stream)
|
||||
ctx.req.params = { Project_id: ctx.project_id }
|
||||
ctx.req.ip = '192.168.1.1'
|
||||
ctx.req.session = {
|
||||
@@ -102,9 +110,10 @@ describe('ProjectDownloadsController', function () {
|
||||
},
|
||||
}
|
||||
ctx.project_name = 'project name with accênts and % special characters'
|
||||
ctx.ProjectGetter.getProject = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, { name: ctx.project_name })
|
||||
ctx.ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, {
|
||||
name: ctx.project_name,
|
||||
overleaf: { history: { id: 123 } },
|
||||
})
|
||||
ctx.DocumentUpdaterHandler.flushProjectToMongo = sinon
|
||||
.stub()
|
||||
.callsArgWith(1)
|
||||
@@ -138,7 +147,7 @@ describe('ProjectDownloadsController', function () {
|
||||
|
||||
it("should look up the project's name", function (ctx) {
|
||||
return ctx.ProjectGetter.getProject
|
||||
.calledWith(ctx.project_id, { name: true })
|
||||
.calledWith(ctx.project_id, { name: true, 'overleaf.history.id': true })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
@@ -172,7 +181,7 @@ describe('ProjectDownloadsController', function () {
|
||||
ctx.stream = { pipe: sinon.stub() }
|
||||
ctx.ProjectZipStreamManager.createZipStreamForMultipleProjects = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, ctx.stream)
|
||||
.yields(null, ctx.stream)
|
||||
ctx.project_ids = ['project-1', 'project-2']
|
||||
ctx.req.query = { project_ids: ctx.project_ids.join(',') }
|
||||
ctx.req.ip = '192.168.1.1'
|
||||
|
||||
@@ -46,7 +46,9 @@ describe('ProjectZipStreamManager', function () {
|
||||
vi.doMock(
|
||||
'../../../../app/src/Features/History/HistoryManager.mjs',
|
||||
() => ({
|
||||
default: (ctx.HistoryManager = {}),
|
||||
default: (ctx.HistoryManager = {
|
||||
flushProject: sinon.stub().yields(null),
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
@@ -81,6 +83,8 @@ describe('ProjectZipStreamManager', function () {
|
||||
|
||||
ctx.ProjectZipStreamManager.createZipStreamForProject = (
|
||||
projectId,
|
||||
zipFromHistory,
|
||||
historyId,
|
||||
callback
|
||||
) => {
|
||||
callback(null, ctx.zip_streams[projectId])
|
||||
@@ -92,12 +96,16 @@ describe('ProjectZipStreamManager', function () {
|
||||
sinon.spy(ctx.ProjectZipStreamManager, 'createZipStreamForProject')
|
||||
|
||||
ctx.ProjectGetter.getProject = (projectId, fields, callback) => {
|
||||
return callback(null, { name: ctx.project_names[projectId] })
|
||||
return callback(null, {
|
||||
name: ctx.project_names[projectId],
|
||||
overleaf: { history: { id: 123 } },
|
||||
})
|
||||
}
|
||||
sinon.spy(ctx.ProjectGetter, 'getProject')
|
||||
|
||||
ctx.ProjectZipStreamManager.createZipStreamForMultipleProjects(
|
||||
ctx.project_ids,
|
||||
false,
|
||||
(...args) => {
|
||||
return ctx.callback(...Array.from(args || []))
|
||||
}
|
||||
@@ -131,7 +139,7 @@ describe('ProjectZipStreamManager', function () {
|
||||
it('should get the names of each project', function (ctx) {
|
||||
return Array.from(ctx.project_ids).map(projectId =>
|
||||
ctx.ProjectGetter.getProject
|
||||
.calledWith(projectId, { name: true })
|
||||
.calledWith(projectId, { name: true, 'overleaf.history.id': true })
|
||||
.should.equal(true)
|
||||
)
|
||||
})
|
||||
@@ -160,6 +168,8 @@ describe('ProjectZipStreamManager', function () {
|
||||
|
||||
ctx.ProjectZipStreamManager.createZipStreamForProject = (
|
||||
projectId,
|
||||
zipFromHistory,
|
||||
historyId,
|
||||
callback
|
||||
) => {
|
||||
callback(null, ctx.zip_streams[projectId])
|
||||
@@ -171,12 +181,16 @@ describe('ProjectZipStreamManager', function () {
|
||||
|
||||
ctx.ProjectGetter.getProject = (projectId, fields, callback) => {
|
||||
const name = ctx.project_names[projectId]
|
||||
callback(null, name ? { name } : undefined)
|
||||
callback(
|
||||
null,
|
||||
name ? { name, overleaf: { history: { id: 123 } } } : undefined
|
||||
)
|
||||
}
|
||||
sinon.spy(ctx.ProjectGetter, 'getProject')
|
||||
|
||||
ctx.ProjectZipStreamManager.createZipStreamForMultipleProjects(
|
||||
ctx.project_ids,
|
||||
false,
|
||||
ctx.callback
|
||||
)
|
||||
|
||||
@@ -200,7 +214,7 @@ describe('ProjectZipStreamManager', function () {
|
||||
it('should get the names of each project', function (ctx) {
|
||||
ctx.project_ids.map(projectId =>
|
||||
ctx.ProjectGetter.getProject
|
||||
.calledWith(projectId, { name: true })
|
||||
.calledWith(projectId, { name: true, 'overleaf.history.id': true })
|
||||
.should.equal(true)
|
||||
)
|
||||
})
|
||||
@@ -237,6 +251,8 @@ describe('ProjectZipStreamManager', function () {
|
||||
ctx.archive.finalize = sinon.stub()
|
||||
return ctx.ProjectZipStreamManager.createZipStreamForProject(
|
||||
ctx.project_id,
|
||||
false,
|
||||
123,
|
||||
ctx.callback
|
||||
)
|
||||
})
|
||||
@@ -285,6 +301,8 @@ describe('ProjectZipStreamManager', function () {
|
||||
ctx.archive.finalize = sinon.stub()
|
||||
ctx.ProjectZipStreamManager.createZipStreamForProject(
|
||||
ctx.project_id,
|
||||
false,
|
||||
123,
|
||||
ctx.callback
|
||||
)
|
||||
})
|
||||
@@ -317,6 +335,8 @@ describe('ProjectZipStreamManager', function () {
|
||||
ctx.archive.finalize = sinon.stub()
|
||||
return ctx.ProjectZipStreamManager.createZipStreamForProject(
|
||||
ctx.project_id,
|
||||
false,
|
||||
123,
|
||||
ctx.callback
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user