mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
add unit tests
This commit is contained in:
+16
-1
@@ -3,6 +3,7 @@ chai = require('chai')
|
|||||||
should = chai.should()
|
should = chai.should()
|
||||||
modulePath = "../../../../app/js/ShareJsUpdateManager.js"
|
modulePath = "../../../../app/js/ShareJsUpdateManager.js"
|
||||||
SandboxedModule = require('sandboxed-module')
|
SandboxedModule = require('sandboxed-module')
|
||||||
|
crypto = require('crypto')
|
||||||
|
|
||||||
describe "ShareJsUpdateManager", ->
|
describe "ShareJsUpdateManager", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@@ -26,8 +27,10 @@ describe "ShareJsUpdateManager", ->
|
|||||||
beforeEach ->
|
beforeEach ->
|
||||||
@lines = ["one", "two"]
|
@lines = ["one", "two"]
|
||||||
@version = 34
|
@version = 34
|
||||||
@update = {p: 4, t: "foo"}
|
|
||||||
@updatedDocLines = ["onefoo", "two"]
|
@updatedDocLines = ["onefoo", "two"]
|
||||||
|
content = @updatedDocLines.join("\n")
|
||||||
|
@hash = crypto.createHash('sha1').update("blob " + content.length + "\x00").update(content, 'utf8').digest('hex')
|
||||||
|
@update = {p: 4, t: "foo", v:@version, hash:@hash}
|
||||||
@model =
|
@model =
|
||||||
applyOp: sinon.stub().callsArg(2)
|
applyOp: sinon.stub().callsArg(2)
|
||||||
getSnapshot: sinon.stub()
|
getSnapshot: sinon.stub()
|
||||||
@@ -90,6 +93,18 @@ describe "ShareJsUpdateManager", ->
|
|||||||
it "should call the callback with the error", ->
|
it "should call the callback with the error", ->
|
||||||
@callback.calledWith(@error).should.equal true
|
@callback.calledWith(@error).should.equal true
|
||||||
|
|
||||||
|
describe "with an invalid hash", ->
|
||||||
|
beforeEach (done) ->
|
||||||
|
@error = new Error("invalid hash")
|
||||||
|
@model.getSnapshot.callsArgWith(1, null, {snapshot: "unexpected content", v: @version})
|
||||||
|
@model.db.appliedOps["#{@project_id}:#{@doc_id}"] = @appliedOps = ["mock-ops"]
|
||||||
|
@ShareJsUpdateManager.applyUpdate @project_id, @doc_id, @update, @lines, @version, (err, docLines, version, appliedOps) =>
|
||||||
|
@callback(err, docLines, version, appliedOps)
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should call the callback with the error", ->
|
||||||
|
@callback.calledWith(@error).should.equal true
|
||||||
|
|
||||||
describe "_listenForOps", ->
|
describe "_listenForOps", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@model = on: (event, callback) =>
|
@model = on: (event, callback) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user