2014-11-12 10:54:55 -05:00
|
|
|
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" }
|
2014-11-21 06:48:59 -05:00
|
|
|
{project_id, user_id, privilegeLevel, project, publicAccess} = options
|
2014-11-12 10:54:55 -05:00
|
|
|
|
|
|
|
privileges = {}
|
|
|
|
privileges[user_id] = privilegeLevel
|
2014-11-21 06:48:59 -05:00
|
|
|
if publicAccess
|
|
|
|
privileges["anonymous-user"] = publicAccess
|
2014-11-12 10:54:55 -05:00
|
|
|
|
|
|
|
MockWebServer.createMockProject(project_id, privileges, project)
|
|
|
|
MockWebServer.run (error) =>
|
|
|
|
throw error if error?
|
|
|
|
RealTimeClient.setSession {
|
2014-11-13 10:27:18 -05:00
|
|
|
user: {
|
|
|
|
_id: user_id
|
|
|
|
first_name: "Joe"
|
|
|
|
last_name: "Bloggs"
|
|
|
|
}
|
2014-11-12 10:54:55 -05:00
|
|
|
}, (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)
|
|
|
|
|