convert some helper functions in ProjectHistoryClient

GitOrigin-RevId: a73207c4dfbf13cd96456e024adfa6a046002e00
This commit is contained in:
Domagoj Kriskovic
2025-10-02 11:50:17 +02:00
committed by Copybot
parent 5944d20340
commit 632a563ed2
4 changed files with 32 additions and 59 deletions
@@ -28,7 +28,7 @@ describe('Deleting project', function () {
describe('when the project has no pending updates', function () {
it('successfully deletes the project', async function () {
await ProjectHistoryClient.promises.deleteProject(this.projectId)
await ProjectHistoryClient.deleteProject(this.projectId)
})
})
@@ -44,11 +44,11 @@ describe('Deleting project', function () {
this.projectId,
Date.now()
)
await ProjectHistoryClient.promises.deleteProject(this.projectId)
await ProjectHistoryClient.deleteProject(this.projectId)
})
it('clears pending updates', async function () {
const dump = await ProjectHistoryClient.promises.getDump(this.projectId)
const dump = await ProjectHistoryClient.getDump(this.projectId)
expect(dump.updates).to.deep.equal([])
})
@@ -101,7 +101,7 @@ describe('Diffs', function () {
authors: [31],
})
const diff = await ProjectHistoryClient.promises.getDiff(
const diff = await ProjectHistoryClient.getDiff(
this.projectId,
'foo.tex',
3,
@@ -228,7 +228,7 @@ describe('Diffs', function () {
authors: [{ id: 31, email: 'james.allen@overleaf.com', name: 'James' }],
})
const diff = await ProjectHistoryClient.promises.getDiff(
const diff = await ProjectHistoryClient.getDiff(
this.projectId,
'foo.tex',
4,
@@ -367,7 +367,7 @@ describe('Diffs', function () {
authors: [{ id: 31, email: 'james.allen@overleaf.com', name: 'James' }],
})
const diff = await ProjectHistoryClient.promises.getDiff(
const diff = await ProjectHistoryClient.getDiff(
this.projectId,
'binary.tex',
3,
@@ -75,7 +75,7 @@ describe('Retrying failed projects', function () {
this.project_id,
update
)
await ProjectHistoryClient.promises.setFailure({
await ProjectHistoryClient.setFailure({
project_id: this.project_id,
attempts: 1,
error: 'soft-error',
@@ -143,7 +143,7 @@ describe('Retrying failed projects', function () {
},
},
})
await ProjectHistoryClient.promises.setFailure({
await ProjectHistoryClient.setFailure({
project_id: this.project_id,
attempts: 100,
error: 'hard-error',
@@ -4,6 +4,7 @@ import Settings from '@overleaf/settings'
import RedisWrapper from '@overleaf/redis-wrapper'
import { db } from '../../../../app/js/mongodb.js'
import { promisify } from '@overleaf/promise-utils'
import { fetchJsonWithResponse, fetchNothing } from '@overleaf/fetch-utils'
const rclient = RedisWrapper.createClient(Settings.redis.project_history)
const Keys = Settings.redis.project_history.key_schema
@@ -69,25 +70,15 @@ export function getSummarizedUpdates(projectId, query, callback) {
)
}
export function getDiff(projectId, pathname, from, to, callback) {
request.get(
{
url: `http://127.0.0.1:3054/project/${projectId}/diff`,
qs: {
pathname,
from,
to,
},
json: true,
},
(error, res, body) => {
if (error) {
return callback(error)
}
expect(res.statusCode).to.equal(200)
callback(error, body)
}
)
export async function getDiff(projectId, pathname, from, to) {
const url = new URL(`http://127.0.0.1:3054/project/${projectId}/diff`)
url.searchParams.set('pathname', pathname)
url.searchParams.set('from', from)
url.searchParams.set('to', to)
const { response, json } = await fetchJsonWithResponse(url.toString())
expect(response.status).to.equal(200)
return json
}
export function getFileTreeDiff(projectId, from, to, callback) {
@@ -300,16 +291,9 @@ export function deleteLabel(projectId, labelId, callback) {
)
}
export function setFailure(failureEntry, callback) {
db.projectHistoryFailures.deleteOne(
{ project_id: { $exists: true } },
(err, result) => {
if (err) {
return callback(err)
}
db.projectHistoryFailures.insertOne(failureEntry, callback)
}
)
export async function setFailure(failureEntry) {
await db.projectHistoryFailures.deleteOne({ project_id: { $exists: true } })
return await db.projectHistoryFailures.insertOne(failureEntry)
}
export function getFailure(projectId, callback) {
@@ -331,37 +315,26 @@ export function transferLabelOwnership(fromUser, toUser, callback) {
)
}
export function getDump(projectId, callback) {
request.get(
`http://127.0.0.1:3054/project/${projectId}/dump`,
(err, res, body) => {
if (err) {
return callback(err)
}
expect(res.statusCode).to.equal(200)
callback(null, JSON.parse(body))
}
export async function getDump(projectId) {
const { response, json } = await fetchJsonWithResponse(
`http://127.0.0.1:3054/project/${projectId}/dump`
)
expect(response.status).to.equal(200)
return json
}
export function deleteProject(projectId, callback) {
request.delete(`http://127.0.0.1:3054/project/${projectId}`, (err, res) => {
if (err) {
return callback(err)
}
expect(res.statusCode).to.equal(204)
callback()
})
export async function deleteProject(projectId) {
const response = await fetchNothing(
`http://127.0.0.1:3054/project/${projectId}`,
{ method: 'DELETE' }
)
expect(response.status).to.equal(204)
}
export const promises = {
initializeProject: promisify(initializeProject),
deleteProject: promisify(deleteProject),
pushRawUpdate: promisify(pushRawUpdate),
setFirstOpTimestamp: promisify(setFirstOpTimestamp),
getFirstOpTimestamp: promisify(getFirstOpTimestamp),
getDump: promisify(getDump),
setFailure: promisify(setFailure),
getDiff: promisify(getDiff),
flushProject: promisify(flushProject),
}