|
|
@@ -13,6 +13,7 @@ DocUpdaterApp = require "./helpers/DocUpdaterApp"
|
|
|
describe "Applying updates to a project's structure", ->
|
|
|
before ->
|
|
|
@user_id = 'user-id-123'
|
|
|
+ @version = 1234
|
|
|
|
|
|
describe "renaming a file", ->
|
|
|
before (done) ->
|
|
|
@@ -24,7 +25,7 @@ describe "Applying updates to a project's structure", ->
|
|
|
@fileUpdates = [ @fileUpdate ]
|
|
|
DocUpdaterApp.ensureRunning (error) =>
|
|
|
throw error if error?
|
|
|
- DocUpdaterClient.sendProjectUpdate @project_id, @user_id, [], @fileUpdates, (error) ->
|
|
|
+ DocUpdaterClient.sendProjectUpdate @project_id, @user_id, [], @fileUpdates, @version, (error) ->
|
|
|
throw error if error?
|
|
|
setTimeout done, 200
|
|
|
|
|
|
@@ -38,6 +39,7 @@ describe "Applying updates to a project's structure", ->
|
|
|
update.new_pathname.should.equal '/new-file-path'
|
|
|
update.meta.user_id.should.equal @user_id
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
+ update.version.should.equal "#{@version}.0"
|
|
|
|
|
|
done()
|
|
|
|
|
|
@@ -52,7 +54,7 @@ describe "Applying updates to a project's structure", ->
|
|
|
describe "when the document is not loaded", ->
|
|
|
before (done) ->
|
|
|
@project_id = DocUpdaterClient.randomId()
|
|
|
- DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, [], (error) ->
|
|
|
+ DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, [], @version, (error) ->
|
|
|
throw error if error?
|
|
|
setTimeout done, 200
|
|
|
|
|
|
@@ -66,6 +68,7 @@ describe "Applying updates to a project's structure", ->
|
|
|
update.new_pathname.should.equal '/new-doc-path'
|
|
|
update.meta.user_id.should.equal @user_id
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
+ update.version.should.equal "#{@version}.0"
|
|
|
|
|
|
done()
|
|
|
|
|
|
@@ -76,7 +79,7 @@ describe "Applying updates to a project's structure", ->
|
|
|
DocUpdaterClient.preloadDoc @project_id, @docUpdate.id, (error) =>
|
|
|
throw error if error?
|
|
|
sinon.spy MockWebApi, "getDocument"
|
|
|
- DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, [], (error) ->
|
|
|
+ DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, [], @version, (error) ->
|
|
|
throw error if error?
|
|
|
setTimeout done, 200
|
|
|
|
|
|
@@ -98,9 +101,77 @@ describe "Applying updates to a project's structure", ->
|
|
|
update.new_pathname.should.equal '/new-doc-path'
|
|
|
update.meta.user_id.should.equal @user_id
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
+ update.version.should.equal "#{@version}.0"
|
|
|
|
|
|
done()
|
|
|
|
|
|
+ describe "renaming multiple documents and files", ->
|
|
|
+ before ->
|
|
|
+ @docUpdate0 =
|
|
|
+ id: DocUpdaterClient.randomId()
|
|
|
+ pathname: '/doc-path0'
|
|
|
+ newPathname: '/new-doc-path0'
|
|
|
+ @docUpdate1 =
|
|
|
+ id: DocUpdaterClient.randomId()
|
|
|
+ pathname: '/doc-path1'
|
|
|
+ newPathname: '/new-doc-path1'
|
|
|
+ @docUpdates = [ @docUpdate0, @docUpdate1 ]
|
|
|
+ @fileUpdate0 =
|
|
|
+ id: DocUpdaterClient.randomId()
|
|
|
+ pathname: '/file-path0'
|
|
|
+ newPathname: '/new-file-path0'
|
|
|
+ @fileUpdate1 =
|
|
|
+ id: DocUpdaterClient.randomId()
|
|
|
+ pathname: '/file-path1'
|
|
|
+ newPathname: '/new-file-path1'
|
|
|
+ @fileUpdates = [ @fileUpdate0, @fileUpdate1 ]
|
|
|
+
|
|
|
+ describe "when the documents are not loaded", ->
|
|
|
+ before (done) ->
|
|
|
+ @project_id = DocUpdaterClient.randomId()
|
|
|
+ DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, @fileUpdates, @version, (error) ->
|
|
|
+ throw error if error?
|
|
|
+ setTimeout done, 200
|
|
|
+
|
|
|
+ it "should push the applied doc renames to the project history api", (done) ->
|
|
|
+ rclient_history.lrange ProjectHistoryKeys.projectHistoryOps({@project_id}), 0, -1, (error, updates) =>
|
|
|
+ throw error if error?
|
|
|
+
|
|
|
+ update = JSON.parse(updates[0])
|
|
|
+ update.doc.should.equal @docUpdate0.id
|
|
|
+ update.pathname.should.equal '/doc-path0'
|
|
|
+ update.new_pathname.should.equal '/new-doc-path0'
|
|
|
+ update.meta.user_id.should.equal @user_id
|
|
|
+ update.meta.ts.should.be.a('string')
|
|
|
+ update.version.should.equal "#{@version}.0"
|
|
|
+
|
|
|
+ update = JSON.parse(updates[1])
|
|
|
+ update.doc.should.equal @docUpdate1.id
|
|
|
+ update.pathname.should.equal '/doc-path1'
|
|
|
+ update.new_pathname.should.equal '/new-doc-path1'
|
|
|
+ update.meta.user_id.should.equal @user_id
|
|
|
+ update.meta.ts.should.be.a('string')
|
|
|
+ update.version.should.equal "#{@version}.1"
|
|
|
+
|
|
|
+ update = JSON.parse(updates[2])
|
|
|
+ update.file.should.equal @fileUpdate0.id
|
|
|
+ update.pathname.should.equal '/file-path0'
|
|
|
+ update.new_pathname.should.equal '/new-file-path0'
|
|
|
+ update.meta.user_id.should.equal @user_id
|
|
|
+ update.meta.ts.should.be.a('string')
|
|
|
+ update.version.should.equal "#{@version}.2"
|
|
|
+
|
|
|
+ update = JSON.parse(updates[3])
|
|
|
+ update.file.should.equal @fileUpdate1.id
|
|
|
+ update.pathname.should.equal '/file-path1'
|
|
|
+ update.new_pathname.should.equal '/new-file-path1'
|
|
|
+ update.meta.user_id.should.equal @user_id
|
|
|
+ update.meta.ts.should.be.a('string')
|
|
|
+ update.version.should.equal "#{@version}.3"
|
|
|
+
|
|
|
+ done()
|
|
|
+
|
|
|
+
|
|
|
describe "adding a file", ->
|
|
|
before (done) ->
|
|
|
@project_id = DocUpdaterClient.randomId()
|
|
|
@@ -109,7 +180,7 @@ describe "Applying updates to a project's structure", ->
|
|
|
pathname: '/file-path'
|
|
|
url: 'filestore.example.com'
|
|
|
@fileUpdates = [ @fileUpdate ]
|
|
|
- DocUpdaterClient.sendProjectUpdate @project_id, @user_id, [], @fileUpdates, (error) ->
|
|
|
+ DocUpdaterClient.sendProjectUpdate @project_id, @user_id, [], @fileUpdates, @version, (error) ->
|
|
|
throw error if error?
|
|
|
setTimeout done, 200
|
|
|
|
|
|
@@ -123,6 +194,7 @@ describe "Applying updates to a project's structure", ->
|
|
|
update.url.should.equal 'filestore.example.com'
|
|
|
update.meta.user_id.should.equal @user_id
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
+ update.version.should.equal "#{@version}.0"
|
|
|
|
|
|
done()
|
|
|
|
|
|
@@ -134,7 +206,7 @@ describe "Applying updates to a project's structure", ->
|
|
|
pathname: '/file-path'
|
|
|
docLines: 'a\nb'
|
|
|
@docUpdates = [ @docUpdate ]
|
|
|
- DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, [], (error) ->
|
|
|
+ DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, [], @version, (error) ->
|
|
|
throw error if error?
|
|
|
setTimeout done, 200
|
|
|
|
|
|
@@ -148,6 +220,7 @@ describe "Applying updates to a project's structure", ->
|
|
|
update.docLines.should.equal 'a\nb'
|
|
|
update.meta.user_id.should.equal @user_id
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
+ update.version.should.equal "#{@version}.0"
|
|
|
|
|
|
done()
|
|
|
|
|
|
@@ -155,7 +228,8 @@ describe "Applying updates to a project's structure", ->
|
|
|
before (done) ->
|
|
|
@project_id = DocUpdaterClient.randomId()
|
|
|
@user_id = DocUpdaterClient.randomId()
|
|
|
-
|
|
|
+ @version0 = 12345
|
|
|
+ @version1 = @version0 + 1
|
|
|
updates = []
|
|
|
for v in [0..599] # Should flush after 500 ops
|
|
|
updates.push
|
|
|
@@ -168,9 +242,9 @@ describe "Applying updates to a project's structure", ->
|
|
|
# Send updates in chunks to causes multiple flushes
|
|
|
projectId = @project_id
|
|
|
userId = @project_id
|
|
|
- DocUpdaterClient.sendProjectUpdate projectId, userId, updates.slice(0, 250), [], (error) ->
|
|
|
+ DocUpdaterClient.sendProjectUpdate projectId, userId, updates.slice(0, 250), [], @version0, (error) ->
|
|
|
throw error if error?
|
|
|
- DocUpdaterClient.sendProjectUpdate projectId, userId, updates.slice(250), [], (error) ->
|
|
|
+ DocUpdaterClient.sendProjectUpdate projectId, userId, updates.slice(250), [], @version1, (error) ->
|
|
|
throw error if error?
|
|
|
setTimeout done, 2000
|
|
|
|
|
|
@@ -184,6 +258,8 @@ describe "Applying updates to a project's structure", ->
|
|
|
before (done) ->
|
|
|
@project_id = DocUpdaterClient.randomId()
|
|
|
@user_id = DocUpdaterClient.randomId()
|
|
|
+ @version0 = 12345
|
|
|
+ @version1 = @version0 + 1
|
|
|
|
|
|
updates = []
|
|
|
for v in [0..42] # Should flush after 500 ops
|
|
|
@@ -197,9 +273,9 @@ describe "Applying updates to a project's structure", ->
|
|
|
# Send updates in chunks
|
|
|
projectId = @project_id
|
|
|
userId = @project_id
|
|
|
- DocUpdaterClient.sendProjectUpdate projectId, userId, updates.slice(0, 10), [], (error) ->
|
|
|
+ DocUpdaterClient.sendProjectUpdate projectId, userId, updates.slice(0, 10), [], @version0, (error) ->
|
|
|
throw error if error?
|
|
|
- DocUpdaterClient.sendProjectUpdate projectId, userId, updates.slice(10), [], (error) ->
|
|
|
+ DocUpdaterClient.sendProjectUpdate projectId, userId, updates.slice(10), [], @version1, (error) ->
|
|
|
throw error if error?
|
|
|
setTimeout done, 2000
|
|
|
|