2018-03-09 09:14:14 -05:00
|
|
|
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"
|
2018-04-23 07:08:04 -04:00
|
|
|
@projectHistoryId = "history-id-123"
|
2018-03-09 09:14:14 -05:00
|
|
|
@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}"
|
2018-07-20 05:43:31 -04:00
|
|
|
projectHistoryFirstOpTimestamp: ({project_id}) -> "ProjectHistory:FirstOpTimestamp:#{project_id}"
|
2018-03-09 09:14:14 -05:00
|
|
|
}
|
|
|
|
"redis-sharelatex":
|
|
|
|
createClient: () => @rclient
|
2018-12-05 11:17:41 -05:00
|
|
|
"logger-sharelatex":
|
|
|
|
log:->
|
2020-03-25 10:27:04 -04:00
|
|
|
"./Metrics": @metrics = { summary: sinon.stub()}
|
2018-03-09 09:14:14 -05:00
|
|
|
globals:
|
|
|
|
JSON: @JSON = JSON
|
|
|
|
|
2018-06-05 08:54:05 -04:00
|
|
|
afterEach ->
|
|
|
|
tk.reset()
|
2018-03-09 09:14:14 -05:00
|
|
|
|
|
|
|
describe "queueOps", ->
|
|
|
|
beforeEach ->
|
|
|
|
@ops = ["mock-op-1", "mock-op-2"]
|
2018-07-20 05:43:31 -04:00
|
|
|
@multi = exec: sinon.stub()
|
|
|
|
@multi.rpush = sinon.stub()
|
|
|
|
@multi.setnx = sinon.stub()
|
|
|
|
@rclient.multi = () => @multi
|
|
|
|
# @rclient = multi: () => @multi
|
2018-03-09 09:14:14 -05:00
|
|
|
@ProjectHistoryRedisManager.queueOps @project_id, @ops..., @callback
|
|
|
|
|
|
|
|
it "should queue an update", ->
|
2018-07-20 05:43:31 -04:00
|
|
|
@multi.rpush
|
2018-03-09 09:14:14 -05:00
|
|
|
.calledWithExactly(
|
|
|
|
"ProjectHistory:Ops:#{@project_id}"
|
|
|
|
@ops[0]
|
|
|
|
@ops[1]
|
2018-07-20 05:43:31 -04:00
|
|
|
).should.equal true
|
|
|
|
|
|
|
|
it "should set the queue timestamp if not present", ->
|
|
|
|
@multi.setnx
|
|
|
|
.calledWithExactly(
|
|
|
|
"ProjectHistory:FirstOpTimestamp:#{@project_id}"
|
|
|
|
Date.now()
|
2018-03-09 09:14:14 -05:00
|
|
|
).should.equal true
|
|
|
|
|
|
|
|
describe "queueRenameEntity", ->
|
|
|
|
beforeEach () ->
|
|
|
|
@file_id = 1234
|
|
|
|
|
|
|
|
@rawUpdate =
|
|
|
|
pathname: @pathname = '/old'
|
|
|
|
newPathname: @newPathname = '/new'
|
2018-04-23 07:08:04 -04:00
|
|
|
version: @version = 2
|
2018-03-09 09:14:14 -05:00
|
|
|
|
|
|
|
@ProjectHistoryRedisManager.queueOps = sinon.stub()
|
2018-04-23 07:08:04 -04:00
|
|
|
@ProjectHistoryRedisManager.queueRenameEntity @project_id, @projectHistoryId, 'file', @file_id, @user_id, @rawUpdate, @callback
|
2018-03-09 09:14:14 -05:00
|
|
|
|
|
|
|
it "should queue an update", ->
|
|
|
|
update =
|
|
|
|
pathname: @pathname
|
|
|
|
new_pathname: @newPathname
|
|
|
|
meta:
|
|
|
|
user_id: @user_id
|
|
|
|
ts: new Date()
|
2018-04-23 07:08:04 -04:00
|
|
|
version: @version
|
|
|
|
projectHistoryId: @projectHistoryId
|
2018-03-09 09:14:14 -05:00
|
|
|
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'
|
2018-04-23 07:08:04 -04:00
|
|
|
version: @version = 2
|
2018-03-09 09:14:14 -05:00
|
|
|
url: @url = 'filestore.example.com'
|
|
|
|
|
|
|
|
@ProjectHistoryRedisManager.queueOps = sinon.stub()
|
2018-04-23 07:08:04 -04:00
|
|
|
@ProjectHistoryRedisManager.queueAddEntity @project_id, @projectHistoryId, 'doc', @doc_id, @user_id, @rawUpdate, @callback
|
2018-03-09 09:14:14 -05:00
|
|
|
|
|
|
|
it "should queue an update", ->
|
|
|
|
update =
|
|
|
|
pathname: @pathname
|
|
|
|
docLines: @docLines
|
|
|
|
url: @url
|
|
|
|
meta:
|
|
|
|
user_id: @user_id
|
|
|
|
ts: new Date()
|
2018-04-23 07:08:04 -04:00
|
|
|
version: @version
|
|
|
|
projectHistoryId: @projectHistoryId
|
2018-03-09 09:14:14 -05:00
|
|
|
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", ->
|