ProjectEditorHandlerTests.coffee 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. chai = require('chai')
  2. should = chai.should()
  3. modulePath = "../../../../app/js/Features/Project/ProjectEditorHandler"
  4. SandboxedModule = require('sandboxed-module')
  5. describe "ProjectEditorHandler", ->
  6. beforeEach ->
  7. @project =
  8. _id : "project-id"
  9. name : "Project Name"
  10. rootDoc_id : "file-id"
  11. publicAccesLevel : "private"
  12. deletedByExternalDataSource: false
  13. rootFolder : [{
  14. _id : "root-folder-id"
  15. name : ""
  16. docs : []
  17. fileRefs : []
  18. folders : [{
  19. _id : "sub-folder-id"
  20. name : "folder"
  21. docs : [{
  22. _id : "doc-id"
  23. name : "main.tex"
  24. lines : @lines = [
  25. "line 1"
  26. "line 2"
  27. "line 3"
  28. ]
  29. }]
  30. fileRefs : [{
  31. _id : "file-id"
  32. name : "image.png"
  33. created : new Date()
  34. size : 1234
  35. }]
  36. folders : []
  37. }]
  38. }]
  39. owner_ref :
  40. _id: "owner-id"
  41. first_name : "Owner"
  42. last_name : "ShareLaTeX"
  43. email : "owner@sharelatex.com"
  44. readOnly_refs: [{
  45. _id: "read-only-id"
  46. first_name : "Read"
  47. last_name : "Only"
  48. email : "read-only@sharelatex.com"
  49. }]
  50. collaberator_refs: [{
  51. _id: "read-write-id"
  52. first_name : "Read"
  53. last_name : "Write"
  54. email : "read-write@sharelatex.com"
  55. }]
  56. deletedDocs: [{
  57. _id: "deleted-doc-id"
  58. name: "main.tex"
  59. }]
  60. @handler = SandboxedModule.require modulePath
  61. describe "buildProjectModelView", ->
  62. describe "with owner and members included", ->
  63. beforeEach ->
  64. @result = @handler.buildProjectModelView @project
  65. it "should include the id", ->
  66. should.exist @result._id
  67. @result._id.should.equal "project-id"
  68. it "should include the name", ->
  69. should.exist @result.name
  70. @result.name.should.equal "Project Name"
  71. it "should include the root doc id", ->
  72. should.exist @result.rootDoc_id
  73. @result.rootDoc_id.should.equal "file-id"
  74. it "should include the public access level", ->
  75. should.exist @result.publicAccesLevel
  76. @result.publicAccesLevel.should.equal "private"
  77. it "should include the owner", ->
  78. should.exist @result.owner
  79. @result.owner._id.should.equal "owner-id"
  80. @result.owner.email.should.equal "owner@sharelatex.com"
  81. @result.owner.first_name.should.equal "Owner"
  82. @result.owner.last_name.should.equal "ShareLaTeX"
  83. @result.owner.privileges.should.equal "owner"
  84. it "should include the deletedDocs", ->
  85. should.exist @result.deletedDocs
  86. @result.deletedDocs.should.equal @project.deletedDocs
  87. it "should gather readOnly_refs and collaberators_refs into a list of members", ->
  88. findMember = (id) =>
  89. for member in @result.members
  90. return member if member._id == id
  91. return null
  92. @result.members.length.should.equal 2
  93. should.exist findMember("read-only-id")
  94. findMember("read-only-id").privileges.should.equal "readOnly"
  95. findMember("read-only-id").first_name.should.equal "Read"
  96. findMember("read-only-id").last_name.should.equal "Only"
  97. findMember("read-only-id").email.should.equal "read-only@sharelatex.com"
  98. should.exist findMember("read-write-id")
  99. findMember("read-write-id").privileges.should.equal "readAndWrite"
  100. findMember("read-write-id").first_name.should.equal "Read"
  101. findMember("read-write-id").last_name.should.equal "Write"
  102. findMember("read-write-id").email.should.equal "read-write@sharelatex.com"
  103. it "should include folders in the project", ->
  104. @result.rootFolder[0]._id.should.equal "root-folder-id"
  105. @result.rootFolder[0].name.should.equal ""
  106. @result.rootFolder[0].folders[0]._id.should.equal "sub-folder-id"
  107. @result.rootFolder[0].folders[0].name.should.equal "folder"
  108. it "should not duplicate folder contents", ->
  109. @result.rootFolder[0].docs.length.should.equal 0
  110. @result.rootFolder[0].fileRefs.length.should.equal 0
  111. it "should include files in the project", ->
  112. @result.rootFolder[0].folders[0].fileRefs[0]._id.should.equal "file-id"
  113. @result.rootFolder[0].folders[0].fileRefs[0].name.should.equal "image.png"
  114. should.not.exist @result.rootFolder[0].folders[0].fileRefs[0].created
  115. should.not.exist @result.rootFolder[0].folders[0].fileRefs[0].size
  116. it "should include docs in the project but not the lines", ->
  117. @result.rootFolder[0].folders[0].docs[0]._id.should.equal "doc-id"
  118. @result.rootFolder[0].folders[0].docs[0].name.should.equal "main.tex"
  119. should.not.exist @result.rootFolder[0].folders[0].docs[0].lines
  120. describe "deletedByExternalDataSource", ->
  121. it "should set the deletedByExternalDataSource flag to false when it is not there", ->
  122. delete @project.deletedByExternalDataSource
  123. result = @handler.buildProjectModelView @project
  124. result.deletedByExternalDataSource.should.equal false
  125. it "should set the deletedByExternalDataSource flag to false when it is false", ->
  126. result = @handler.buildProjectModelView @project
  127. result.deletedByExternalDataSource.should.equal false
  128. it "should set the deletedByExternalDataSource flag to true when it is true", ->
  129. @project.deletedByExternalDataSource = true
  130. result = @handler.buildProjectModelView @project
  131. result.deletedByExternalDataSource.should.equal true
  132. describe "features", ->
  133. beforeEach ->
  134. @project.owner_ref.features =
  135. versioning: true
  136. collaborators: 3
  137. @result = @handler.buildProjectModelView @project
  138. it "should copy the owner features to the project", ->
  139. @result.features.versioning.should.equal @project.owner_ref.features.versioning
  140. @result.features.collaborators.should.equal @project.owner_ref.features.collaborators
  141. describe "without owners and members", ->
  142. beforeEach ->
  143. @result = @handler.buildProjectModelView @project, includeUsers: false
  144. it "should not include the owner", ->
  145. should.not.exist @result.owner
  146. it "should not include the members", ->
  147. should.not.exist @result.members