|
|
@@ -11,12 +11,10 @@ TrackChangesClient = require "./helpers/TrackChangesClient"
|
|
|
MockWebApi = require "./helpers/MockWebApi"
|
|
|
|
|
|
describe "Getting updates", ->
|
|
|
- before (done) ->
|
|
|
+ before ->
|
|
|
@now = Date.now()
|
|
|
@to = @now
|
|
|
@user_id = ObjectId().toString()
|
|
|
- @doc_id = ObjectId().toString()
|
|
|
- @project_id = ObjectId().toString()
|
|
|
|
|
|
@minutes = 60 * 1000
|
|
|
|
|
|
@@ -27,49 +25,87 @@ describe "Getting updates", ->
|
|
|
id: @user_id
|
|
|
sinon.spy MockWebApi, "getUser"
|
|
|
|
|
|
- @updates = [{
|
|
|
- op: [{ i: "one ", p: 0 }]
|
|
|
- meta: { ts: @to - 4 * @minutes, user_id: @user_id }
|
|
|
- v: 3
|
|
|
- }, {
|
|
|
- op: [{ i: "two ", p: 4 }]
|
|
|
- meta: { ts: @to - 2 * @minutes }
|
|
|
- v: 4
|
|
|
- }, {
|
|
|
- op: [{ i: "three ", p: 8 }]
|
|
|
- meta: { ts: @to, user_id: @user_id }
|
|
|
- v: @toVersion = 5
|
|
|
- }, {
|
|
|
- op: [{ i: "four", p: 14 }]
|
|
|
- meta: { ts: @to + 2 * @minutes, user_id: @user_id }
|
|
|
- v: 6
|
|
|
- }]
|
|
|
+ after: () ->
|
|
|
+ MockWebApi.getUser.restore()
|
|
|
|
|
|
- TrackChangesClient.pushRawUpdates @doc_id, @updates, (error) =>
|
|
|
- throw error if error?
|
|
|
- TrackChangesClient.getUpdates @project_id, @doc_id, { to: @toVersion, limit: 2 }, (error, body) =>
|
|
|
+ describe "getting updates in the middle", ->
|
|
|
+ before (done) ->
|
|
|
+ @doc_id = ObjectId().toString()
|
|
|
+ @project_id = ObjectId().toString()
|
|
|
+ @updates = [{
|
|
|
+ op: [{ i: "one ", p: 0 }]
|
|
|
+ meta: { ts: @to - 20 * @minutes, user_id: @user_id }
|
|
|
+ v: 3
|
|
|
+ }, {
|
|
|
+ op: [{ i: "two ", p: 4 }]
|
|
|
+ meta: { ts: @to - 10 * @minutes }
|
|
|
+ v: 4
|
|
|
+ }, {
|
|
|
+ op: [{ i: "three ", p: 8 }]
|
|
|
+ meta: { ts: @to, user_id: @user_id }
|
|
|
+ v: @toVersion = 5
|
|
|
+ }, {
|
|
|
+ op: [{ i: "four", p: 14 }]
|
|
|
+ meta: { ts: @to + 2 * @minutes, user_id: @user_id }
|
|
|
+ v: 6
|
|
|
+ }]
|
|
|
+
|
|
|
+ TrackChangesClient.pushRawUpdates @doc_id, @updates, (error) =>
|
|
|
throw error if error?
|
|
|
- @updates = body.updates
|
|
|
- done()
|
|
|
+ TrackChangesClient.getUpdates @project_id, @doc_id, { to: @toVersion, limit: 2 }, (error, body) =>
|
|
|
+ throw error if error?
|
|
|
+ @updates = body.updates
|
|
|
+ done()
|
|
|
|
|
|
- after: () ->
|
|
|
- MockWebApi.getUser.restore()
|
|
|
+ it "should fetch the user details from the web api", ->
|
|
|
+ MockWebApi.getUser
|
|
|
+ .calledWith(@user_id)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should return the updates", ->
|
|
|
+ expect(@updates).to.deep.equal [{
|
|
|
+ meta:
|
|
|
+ start_ts: @to
|
|
|
+ end_ts: @to
|
|
|
+ users: [@user]
|
|
|
+ fromV: 5
|
|
|
+ toV: 5
|
|
|
+ }, {
|
|
|
+ meta:
|
|
|
+ users: []
|
|
|
+ start_ts: @to - 10 * @minutes
|
|
|
+ end_ts: @to - 10 * @minutes
|
|
|
+ toV: 4
|
|
|
+ fromV: 4
|
|
|
+ }]
|
|
|
|
|
|
- it "should fetch the user details from the web api", ->
|
|
|
- MockWebApi.getUser
|
|
|
- .calledWith(@user_id)
|
|
|
- .should.equal true
|
|
|
+ describe "getting updates that should be combined", ->
|
|
|
+ before (done) ->
|
|
|
+ @doc_id = ObjectId().toString()
|
|
|
+ @project_id = ObjectId().toString()
|
|
|
+ @updates = [{
|
|
|
+ op: [{ i: "two ", p: 4 }]
|
|
|
+ meta: { ts: @to - 2 * @minutes, user_id: @user_id }
|
|
|
+ v: 4
|
|
|
+ }, {
|
|
|
+ op: [{ i: "three ", p: 8 }]
|
|
|
+ meta: { ts: @to, user_id: @user_id }
|
|
|
+ v: @toVersion = 5
|
|
|
+ }]
|
|
|
+
|
|
|
+ TrackChangesClient.pushRawUpdates @doc_id, @updates, (error) =>
|
|
|
+ throw error if error?
|
|
|
+ TrackChangesClient.getUpdates @project_id, @doc_id, { to: @toVersion, limit: 2 }, (error, body) =>
|
|
|
+ throw error if error?
|
|
|
+ @updates = body.updates
|
|
|
+ done()
|
|
|
|
|
|
- it "should return the updates", ->
|
|
|
- expect(@updates).to.deep.equal [{
|
|
|
- meta:
|
|
|
- start_ts: @to
|
|
|
- end_ts: @to
|
|
|
- user: @user
|
|
|
- v: 5
|
|
|
- }, {
|
|
|
- meta:
|
|
|
- start_ts: @to - 2 * @minutes
|
|
|
- end_ts: @to - 2 * @minutes
|
|
|
- v: 4
|
|
|
- }]
|
|
|
+ it "should return the updates", ->
|
|
|
+ expect(@updates).to.deep.equal [{
|
|
|
+ meta:
|
|
|
+ start_ts: @to - 2 * @minutes
|
|
|
+ end_ts: @to
|
|
|
+ users: [@user]
|
|
|
+ fromV: 4
|
|
|
+ toV: 5
|
|
|
+ }]
|