mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
42 lines
No EOL
1.4 KiB
CoffeeScript
42 lines
No EOL
1.4 KiB
CoffeeScript
RealTimeClient = require "./RealTimeClient"
|
|
MockWebServer = require "./MockWebServer"
|
|
MockDocUpdaterServer = require "./MockDocUpdaterServer"
|
|
|
|
module.exports = FixturesManager =
|
|
setUpProject: (options = {}, callback = (error, data) ->) ->
|
|
options.user_id ||= FixturesManager.getRandomId()
|
|
options.project_id ||= FixturesManager.getRandomId()
|
|
options.project ||= { name: "Test Project" }
|
|
{project_id, user_id, privilegeLevel, project} = options
|
|
|
|
privileges = {}
|
|
privileges[user_id] = privilegeLevel
|
|
|
|
MockWebServer.createMockProject(project_id, privileges, project)
|
|
MockWebServer.run (error) =>
|
|
throw error if error?
|
|
RealTimeClient.setSession {
|
|
user: { _id: user_id }
|
|
}, (error) =>
|
|
throw error if error?
|
|
callback null, {project_id, user_id, privilegeLevel, project}
|
|
|
|
setUpDoc: (project_id, options = {}, callback = (error, data) ->) ->
|
|
options.doc_id ||= FixturesManager.getRandomId()
|
|
options.lines ||= ["doc", "lines"]
|
|
options.version ||= 42
|
|
options.ops ||= ["mock", "ops"]
|
|
{doc_id, lines, version, ops} = options
|
|
|
|
MockDocUpdaterServer.createMockDoc project_id, doc_id, {lines, version, ops}
|
|
MockDocUpdaterServer.run (error) =>
|
|
throw error if error?
|
|
callback null, {project_id, doc_id, lines, version, ops}
|
|
|
|
getRandomId: () ->
|
|
return require("crypto")
|
|
.createHash("sha1")
|
|
.update(Math.random().toString())
|
|
.digest("hex")
|
|
.slice(0,24)
|
|
|