ProjectHistoryRedisManagerTests.coffee 2.6 KB

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