Merge pull request #22202 from overleaf/jpa-tpds

[misc] tpds: read files from history-v1 with fallback to filestore

GitOrigin-RevId: afdde47e453b0cb07985392b5e2b03abf348debf
This commit is contained in:
Jakob Ackermann
2024-11-29 09:04:54 +00:00
committed by Copybot
parent cc60acd4ea
commit 892eaabdf7
6 changed files with 99 additions and 18 deletions
@@ -9,7 +9,7 @@ const MODULE_PATH =
describe('TpdsProjectFlusher', function () {
beforeEach(function () {
this.project = { _id: new ObjectId() }
this.project = { _id: new ObjectId(), overleaf: { history: { id: 42 } } }
this.folder = { _id: new ObjectId() }
this.docs = {
'/doc/one': {
@@ -26,8 +26,18 @@ describe('TpdsProjectFlusher', function () {
},
}
this.files = {
'/file/one': { _id: 'mock-file-1', rev: 7, folder: this.folder },
'/file/two': { _id: 'mock-file-2', rev: 8, folder: this.folder },
'/file/one': {
_id: 'mock-file-1',
rev: 7,
folder: this.folder,
hash: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
},
'/file/two': {
_id: 'mock-file-2',
rev: 8,
folder: this.folder,
hash: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
},
}
this.DocumentUpdaterHandler = {
promises: {
@@ -107,7 +117,9 @@ describe('TpdsProjectFlusher', function () {
this.TpdsUpdateSender.promises.addFile
).to.have.been.calledWith({
projectId: this.project._id,
historyId: this.project.overleaf.history.id,
fileId: file._id,
hash: file.hash,
projectName: this.project.name,
rev: file.rev,
path,
@@ -235,7 +247,9 @@ describe('TpdsProjectFlusher', function () {
this.TpdsUpdateSender.promises.addFile
).to.have.been.calledWith({
projectId: this.project._id,
historyId: this.project.overleaf.history.id,
fileId: file._id,
hash: file.hash,
projectName: this.project.name,
rev: file.rev,
path,
@@ -18,6 +18,7 @@ const projectName = 'project_name_here'
const thirdPartyDataStoreApiUrl = 'http://third-party-json-store.herokuapp.com'
const siteUrl = 'http://127.0.0.1:3000'
const filestoreUrl = 'filestore.overleaf.com'
const projectHistoryUrl = 'http://project-history:3054'
describe('TpdsUpdateSender', function () {
beforeEach(function () {
@@ -52,6 +53,9 @@ describe('TpdsUpdateSender', function () {
docstore: {
pubUrl: this.docstoreUrl,
},
project_history: {
url: projectHistoryUrl,
},
},
}
const getUsers = sinon.stub()
@@ -113,11 +117,15 @@ describe('TpdsUpdateSender', function () {
it('queues a post the file with user and file id', async function () {
const fileId = '4545345'
const hash = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
const historyId = 91525
const path = '/some/path/here.jpg'
await this.TpdsUpdateSender.promises.addFile({
projectId,
historyId,
fileId,
hash,
path,
projectName,
})
@@ -130,7 +138,8 @@ describe('TpdsUpdateSender', function () {
method: 'pipeStreamFrom',
job: {
method: 'post',
streamOrigin: `${filestoreUrl}/project/${projectId}/file/${fileId}`,
streamOrigin: `${projectHistoryUrl}/project/${historyId}/blob/${hash}`,
streamFallback: `${filestoreUrl}/project/${projectId}/file/${fileId}`,
uri: `${thirdPartyDataStoreApiUrl}/user/${userId}/entity/${encodeURIComponent(
projectName
)}${encodeURIComponent(path)}`,
@@ -412,18 +421,22 @@ describe('TpdsUpdateSender', function () {
})
.resolves([])
})
})
it('does not make request to tpds', async function () {
const fileId = '4545345'
const path = '/some/path/here.jpg'
it('does not make request to tpds', async function () {
const fileId = '4545345'
const hash = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
const historyId = 91525
const path = '/some/path/here.jpg'
await this.TpdsUpdateSender.promises.addFile({
projectId,
fileId,
path,
projectName,
await this.TpdsUpdateSender.promises.addFile({
projectId,
historyId,
hash,
fileId,
path,
projectName,
})
this.FetchUtils.fetchNothing.should.not.have.been.called
})
this.FetchUtils.fetchNothing.should.not.have.been.called
})
})