mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
102 lines
2.6 KiB
CoffeeScript
102 lines
2.6 KiB
CoffeeScript
|
sinon = require('sinon')
|
||
|
chai = require('chai')
|
||
|
should = chai.should()
|
||
|
modulePath = "../../../../app/js/ProjectHistoryRedisManager.js"
|
||
|
SandboxedModule = require('sandboxed-module')
|
||
|
tk = require "timekeeper"
|
||
|
|
||
|
describe "ProjectHistoryRedisManager", ->
|
||
|
beforeEach ->
|
||
|
@project_id = "project-id-123"
|
||
|
@user_id = "user-id-123"
|
||
|
@callback = sinon.stub()
|
||
|
@rclient = {}
|
||
|
tk.freeze(new Date())
|
||
|
@ProjectHistoryRedisManager = SandboxedModule.require modulePath,
|
||
|
requires:
|
||
|
"settings-sharelatex": @settings = {
|
||
|
redis:
|
||
|
project_history:
|
||
|
key_schema:
|
||
|
projectHistoryOps: ({project_id}) -> "ProjectHistory:Ops:#{project_id}"
|
||
|
}
|
||
|
"redis-sharelatex":
|
||
|
createClient: () => @rclient
|
||
|
globals:
|
||
|
JSON: @JSON = JSON
|
||
|
|
||
|
afterEach ->
|
||
|
tk.reset()
|
||
|
|
||
|
describe "queueOps", ->
|
||
|
beforeEach ->
|
||
|
@ops = ["mock-op-1", "mock-op-2"]
|
||
|
@rclient.rpush = sinon.stub()
|
||
|
@ProjectHistoryRedisManager.queueOps @project_id, @ops..., @callback
|
||
|
|
||
|
it "should queue an update", ->
|
||
|
@rclient.rpush
|
||
|
.calledWithExactly(
|
||
|
"ProjectHistory:Ops:#{@project_id}"
|
||
|
@ops[0]
|
||
|
@ops[1]
|
||
|
@callback
|
||
|
).should.equal true
|
||
|
|
||
|
describe "queueRenameEntity", ->
|
||
|
beforeEach () ->
|
||
|
@file_id = 1234
|
||
|
|
||
|
@rawUpdate =
|
||
|
pathname: @pathname = '/old'
|
||
|
newPathname: @newPathname = '/new'
|
||
|
|
||
|
@ProjectHistoryRedisManager.queueOps = sinon.stub()
|
||
|
@ProjectHistoryRedisManager.queueRenameEntity @project_id, 'file', @file_id, @user_id, @rawUpdate, @callback
|
||
|
|
||
|
it "should queue an update", ->
|
||
|
update =
|
||
|
pathname: @pathname
|
||
|
new_pathname: @newPathname
|
||
|
meta:
|
||
|
user_id: @user_id
|
||
|
ts: new Date()
|
||
|
file: @file_id
|
||
|
|
||
|
@ProjectHistoryRedisManager.queueOps
|
||
|
.calledWithExactly(@project_id, @JSON.stringify(update), @callback)
|
||
|
.should.equal true
|
||
|
|
||
|
describe "queueAddEntity", ->
|
||
|
beforeEach () ->
|
||
|
@rclient.rpush = sinon.stub().yields()
|
||
|
@doc_id = 1234
|
||
|
|
||
|
@rawUpdate =
|
||
|
pathname: @pathname = '/old'
|
||
|
docLines: @docLines = 'a\nb'
|
||
|
url: @url = 'filestore.example.com'
|
||
|
|
||
|
@ProjectHistoryRedisManager.queueOps = sinon.stub()
|
||
|
@ProjectHistoryRedisManager.queueAddEntity @project_id, 'doc', @doc_id, @user_id, @rawUpdate, @callback
|
||
|
|
||
|
it "should queue an update", ->
|
||
|
update =
|
||
|
pathname: @pathname
|
||
|
docLines: @docLines
|
||
|
url: @url
|
||
|
meta:
|
||
|
user_id: @user_id
|
||
|
ts: new Date()
|
||
|
doc: @doc_id
|
||
|
|
||
|
@ProjectHistoryRedisManager.queueOps
|
||
|
.calledWithExactly(@project_id, @JSON.stringify(update), @callback)
|
||
|
.should.equal true
|
||
|
|
||
|
describe "queueResyncProjectStructure", ->
|
||
|
it "should queue an update", ->
|
||
|
|
||
|
describe "queueResyncDocContent", ->
|
||
|
it "should queue an update", ->
|