mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
4a6af88760
[tests] rebased refactoring of acceptance test mocks GitOrigin-RevId: dd8b7d69c507aa1270b6fb165b1339bc8a7d6415
43 lines
1 KiB
JavaScript
43 lines
1 KiB
JavaScript
const AbstractMockApi = require('./AbstractMockApi')
|
|
|
|
class MockChatApi extends AbstractMockApi {
|
|
reset() {
|
|
this.projects = {}
|
|
}
|
|
|
|
getGlobalMessages(req, res) {
|
|
res.send(this.projects[req.params.project_id] || [])
|
|
}
|
|
|
|
sendGlobalMessage(req, res) {
|
|
const projectId = req.params.project_id
|
|
const message = {
|
|
id: Math.random().toString(),
|
|
content: req.body.content,
|
|
timestamp: Date.now(),
|
|
user_id: req.body.user_id
|
|
}
|
|
this.projects[projectId] = this.projects[projectId] || []
|
|
this.projects[projectId].push(message)
|
|
res.sendStatus(201).send(Object.assign({ room_id: projectId }, message))
|
|
}
|
|
|
|
applyRoutes() {
|
|
this.app.get('/project/:project_id/messages', (req, res) =>
|
|
this.getGlobalMessages(req, res)
|
|
)
|
|
this.app.post('/project/:project_id/messages', (req, res) =>
|
|
this.sendGlobalMessage(req, res)
|
|
)
|
|
}
|
|
}
|
|
|
|
module.exports = MockChatApi
|
|
|
|
// type hint for the inherited `instance` method
|
|
/**
|
|
* @function instance
|
|
* @memberOf MockChatApi
|
|
* @static
|
|
* @returns {MockChatApi}
|
|
*/
|