JoinDocTests.coffee 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. chai = require("chai")
  2. expect = chai.expect
  3. chai.should()
  4. RealTimeClient = require "./helpers/RealTimeClient"
  5. MockDocUpdaterServer = require "./helpers/MockDocUpdaterServer"
  6. FixturesManager = require "./helpers/FixturesManager"
  7. describe "joinDoc", ->
  8. before ->
  9. @lines = ["test", "doc", "lines"]
  10. @version = 42
  11. @ops = ["mock", "doc", "ops"]
  12. describe "when authorised readAndWrite", ->
  13. before (done) ->
  14. FixturesManager.setUpProject {
  15. privilegeLevel: "readAndWrite"
  16. }, (error, data) =>
  17. throw error if error?
  18. {@project_id, @user_id} = data
  19. FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (error, data) =>
  20. throw error if error?
  21. {@doc_id} = data
  22. @client = RealTimeClient.connect()
  23. @client.emit "joinProject", project_id: @project_id, (error) =>
  24. throw error if error?
  25. @client.emit "joinDoc", @doc_id, (error, @returnedArgs...) =>
  26. throw error if error?
  27. done()
  28. it "should get the doc from the doc updater", ->
  29. MockDocUpdaterServer.getDocument
  30. .calledWith(@project_id, @doc_id, -1)
  31. .should.equal true
  32. it "should return the doc lines, version and ops", ->
  33. @returnedArgs.should.deep.equal [@lines, @version, @ops]
  34. it "should have joined the doc room", (done) ->
  35. RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
  36. expect(@doc_id in client.rooms).to.equal true
  37. done()
  38. describe "when authorised readOnly", ->
  39. before (done) ->
  40. FixturesManager.setUpProject {
  41. privilegeLevel: "readOnly"
  42. }, (error, data) =>
  43. throw error if error?
  44. {@project_id, @user_id} = data
  45. FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (error, data) =>
  46. throw error if error?
  47. {@doc_id} = data
  48. @client = RealTimeClient.connect()
  49. @client.emit "joinProject", project_id: @project_id, (error) =>
  50. throw error if error?
  51. @client.emit "joinDoc", @doc_id, (error, @returnedArgs...) =>
  52. throw error if error?
  53. done()
  54. it "should get the doc from the doc updater", ->
  55. MockDocUpdaterServer.getDocument
  56. .calledWith(@project_id, @doc_id, -1)
  57. .should.equal true
  58. it "should return the doc lines, version and ops", ->
  59. @returnedArgs.should.deep.equal [@lines, @version, @ops]
  60. it "should have joined the doc room", (done) ->
  61. RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
  62. expect(@doc_id in client.rooms).to.equal true
  63. done()
  64. describe "when authorised as owner", ->
  65. before (done) ->
  66. FixturesManager.setUpProject {
  67. privilegeLevel: "owner"
  68. }, (error, data) =>
  69. throw error if error?
  70. {@project_id, @user_id} = data
  71. FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (error, data) =>
  72. throw error if error?
  73. {@doc_id} = data
  74. @client = RealTimeClient.connect()
  75. @client.emit "joinProject", project_id: @project_id, (error) =>
  76. throw error if error?
  77. @client.emit "joinDoc", @doc_id, (error, @returnedArgs...) =>
  78. throw error if error?
  79. done()
  80. it "should get the doc from the doc updater", ->
  81. MockDocUpdaterServer.getDocument
  82. .calledWith(@project_id, @doc_id, -1)
  83. .should.equal true
  84. it "should return the doc lines, version and ops", ->
  85. @returnedArgs.should.deep.equal [@lines, @version, @ops]
  86. it "should have joined the doc room", (done) ->
  87. RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
  88. expect(@doc_id in client.rooms).to.equal true
  89. done()
  90. # It is impossible to write an acceptance test to test joining an unauthorized
  91. # project, since joinProject already catches that. If you can join a project,
  92. # then you can join a doc in that project.
  93. describe "with a fromVersion", ->
  94. before (done) ->
  95. @fromVersion = 36
  96. FixturesManager.setUpProject {
  97. privilegeLevel: "readAndWrite"
  98. }, (error, data) =>
  99. throw error if error?
  100. {@project_id, @user_id} = data
  101. FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (error, data) =>
  102. throw error if error?
  103. {@doc_id} = data
  104. @client = RealTimeClient.connect()
  105. @client.emit "joinProject", project_id: @project_id, (error) =>
  106. throw error if error?
  107. @client.emit "joinDoc", @doc_id, @fromVersion, (error, @returnedArgs...) =>
  108. throw error if error?
  109. done()
  110. it "should get the doc from the doc updater with the fromVersion", ->
  111. MockDocUpdaterServer.getDocument
  112. .calledWith(@project_id, @doc_id, @fromVersion)
  113. .should.equal true
  114. it "should return the doc lines, version and ops", ->
  115. @returnedArgs.should.deep.equal [@lines, @version, @ops]
  116. it "should have joined the doc room", (done) ->
  117. RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
  118. expect(@doc_id in client.rooms).to.equal true
  119. done()