mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #30310 from overleaf/mj-async-mock-docstore-api
[document-updater] Remove callbacks from MockDocstoreApi GitOrigin-RevId: 86342f293e9bbbcaddd6c44bcca62c301db23670
This commit is contained in:
committed by
Copybot
parent
c4fb6233ce
commit
6f67ae4312
@@ -339,17 +339,12 @@ describe('CheckRedisMongoSyncState', function () {
|
||||
})
|
||||
})
|
||||
describe('with docstore metadata updated', function () {
|
||||
beforeEach(function (done) {
|
||||
MockDocstoreApi.patchDocument(
|
||||
projectId,
|
||||
docId,
|
||||
{
|
||||
deleted: true,
|
||||
deletedAt: new Date(),
|
||||
name: 'c.tex',
|
||||
},
|
||||
done
|
||||
)
|
||||
beforeEach(async function () {
|
||||
await MockDocstoreApi.patchDocument(projectId, docId, {
|
||||
deleted: true,
|
||||
deletedAt: new Date(),
|
||||
name: 'c.tex',
|
||||
})
|
||||
})
|
||||
|
||||
it('should work when in sync', async function () {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const express = require('express')
|
||||
const bodyParser = require('body-parser')
|
||||
const { expressify } = require('@overleaf/promise-utils')
|
||||
const app = express()
|
||||
const MAX_REQUEST_SIZE = 2 * (2 * 1024 * 1024 + 64 * 1024)
|
||||
|
||||
@@ -24,74 +25,73 @@ const MockDocstoreApi = {
|
||||
this.docs[`${projectId}:${docId}`] = doc
|
||||
},
|
||||
|
||||
patchDocument(projectId, docId, meta, callback) {
|
||||
async patchDocument(projectId, docId, meta) {
|
||||
Object.assign(this.docs[`${projectId}:${docId}`], meta)
|
||||
callback(null)
|
||||
},
|
||||
|
||||
peekDocument(projectId, docId, callback) {
|
||||
callback(null, this.docs[`${projectId}:${docId}`])
|
||||
async peekDocument(projectId, docId) {
|
||||
return this.docs[`${projectId}:${docId}`]
|
||||
},
|
||||
|
||||
getAllDeletedDocs(projectId, callback) {
|
||||
callback(
|
||||
null,
|
||||
Object.entries(this.docs)
|
||||
.filter(([key, doc]) => key.startsWith(projectId) && doc.deleted)
|
||||
.map(([key, doc]) => {
|
||||
return {
|
||||
_id: key.split(':')[1],
|
||||
name: doc.name,
|
||||
deletedAt: doc.deletedAt,
|
||||
}
|
||||
})
|
||||
)
|
||||
async getAllDeletedDocs(projectId) {
|
||||
return Object.entries(this.docs)
|
||||
.filter(([key, doc]) => key.startsWith(projectId) && doc.deleted)
|
||||
.map(([key, doc]) => {
|
||||
return {
|
||||
_id: key.split(':')[1],
|
||||
name: doc.name,
|
||||
deletedAt: doc.deletedAt,
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
run() {
|
||||
app.get('/project/:project_id/doc-deleted', (req, res, next) => {
|
||||
this.getAllDeletedDocs(req.params.project_id, (error, docs) => {
|
||||
if (error) {
|
||||
res.sendStatus(500)
|
||||
} else {
|
||||
res.json(docs)
|
||||
app.get(
|
||||
'/project/:project_id/doc-deleted',
|
||||
expressify(async (req, res) => {
|
||||
try {
|
||||
const docs = await this.getAllDeletedDocs(req.params.project_id)
|
||||
return res.json(docs)
|
||||
} catch (error) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
app.get('/project/:project_id/doc/:doc_id/peek', (req, res, next) => {
|
||||
this.peekDocument(
|
||||
req.params.project_id,
|
||||
req.params.doc_id,
|
||||
(error, doc) => {
|
||||
if (error) {
|
||||
res.sendStatus(500)
|
||||
} else if (doc) {
|
||||
res.json(doc)
|
||||
app.get(
|
||||
'/project/:project_id/doc/:doc_id/peek',
|
||||
expressify(async (req, res) => {
|
||||
try {
|
||||
const doc = await this.peekDocument(
|
||||
req.params.project_id,
|
||||
req.params.doc_id
|
||||
)
|
||||
if (doc) {
|
||||
return res.json(doc)
|
||||
} else {
|
||||
res.sendStatus(404)
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
} catch (error) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
app.patch(
|
||||
'/project/:project_id/doc/:doc_id',
|
||||
bodyParser.json({ limit: MAX_REQUEST_SIZE }),
|
||||
(req, res, next) => {
|
||||
MockDocstoreApi.patchDocument(
|
||||
req.params.project_id,
|
||||
req.params.doc_id,
|
||||
req.body,
|
||||
error => {
|
||||
if (error) {
|
||||
res.sendStatus(500)
|
||||
} else {
|
||||
res.sendStatus(204)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
expressify(async (req, res) => {
|
||||
try {
|
||||
await MockDocstoreApi.patchDocument(
|
||||
req.params.project_id,
|
||||
req.params.doc_id,
|
||||
req.body
|
||||
)
|
||||
return res.sendStatus(204)
|
||||
} catch (error) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
app
|
||||
|
||||
Reference in New Issue
Block a user