Add in project_id to flushing HTTP endpoint

This commit is contained in:
James Allen 2014-03-19 16:14:17 +00:00
parent d32b0ee12f
commit fec648666c
3 changed files with 13 additions and 9 deletions

View file

@ -10,7 +10,7 @@ app = express()
app.use express.logger()
app.post "/doc/:doc_id/flush", HttpController.flushUpdatesWithLock
app.post "/project/:project_id/doc/:doc_id/flush", HttpController.flushUpdatesWithLock
app.get "/project/:project_id/doc/:doc_id/diff", HttpController.getDiff

View file

@ -13,6 +13,7 @@ TrackChangesClient = require "./helpers/TrackChangesClient"
describe "Appending doc ops to the history", ->
describe "when the history does not exist yet", ->
before (done) ->
@project_id = ObjectId().toString()
@doc_id = ObjectId().toString()
@user_id = ObjectId().toString()
TrackChangesClient.pushRawUpdates @doc_id, [{
@ -29,7 +30,7 @@ describe "Appending doc ops to the history", ->
v: 5
}], (error) =>
throw error if error?
TrackChangesClient.flushAndGetCompressedUpdates @doc_id, (error, @updates) =>
TrackChangesClient.flushAndGetCompressedUpdates @project_id, @doc_id, (error, @updates) =>
throw error if error?
done()
@ -43,6 +44,7 @@ describe "Appending doc ops to the history", ->
describe "when the history has already been started", ->
beforeEach (done) ->
@project_id = ObjectId().toString()
@doc_id = ObjectId().toString()
@user_id = ObjectId().toString()
TrackChangesClient.pushRawUpdates @doc_id, [{
@ -59,7 +61,7 @@ describe "Appending doc ops to the history", ->
v: 5
}], (error) =>
throw error if error?
TrackChangesClient.flushAndGetCompressedUpdates @doc_id, (error, updates) =>
TrackChangesClient.flushAndGetCompressedUpdates @project_id, @doc_id, (error, updates) =>
throw error if error?
done()
@ -79,7 +81,7 @@ describe "Appending doc ops to the history", ->
v: 8
}], (error) =>
throw error if error?
TrackChangesClient.flushAndGetCompressedUpdates @doc_id, (error, @updates) =>
TrackChangesClient.flushAndGetCompressedUpdates @project_id, @doc_id, (error, @updates) =>
throw error if error?
done()
@ -109,7 +111,7 @@ describe "Appending doc ops to the history", ->
v: 8
}], (error) =>
throw error if error?
TrackChangesClient.flushAndGetCompressedUpdates @doc_id, (error, @updates) =>
TrackChangesClient.flushAndGetCompressedUpdates @project_id, @doc_id, (error, @updates) =>
throw error if error?
done()
@ -123,6 +125,7 @@ describe "Appending doc ops to the history", ->
describe "when the updates need processing in batches", ->
before (done) ->
@project_id = ObjectId().toString()
@doc_id = ObjectId().toString()
@user_id = ObjectId().toString()
updates = []
@ -137,7 +140,7 @@ describe "Appending doc ops to the history", ->
TrackChangesClient.pushRawUpdates @doc_id, updates, (error) =>
throw error if error?
TrackChangesClient.flushAndGetCompressedUpdates @doc_id, (error, @updates) =>
TrackChangesClient.flushAndGetCompressedUpdates @project_id, @doc_id, (error, @updates) =>
throw error if error?
done()
@ -150,6 +153,7 @@ describe "Appending doc ops to the history", ->
describe "when there are multiple ops in each update", ->
before (done) ->
@project_id = ObjectId().toString()
@doc_id = ObjectId().toString()
@user_id = ObjectId().toString()
oneDay = 24 * 60 * 60 * 1000
@ -163,7 +167,7 @@ describe "Appending doc ops to the history", ->
v: 4
}], (error) =>
throw error if error?
TrackChangesClient.flushAndGetCompressedUpdates @doc_id, (error, @updates) =>
TrackChangesClient.flushAndGetCompressedUpdates @project_id, @doc_id, (error, @updates) =>
throw error if error?
done()

View file

@ -3,9 +3,9 @@ rclient = require("redis").createClient() # Only works locally for now
{db, ObjectId} = require "../../../../app/js/mongojs"
module.exports = TrackChangesClient =
flushAndGetCompressedUpdates: (doc_id, callback = (error, updates) ->) ->
flushAndGetCompressedUpdates: (project_id, doc_id, callback = (error, updates) ->) ->
request.post {
url: "http://localhost:3015/doc/#{doc_id}/flush"
url: "http://localhost:3015/project/#{project_id}/doc/#{doc_id}/flush"
}, (error, response, body) =>
response.statusCode.should.equal 204
db.docHistory