 			it "should call the callback with the error", ->
 				@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", ->
 		beforeEach ->
 			@model = on: (event, callback) =>

		beforeEach ->
			@lines = ["one", "two"]
			@version = 34
			@update = {p: 4, t: "foo"}
			@updatedDocLines = ["onefoo", "two"]
			@model =
				applyOp: sinon.stub().callsArg(2)
				getSnapshot: sinon.stub()

should = chai.should()
modulePath = "../../../../app/js/ShareJsUpdateManager.js"
SandboxedModule = require('sandboxed-module')
crypto = require('crypto')

describe "ShareJsUpdateManager", ->
	beforeEach ->
