|
|
@@ -11,7 +11,7 @@ describe "RealTimeRedisManager", ->
|
|
|
auth: () ->
|
|
|
exec: sinon.stub()
|
|
|
@rclient.multi = () => @rclient
|
|
|
- @pubsubClient =
|
|
|
+ @pubsubClient =
|
|
|
publish: sinon.stub()
|
|
|
@RealTimeRedisManager = SandboxedModule.require modulePath, requires:
|
|
|
"redis-sharelatex": createClient: (config) => if (config.name is 'pubsub') then @pubsubClient else @rclient
|
|
|
@@ -25,11 +25,12 @@ describe "RealTimeRedisManager", ->
|
|
|
"logger-sharelatex": { log: () -> }
|
|
|
"crypto": @crypto = { randomBytes: sinon.stub().withArgs(4).returns(Buffer.from([0x1, 0x2, 0x3, 0x4])) }
|
|
|
"os": @os = {hostname: sinon.stub().returns("somehost")}
|
|
|
+ "./Metrics": @metrics = { summary: sinon.stub()}
|
|
|
|
|
|
@doc_id = "doc-id-123"
|
|
|
@project_id = "project-id-123"
|
|
|
@callback = sinon.stub()
|
|
|
-
|
|
|
+
|
|
|
describe "getPendingUpdatesForDoc", ->
|
|
|
beforeEach ->
|
|
|
@rclient.lrange = sinon.stub()
|
|
|
@@ -44,7 +45,7 @@ describe "RealTimeRedisManager", ->
|
|
|
@jsonUpdates = @updates.map (update) -> JSON.stringify update
|
|
|
@rclient.exec = sinon.stub().callsArgWith(0, null, [@jsonUpdates])
|
|
|
@RealTimeRedisManager.getPendingUpdatesForDoc @doc_id, @callback
|
|
|
-
|
|
|
+
|
|
|
it "should get the pending updates", ->
|
|
|
@rclient.lrange
|
|
|
.calledWith("PendingUpdates:#{@doc_id}", 0, 7)
|
|
|
@@ -75,10 +76,10 @@ describe "RealTimeRedisManager", ->
|
|
|
beforeEach ->
|
|
|
@rclient.llen = sinon.stub().yields(null, @length = 3)
|
|
|
@RealTimeRedisManager.getUpdatesLength @doc_id, @callback
|
|
|
-
|
|
|
+
|
|
|
it "should look up the length", ->
|
|
|
@rclient.llen.calledWith("PendingUpdates:#{@doc_id}").should.equal true
|
|
|
-
|
|
|
+
|
|
|
it "should return the length", ->
|
|
|
@callback.calledWith(null, @length).should.equal true
|
|
|
|
|
|
@@ -86,6 +87,6 @@ describe "RealTimeRedisManager", ->
|
|
|
beforeEach ->
|
|
|
@message_id = "doc:somehost:01020304-0"
|
|
|
@RealTimeRedisManager.sendData({op: "thisop"})
|
|
|
-
|
|
|
+
|
|
|
it "should send the op with a message id", ->
|
|
|
- @pubsubClient.publish.calledWith("applied-ops", JSON.stringify({op:"thisop",_id:@message_id})).should.equal true
|
|
|
+ @pubsubClient.publish.calledWith("applied-ops", JSON.stringify({op:"thisop",_id:@message_id})).should.equal true
|