mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-07 08:09:01 +02:00
Add docModified hook in ds-mobile-app module (#27196)
* Add docModified hook in ds-mobile-app module * use Object.entries when iterating over promises * avoid project lookup * update tests GitOrigin-RevId: 88676746f56558a97ce31010b57f5eeb254fefef
This commit is contained in:
committed by
Copybot
parent
868d562d96
commit
d5b5710d01
@@ -7,6 +7,7 @@ import logger from '@overleaf/logger'
|
||||
import _ from 'lodash'
|
||||
import { plainTextResponse } from '../../infrastructure/Response.js'
|
||||
import { expressify } from '@overleaf/promise-utils'
|
||||
import Modules from '../../infrastructure/Modules.js'
|
||||
|
||||
async function getDocument(req, res) {
|
||||
const { Project_id: projectId, doc_id: docId } = req.params
|
||||
@@ -92,6 +93,9 @@ async function setDocument(req, res) {
|
||||
{ docId, projectId },
|
||||
'finished receiving set document request from api (docupdater)'
|
||||
)
|
||||
|
||||
await Modules.promises.hooks.fire('docModified', projectId, docId)
|
||||
|
||||
res.json(result)
|
||||
}
|
||||
|
||||
|
||||
@@ -150,8 +150,7 @@ async function linkedFileAgentsIncludes() {
|
||||
async function attachHooks() {
|
||||
for (const module of await modules()) {
|
||||
const { promises, ...hooks } = module.hooks || {}
|
||||
for (const hook in promises || {}) {
|
||||
const method = promises[hook]
|
||||
for (const [hook, method] of Object.entries(promises || {})) {
|
||||
attachHook(hook, method)
|
||||
}
|
||||
for (const hook in hooks || {}) {
|
||||
|
||||
@@ -87,6 +87,14 @@ describe('DocumentController', function () {
|
||||
},
|
||||
}
|
||||
|
||||
ctx.Modules = {
|
||||
promises: {
|
||||
hooks: {
|
||||
fire: sinon.stub().resolves(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
vi.doMock('../../../../app/src/Features/Project/ProjectGetter', () => ({
|
||||
default: ctx.ProjectGetter,
|
||||
}))
|
||||
@@ -113,6 +121,10 @@ describe('DocumentController', function () {
|
||||
default: ctx.ChatApiHandler,
|
||||
}))
|
||||
|
||||
vi.doMock('../../../../app/src/infrastructure/Modules.js', () => ({
|
||||
default: ctx.Modules,
|
||||
}))
|
||||
|
||||
ctx.DocumentController = (await import(MODULE_PATH)).default
|
||||
})
|
||||
|
||||
@@ -208,6 +220,15 @@ describe('DocumentController', function () {
|
||||
it('should return a successful response', function (ctx) {
|
||||
ctx.res.success.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the docModified hook', function (ctx) {
|
||||
sinon.assert.calledWith(
|
||||
ctx.Modules.promises.hooks.fire,
|
||||
'docModified',
|
||||
ctx.project._id,
|
||||
ctx.doc._id
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the document doesn't exist", function () {
|
||||
|
||||
@@ -53,7 +53,10 @@ export type WebModule = {
|
||||
apply: (webRouter: any, privateApiRouter: any, publicApiRouter: any) => void
|
||||
}
|
||||
hooks?: {
|
||||
[name: string]: (args: any[]) => void
|
||||
promises?: {
|
||||
[name: string]: (...args: any[]) => Promise<any>
|
||||
}
|
||||
[name: string]: ((...args: any[]) => void) | any
|
||||
}
|
||||
middleware?: {
|
||||
[name: string]: RequestHandler
|
||||
|
||||
Reference in New Issue
Block a user