ProjectHistoryRedisManagerTests.coffee 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/ProjectHistoryRedisManager.js"
  5. SandboxedModule = require('sandboxed-module')
  6. tk = require "timekeeper"
  7. describe "ProjectHistoryRedisManager", ->
  8. beforeEach ->
  9. @project_id = "project-id-123"
  10. @projectHistoryId = "history-id-123"
  11. @user_id = "user-id-123"
  12. @callback = sinon.stub()
  13. @rclient = {}
  14. tk.freeze(new Date())
  15. @ProjectHistoryRedisManager = SandboxedModule.require modulePath,
  16. requires:
  17. "settings-sharelatex": @settings = {
  18. redis:
  19. project_history:
  20. key_schema:
  21. projectHistoryOps: ({project_id}) -> "ProjectHistory:Ops:#{project_id}"
  22. }
  23. "redis-sharelatex":
  24. createClient: () => @rclient
  25. globals:
  26. JSON: @JSON = JSON
  27. afterEach ->
  28. tk.reset()
  29. describe "queueOps", ->
  30. beforeEach ->
  31. @ops = ["mock-op-1", "mock-op-2"]
  32. @rclient.rpush = sinon.stub()
  33. @ProjectHistoryRedisManager.queueOps @project_id, @ops..., @callback
  34. it "should queue an update", ->
  35. @rclient.rpush
  36. .calledWithExactly(
  37. "ProjectHistory:Ops:#{@project_id}"
  38. @ops[0]
  39. @ops[1]
  40. @callback
  41. ).should.equal true
  42. describe "queueRenameEntity", ->
  43. beforeEach () ->
  44. @file_id = 1234
  45. @rawUpdate =
  46. pathname: @pathname = '/old'
  47. newPathname: @newPathname = '/new'
  48. version: @version = 2
  49. @ProjectHistoryRedisManager.queueOps = sinon.stub()
  50. @ProjectHistoryRedisManager.queueRenameEntity @project_id, @projectHistoryId, 'file', @file_id, @user_id, @rawUpdate, @callback
  51. it "should queue an update", ->
  52. update =
  53. pathname: @pathname
  54. new_pathname: @newPathname
  55. meta:
  56. user_id: @user_id
  57. ts: new Date()
  58. version: @version
  59. projectHistoryId: @projectHistoryId
  60. file: @file_id
  61. @ProjectHistoryRedisManager.queueOps
  62. .calledWithExactly(@project_id, @JSON.stringify(update), @callback)
  63. .should.equal true
  64. describe "queueAddEntity", ->
  65. beforeEach () ->
  66. @rclient.rpush = sinon.stub().yields()
  67. @doc_id = 1234
  68. @rawUpdate =
  69. pathname: @pathname = '/old'
  70. docLines: @docLines = 'a\nb'
  71. version: @version = 2
  72. url: @url = 'filestore.example.com'
  73. @ProjectHistoryRedisManager.queueOps = sinon.stub()
  74. @ProjectHistoryRedisManager.queueAddEntity @project_id, @projectHistoryId, 'doc', @doc_id, @user_id, @rawUpdate, @callback
  75. it "should queue an update", ->
  76. update =
  77. pathname: @pathname
  78. docLines: @docLines
  79. url: @url
  80. meta:
  81. user_id: @user_id
  82. ts: new Date()
  83. version: @version
  84. projectHistoryId: @projectHistoryId
  85. doc: @doc_id
  86. @ProjectHistoryRedisManager.queueOps
  87. .calledWithExactly(@project_id, @JSON.stringify(update), @callback)
  88. .should.equal true
  89. describe "queueResyncProjectStructure", ->
  90. it "should queue an update", ->
  91. describe "queueResyncDocContent", ->
  92. it "should queue an update", ->